model fix
This commit is contained in:
parent
1c1dd11635
commit
387d4e8353
@ -65,11 +65,12 @@ async def run():
|
|||||||
|
|
||||||
total_symbols = stock_symbols
|
total_symbols = stock_symbols
|
||||||
print(f"Total tickers: {len(total_symbols)}")
|
print(f"Total tickers: {len(total_symbols)}")
|
||||||
start_date = datetime(2015, 1, 1).strftime("%Y-%m-%d")
|
start_date = datetime(2020, 1, 1).strftime("%Y-%m-%d")
|
||||||
end_date = datetime.today().strftime("%Y-%m-%d")
|
end_date = datetime.today().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
chunk_size = len(total_symbols) // 70 # Divide the list into N chunks
|
chunk_size = len(total_symbols) // 70 # Divide the list into N chunks
|
||||||
chunks = [total_symbols[i:i + chunk_size] for i in range(0, len(total_symbols), chunk_size)]
|
chunks = [total_symbols[i:i + chunk_size] for i in range(0, len(total_symbols), chunk_size)]
|
||||||
|
#chunks = [['TSLA']]
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
tasks = []
|
tasks = []
|
||||||
for ticker in tqdm(chunk):
|
for ticker in tqdm(chunk):
|
||||||
|
|||||||
@ -64,9 +64,9 @@ class PricePredictor:
|
|||||||
|
|
||||||
# Apply rolling average to smooth the forecast intervals
|
# Apply rolling average to smooth the forecast intervals
|
||||||
rolling_window = 200
|
rolling_window = 200
|
||||||
forecast['smoothed_upper'] = forecast['yhat_upper'].rolling(window=rolling_window, min_periods=1).mean().round(2)
|
forecast['smoothed_upper'] = forecast['yhat_upper'].round(2)#.rolling(window=rolling_window, min_periods=1).mean().round(2)
|
||||||
forecast['smoothed_lower'] = forecast['yhat_lower'].rolling(window=rolling_window, min_periods=1).mean().round(2)
|
forecast['smoothed_lower'] = forecast['yhat_lower'].round(2)#.rolling(window=rolling_window, min_periods=1).mean().round(2)
|
||||||
forecast['smoothed_mean'] = forecast['yhat'].rolling(window=rolling_window, min_periods=1).mean().round(2)
|
forecast['smoothed_mean'] = forecast['yhat'].round(2)#.rolling(window=rolling_window, min_periods=1).mean().round(2)
|
||||||
|
|
||||||
# Actual and predicted values for evaluation (optional)
|
# Actual and predicted values for evaluation (optional)
|
||||||
actual_values = df['y'].values
|
actual_values = df['y'].values
|
||||||
@ -81,16 +81,23 @@ class PricePredictor:
|
|||||||
historical_date_list = df['ds'][-1200:].dt.strftime('%Y-%m-%d').tolist()
|
historical_date_list = df['ds'][-1200:].dt.strftime('%Y-%m-%d').tolist()
|
||||||
historical_price_list = df['y'][-1200:].round(2).tolist()
|
historical_price_list = df['y'][-1200:].round(2).tolist()
|
||||||
|
|
||||||
|
metrics_dict = {
|
||||||
|
'mse': mean_squared_error(actual_values, predicted_values),
|
||||||
|
'mae': mean_absolute_error(actual_values, predicted_values),
|
||||||
|
'r2': r2_score(actual_values, predicted_values)}
|
||||||
|
print("Metrics:", metrics_dict)
|
||||||
|
|
||||||
# Get monthly historical data and round the close value
|
# Get monthly historical data and round the close value
|
||||||
monthly_historical_data = get_monthly_historical_data(df)
|
monthly_historical_data = get_monthly_historical_data(df)
|
||||||
monthly_historical_data = [{**item, 'close': round(item['close'], 2)} for item in monthly_historical_data]
|
monthly_historical_data = [{**item, 'close': round(item['close'], 2)} for item in monthly_historical_data]
|
||||||
|
|
||||||
|
|
||||||
future_forecast = forecast[forecast['ds'] > df['ds'].max()]['smoothed_mean']
|
future_forecast = forecast[forecast['ds'] > df['ds'].max()]['smoothed_mean']
|
||||||
if not future_forecast.empty:
|
median_price = round(np.mean([
|
||||||
median_price = round(np.median(future_forecast), 2)
|
forecast['smoothed_lower'].iloc[-1],
|
||||||
else:
|
forecast['smoothed_mean'].iloc[-1],
|
||||||
median_price = round(forecast['smoothed_mean'].iloc[-1], 2)
|
forecast['smoothed_upper'].iloc[-1]
|
||||||
|
]), 2)
|
||||||
|
|
||||||
# Latest actual price from the dataset
|
# Latest actual price from the dataset
|
||||||
latest_price = round(df['y'].iloc[-1], 2)
|
latest_price = round(df['y'].iloc[-1], 2)
|
||||||
@ -101,7 +108,6 @@ class PricePredictor:
|
|||||||
'highPriceTarget': upper_list[-1],
|
'highPriceTarget': upper_list[-1],
|
||||||
'lowPriceTarget': lower_list[-1],
|
'lowPriceTarget': lower_list[-1],
|
||||||
'medianPriceTarget': median_price,
|
'medianPriceTarget': median_price,
|
||||||
'latestPrice': latest_price
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user