Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -67,7 +67,7 @@ with demo:
|
|
67 |
return gr.Dropdown(choices=stock_names, label='Please Select Stock from your selected index', interactive=True)
|
68 |
|
69 |
d1.input(get_stocks_from_index, d1, d2)
|
70 |
-
|
71 |
def get_stock_graph(idx, stock, interval, graph_type, forecast_method):
|
72 |
stock_name, ticker_name = stock.split(":")
|
73 |
|
@@ -75,17 +75,27 @@ with demo:
|
|
75 |
ticker_name += '.L' if ticker_name[-1] != '.' else 'L'
|
76 |
elif ticker_dict[idx] == 'CAC 40':
|
77 |
ticker_name += '.PA'
|
78 |
-
|
79 |
series = yf.download(tickers=ticker_name, start=START_DATE, end=END_DATE, interval=interval)
|
80 |
series = series.reset_index()
|
81 |
-
|
82 |
predictions = forecast_series(series, model=forecast_method)
|
83 |
-
|
84 |
last_date = pd.to_datetime(series['Date'].values[-1])
|
85 |
-
forecast_week = [
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
forecast = pd.DataFrame({"Date": forecast_week, "Forecast": predictions})
|
88 |
-
|
89 |
if graph_type == 'Line Graph':
|
90 |
fig = go.Figure()
|
91 |
fig.add_trace(go.Scatter(x=series['Date'], y=series['Close'], mode='lines', name='Historical'))
|
@@ -98,13 +108,12 @@ with demo:
|
|
98 |
close=series['Close'],
|
99 |
name='Historical')])
|
100 |
fig.add_trace(go.Scatter(x=forecast['Date'], y=forecast['Forecast'], mode='lines', name='Forecast'))
|
101 |
-
|
102 |
fig.update_layout(title=f"Stock Price of {stock_name}",
|
103 |
xaxis_title="Date",
|
104 |
yaxis_title="Price")
|
105 |
-
|
106 |
return fig
|
107 |
-
|
108 |
out = gr.Plot()
|
109 |
inputs = [d1, d2, d3, d4, d5]
|
110 |
d2.input(get_stock_graph, inputs, out)
|
|
|
67 |
return gr.Dropdown(choices=stock_names, label='Please Select Stock from your selected index', interactive=True)
|
68 |
|
69 |
d1.input(get_stocks_from_index, d1, d2)
|
70 |
+
|
71 |
def get_stock_graph(idx, stock, interval, graph_type, forecast_method):
|
72 |
stock_name, ticker_name = stock.split(":")
|
73 |
|
|
|
75 |
ticker_name += '.L' if ticker_name[-1] != '.' else 'L'
|
76 |
elif ticker_dict[idx] == 'CAC 40':
|
77 |
ticker_name += '.PA'
|
78 |
+
|
79 |
series = yf.download(tickers=ticker_name, start=START_DATE, end=END_DATE, interval=interval)
|
80 |
series = series.reset_index()
|
81 |
+
|
82 |
predictions = forecast_series(series, model=forecast_method)
|
83 |
+
|
84 |
last_date = pd.to_datetime(series['Date'].values[-1])
|
85 |
+
forecast_week = []
|
86 |
+
i = 1
|
87 |
+
while len(forecast_week) < FORECAST_PERIOD:
|
88 |
+
next_date = last_date + timedelta(days=i)
|
89 |
+
if is_business_day(next_date):
|
90 |
+
forecast_week.append(next_date)
|
91 |
+
i += 1
|
92 |
+
|
93 |
+
# Ensure predictions and forecast_week have the same length
|
94 |
+
predictions = predictions[:len(forecast_week)]
|
95 |
+
forecast_week = forecast_week[:len(predictions)]
|
96 |
+
|
97 |
forecast = pd.DataFrame({"Date": forecast_week, "Forecast": predictions})
|
98 |
+
|
99 |
if graph_type == 'Line Graph':
|
100 |
fig = go.Figure()
|
101 |
fig.add_trace(go.Scatter(x=series['Date'], y=series['Close'], mode='lines', name='Historical'))
|
|
|
108 |
close=series['Close'],
|
109 |
name='Historical')])
|
110 |
fig.add_trace(go.Scatter(x=forecast['Date'], y=forecast['Forecast'], mode='lines', name='Forecast'))
|
111 |
+
|
112 |
fig.update_layout(title=f"Stock Price of {stock_name}",
|
113 |
xaxis_title="Date",
|
114 |
yaxis_title="Price")
|
115 |
+
|
116 |
return fig
|
|
|
117 |
out = gr.Plot()
|
118 |
inputs = [d1, d2, d3, d4, d5]
|
119 |
d2.input(get_stock_graph, inputs, out)
|