Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,20 +79,28 @@ def get_market_minutes():
|
|
| 79 |
# TRAIN MODEL
|
| 80 |
@app.get('/model/train/{symbol}/{p_step}')
|
| 81 |
def train(symbol: str, p_step: int):
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
training_period = '5d'
|
| 84 |
-
epochs =
|
| 85 |
|
| 86 |
tz = pytz.timezone('Asia/Kolkata')
|
| 87 |
now = datetime.now(tz)
|
| 88 |
today = now.date()
|
| 89 |
|
| 90 |
-
data = yf.download(tickers=symbol, interval='
|
| 91 |
-
|
|
|
|
| 92 |
|
|
|
|
| 93 |
data['Date'] = data.index.date
|
| 94 |
available_dates = sorted(list(set(data['Date'])))
|
| 95 |
if today not in available_dates:
|
|
|
|
|
|
|
| 96 |
today = available_dates[-1]
|
| 97 |
|
| 98 |
data_today = data[data['Date'] == today].between_time("09:15", "15:30")
|
|
|
|
| 79 |
# TRAIN MODEL
|
| 80 |
@app.get('/model/train/{symbol}/{p_step}')
|
| 81 |
def train(symbol: str, p_step: int):
|
| 82 |
+
import pytz
|
| 83 |
+
import yfinance as yf
|
| 84 |
+
|
| 85 |
+
predict_steps = p_step
|
| 86 |
+
time_steps = 60
|
| 87 |
training_period = '5d'
|
| 88 |
+
epochs = 206
|
| 89 |
|
| 90 |
tz = pytz.timezone('Asia/Kolkata')
|
| 91 |
now = datetime.now(tz)
|
| 92 |
today = now.date()
|
| 93 |
|
| 94 |
+
data = yf.download(tickers=symbol, interval='5m', period=training_period, progress=False)
|
| 95 |
+
if data.empty:
|
| 96 |
+
return {"error": "No data received from Yahoo Finance. Try another symbol or interval."}
|
| 97 |
|
| 98 |
+
data = data.tz_convert('Asia/Kolkata')
|
| 99 |
data['Date'] = data.index.date
|
| 100 |
available_dates = sorted(list(set(data['Date'])))
|
| 101 |
if today not in available_dates:
|
| 102 |
+
if not available_dates:
|
| 103 |
+
return {"error": "No available trading dates in the data."}
|
| 104 |
today = available_dates[-1]
|
| 105 |
|
| 106 |
data_today = data[data['Date'] == today].between_time("09:15", "15:30")
|