Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ def download_data(ticker, start_date='2010-01-01'):
|
|
13 |
raise ValueError(f"No data returned for {ticker}")
|
14 |
data.reset_index(inplace=True)
|
15 |
if 'Adj Close' in data.columns:
|
16 |
-
data = data[['Date', 'Adj Close']]
|
17 |
data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
|
18 |
else:
|
19 |
raise ValueError("Expected 'Adj Close' in columns")
|
@@ -31,13 +31,16 @@ def predict_future_prices(ticker, periods=1825):
|
|
31 |
forecast = model.predict(future)
|
32 |
|
33 |
# 예측 결과 그래프 생성
|
34 |
-
forecast['ds'] = forecast['ds']
|
35 |
fig_main = go.Figure()
|
36 |
fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
|
37 |
fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
|
38 |
|
39 |
# 연간 및 주간 계절성 그래프 생성
|
|
|
40 |
fig_seasonal = model.plot_components(forecast)
|
|
|
|
|
41 |
fig_yearly = px.line(x=pd.to_datetime(fig_seasonal[0]['ds']), y=fig_seasonal[0]['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
|
42 |
fig_weekly = px.line(x=fig_seasonal[1]['day'], y=fig_seasonal[1]['weekly'], labels={'x': 'Day of Week', 'y': 'Weekly Trend'})
|
43 |
|
|
|
13 |
raise ValueError(f"No data returned for {ticker}")
|
14 |
data.reset_index(inplace=True)
|
15 |
if 'Adj Close' in data.columns:
|
16 |
+
data = data[['Date', 'Adj Close']].copy()
|
17 |
data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
|
18 |
else:
|
19 |
raise ValueError("Expected 'Adj Close' in columns")
|
|
|
31 |
forecast = model.predict(future)
|
32 |
|
33 |
# 예측 결과 그래프 생성
|
34 |
+
forecast['ds'] = pd.to_datetime(forecast['ds']) # Ensure 'ds' is datetime type
|
35 |
fig_main = go.Figure()
|
36 |
fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
|
37 |
fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
|
38 |
|
39 |
# 연간 및 주간 계절성 그래프 생성
|
40 |
+
forecast['ds'] = forecast['ds'].dt.strftime('%Y-%m-%d') # Formatting for display
|
41 |
fig_seasonal = model.plot_components(forecast)
|
42 |
+
forecast['ds'] = pd.to_datetime(forecast['ds']) # Revert to datetime type for proper handling in Prophet components
|
43 |
+
|
44 |
fig_yearly = px.line(x=pd.to_datetime(fig_seasonal[0]['ds']), y=fig_seasonal[0]['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
|
45 |
fig_weekly = px.line(x=fig_seasonal[1]['day'], y=fig_seasonal[1]['weekly'], labels={'x': 'Day of Week', 'y': 'Weekly Trend'})
|
46 |
|