michaellupo74 commited on
Commit
f41d71c
·
verified ·
1 Parent(s): 733c07f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -169,8 +169,8 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
169
  with tcol1:
170
  ft_ticker = st.text_input("Ticker", "SPY")
171
  with tcol3:
172
- # Intraday intervals are limited by Yahoo (usually <=60d). Keep it simple here.
173
  ft_interval = st.selectbox("Interval", ["1d", "60m", "30m", "15m"], index=0)
 
174
  # Allowed lookbacks depend on interval
175
  if ft_interval == "1d":
176
  allowed_periods = ["6mo", "1y", "2y", "5y"]
@@ -210,7 +210,13 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
210
  )
211
  if df.empty:
212
  st.error("No data returned. Try a shorter lookback for intraday (e.g., 30d/60d) or use Interval=1d.")
213
- st.stop() # Handle MultiIndex columns (yfinance can return 2-level columns)
 
 
 
 
 
 
214
  if isinstance(df.columns, pd.MultiIndex):
215
  try:
216
  sym = df.columns.get_level_values(1).unique()[0]
@@ -248,6 +254,11 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
248
  tsdf = TimeSeriesDataFrame.from_data_frame(
249
  ts, id_column="item_id", timestamp_column="timestamp"
250
  )
 
 
 
 
 
251
 
252
  with st.spinner("Fine-tuning Chronos-Bolt (small demo)…"):
253
  # Chronos-Bolt preset via hyperparameters; fine_tune on CPU is OK for small steps
@@ -255,6 +266,7 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
255
  prediction_length=int(pred_len), # reuse your UI's pred_len
256
  eval_metric="WQL",
257
  quantile_levels=[0.1, 0.5, 0.9],
 
258
  ).fit(
259
  train_data=tsdf,
260
  enable_ensemble=False,
@@ -295,4 +307,4 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
295
  out.to_csv(index=False).encode("utf-8"),
296
  file_name=f"{item}_chronos_finetuned.csv",
297
  mime="text/csv",
298
- )
 
169
  with tcol1:
170
  ft_ticker = st.text_input("Ticker", "SPY")
171
  with tcol3:
 
172
  ft_interval = st.selectbox("Interval", ["1d", "60m", "30m", "15m"], index=0)
173
+
174
  # Allowed lookbacks depend on interval
175
  if ft_interval == "1d":
176
  allowed_periods = ["6mo", "1y", "2y", "5y"]
 
210
  )
211
  if df.empty:
212
  st.error("No data returned. Try a shorter lookback for intraday (e.g., 30d/60d) or use Interval=1d.")
213
+ st.stop()
214
+
215
+ # Determine frequency alias for AutoGluon and ensure tz-naive index
216
+ freq_alias = {"1d": "B", "60m": "60min", "30m": "30min", "15m": "15min"}.get(ft_interval, "B")
217
+ df.index = pd.DatetimeIndex(df.index).tz_localize(None)
218
+
219
+ # Handle MultiIndex columns (yfinance can return 2-level columns)
220
  if isinstance(df.columns, pd.MultiIndex):
221
  try:
222
  sym = df.columns.get_level_values(1).unique()[0]
 
254
  tsdf = TimeSeriesDataFrame.from_data_frame(
255
  ts, id_column="item_id", timestamp_column="timestamp"
256
  )
257
+ # Ensure a regular time grid for AutoGluon
258
+ try:
259
+ tsdf = tsdf.convert_frequency(freq=freq_alias)
260
+ except Exception:
261
+ pass
262
 
263
  with st.spinner("Fine-tuning Chronos-Bolt (small demo)…"):
264
  # Chronos-Bolt preset via hyperparameters; fine_tune on CPU is OK for small steps
 
266
  prediction_length=int(pred_len), # reuse your UI's pred_len
267
  eval_metric="WQL",
268
  quantile_levels=[0.1, 0.5, 0.9],
269
+ freq=freq_alias,
270
  ).fit(
271
  train_data=tsdf,
272
  enable_ensemble=False,
 
307
  out.to_csv(index=False).encode("utf-8"),
308
  file_name=f"{item}_chronos_finetuned.csv",
309
  mime="text/csv",
310
+ )