aiqtech commited on
Commit
240671f
ยท
verified ยท
1 Parent(s): 696277a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -17,18 +17,25 @@ def download_data(ticker, start_date='2010-01-01'):
17
  raise ValueError("Expected 'Adj Close' in columns")
18
  return data
19
 
20
- def predict_future_prices(ticker):
21
- """ ์ฃผ์‹ ๊ฐ€๊ฒฉ์„ ์˜ˆ์ธกํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ """
22
- data = download_data(ticker)
23
- model = Prophet(daily_seasonality=False, yearly_seasonality=True)
 
24
  model.fit(data)
25
- future = model.make_future_dataframe(periods=5 * 365) # ํ–ฅํ›„ 5๋…„
 
26
  forecast = model.predict(future)
27
 
28
- fig = px.line(forecast, x='ds', y='yhat', title=f'5-Year Future Price Forecast for {ticker}')
29
- return fig, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
 
 
 
 
 
30
 
31
- # ์ด์ œ ์ด ํ•จ์ˆ˜๋ฅผ Gradio ์ธํ„ฐํŽ˜์ด์Šค์™€ ์—ฐ๊ฒฐํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ํ‹ฐ์ปค ์ž…๋ ฅ์„ ํ†ตํ•ด ๋ฏธ๋ž˜ ๊ฐ€๊ฒฉ ์˜ˆ์ธก์„ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
32
 
33
 
34
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
 
17
  raise ValueError("Expected 'Adj Close' in columns")
18
  return data
19
 
20
+ def predict_future_prices(ticker, periods=1825): # 5๋…„๊ฐ„์˜ ๋ฐ์ดํ„ฐ ์˜ˆ์ธก
21
+ data = yf.download(ticker, start="2010-01-01")['Adj Close'].reset_index()
22
+ data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
23
+
24
+ model = Prophet(daily_seasonality=False, weekly_seasonality=False, yearly_seasonality=True)
25
  model.fit(data)
26
+
27
+ future = model.make_future_dataframe(periods=periods, freq='D')
28
  forecast = model.predict(future)
29
 
30
+ # Timestamp๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜
31
+ forecast['ds'] = forecast['ds'].dt.strftime('%Y-%m-%d')
32
+
33
+ fig = go.Figure(data=[go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast')])
34
+ fig.update_layout(title=f'5-Year Future Price Forecast for {ticker}', xaxis_title='Date', yaxis_title='Predicted Price')
35
+
36
+ return fig, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].to_dict(orient='records')
37
 
38
+ # ์ด์ œ ์ด ํ•จ์ˆ˜๋ฅผ Gradio ์ธํ„ฐํŽ˜์ด์Šค์™€ ์—ฐ๊ฒฐํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ์‹œ๊ฐํ™”๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.
39
 
40
 
41
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •