Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ st.set_page_config(page_title="Chronos-Bolt Zero-Shot Forecast", layout="centere
|
|
| 8 |
st.title("Chronos-Bolt Zero-Shot Forecast")
|
| 9 |
st.caption("Zero-shot probabilistic forecasting (q10/q50/q90) using amazon/chronos-bolt-* models.")
|
| 10 |
|
|
|
|
| 11 |
def ema(series, length=20):
|
| 12 |
s = pd.Series(series).astype("float64")
|
| 13 |
return s.ewm(span=length, adjust=False).mean()
|
|
@@ -65,7 +66,7 @@ def parse_pasted_series(txt: str):
|
|
| 65 |
toks = re.split(r"[,\s]+", txt.strip())
|
| 66 |
vals = []
|
| 67 |
for t in toks:
|
| 68 |
-
if not t:
|
| 69 |
continue
|
| 70 |
try:
|
| 71 |
vals.append(float(t))
|
|
@@ -158,8 +159,9 @@ if series is not None and series.size > 5:
|
|
| 158 |
)
|
| 159 |
else:
|
| 160 |
st.info("Load a ticker, paste values, or upload a CSV to begin.")
|
| 161 |
-
|
| 162 |
-
#
|
|
|
|
| 163 |
# ================================
|
| 164 |
with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
| 165 |
st.write("Fine-tune Chronos-Bolt on one ticker using indicator covariates (past-only).")
|
|
@@ -176,7 +178,7 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
|
| 176 |
|
| 177 |
if run_ft:
|
| 178 |
with st.spinner("Downloading & computing indicators…"):
|
| 179 |
-
import yfinance as yf
|
| 180 |
from autogluon.timeseries import TimeSeriesPredictor, TimeSeriesDataFrame
|
| 181 |
|
| 182 |
# 1) Load OHLC so we can compute Stochastic (needs High/Low/Close)
|
|
@@ -194,14 +196,10 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
|
| 194 |
# Keep only needed cols and drop NaNs
|
| 195 |
df = df[["Close", "High", "Low"]].dropna().copy()
|
| 196 |
|
| 197 |
-
# 2) Indicators
|
| 198 |
-
|
| 199 |
-
df["
|
| 200 |
-
df["
|
| 201 |
-
stoch = ta.stoch(df["High"], df["Low"], df["Close"], k=14, d=3, smooth_k=3)
|
| 202 |
-
# pandas_ta returns columns like 'STOCHk_14_3_3' / 'STOCHd_14_3_3'
|
| 203 |
-
df["stoch_k"] = stoch.iloc[:, 0]
|
| 204 |
-
df["stoch_d"] = stoch.iloc[:, 1]
|
| 205 |
|
| 206 |
df = df.dropna().astype("float32")
|
| 207 |
if df.shape[0] < 200:
|
|
@@ -246,7 +244,7 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
|
| 246 |
med = ypred["0.5"].to_numpy()
|
| 247 |
hi = ypred["0.9"].to_numpy()
|
| 248 |
|
| 249 |
-
import
|
| 250 |
hx = np.arange(len(yhist))
|
| 251 |
fx = np.arange(len(yhist), len(yhist) + len(med))
|
| 252 |
|
|
@@ -264,4 +262,3 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
|
| 264 |
file_name=f"{item}_chronos_finetuned.csv",
|
| 265 |
mime="text/csv",
|
| 266 |
)
|
| 267 |
-
|
|
|
|
| 8 |
st.title("Chronos-Bolt Zero-Shot Forecast")
|
| 9 |
st.caption("Zero-shot probabilistic forecasting (q10/q50/q90) using amazon/chronos-bolt-* models.")
|
| 10 |
|
| 11 |
+
# -------------------- Indicator helpers (no pandas-ta needed) --------------------
|
| 12 |
def ema(series, length=20):
|
| 13 |
s = pd.Series(series).astype("float64")
|
| 14 |
return s.ewm(span=length, adjust=False).mean()
|
|
|
|
| 66 |
toks = re.split(r"[,\s]+", txt.strip())
|
| 67 |
vals = []
|
| 68 |
for t in toks:
|
| 69 |
+
if not t:
|
| 70 |
continue
|
| 71 |
try:
|
| 72 |
vals.append(float(t))
|
|
|
|
| 159 |
)
|
| 160 |
else:
|
| 161 |
st.info("Load a ticker, paste values, or upload a CSV to begin.")
|
| 162 |
+
|
| 163 |
+
# ================================
|
| 164 |
+
# Train with RSI / EMA / Stochastic (AutoGluon) — no pandas-ta
|
| 165 |
# ================================
|
| 166 |
with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
| 167 |
st.write("Fine-tune Chronos-Bolt on one ticker using indicator covariates (past-only).")
|
|
|
|
| 178 |
|
| 179 |
if run_ft:
|
| 180 |
with st.spinner("Downloading & computing indicators…"):
|
| 181 |
+
import yfinance as yf
|
| 182 |
from autogluon.timeseries import TimeSeriesPredictor, TimeSeriesDataFrame
|
| 183 |
|
| 184 |
# 1) Load OHLC so we can compute Stochastic (needs High/Low/Close)
|
|
|
|
| 196 |
# Keep only needed cols and drop NaNs
|
| 197 |
df = df[["Close", "High", "Low"]].dropna().copy()
|
| 198 |
|
| 199 |
+
# 2) Indicators (helpers above)
|
| 200 |
+
df["rsi14"] = rsi(df["Close"], 14)
|
| 201 |
+
df["ema20"] = ema(df["Close"], 20)
|
| 202 |
+
df["stoch_k"], df["stoch_d"] = stochastic_kd(df["High"], df["Low"], df["Close"], 14, 3, 3)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
df = df.dropna().astype("float32")
|
| 205 |
if df.shape[0] < 200:
|
|
|
|
| 244 |
med = ypred["0.5"].to_numpy()
|
| 245 |
hi = ypred["0.9"].to_numpy()
|
| 246 |
|
| 247 |
+
import matplotlib.pyplot as plt
|
| 248 |
hx = np.arange(len(yhist))
|
| 249 |
fx = np.arange(len(yhist), len(yhist) + len(med))
|
| 250 |
|
|
|
|
| 262 |
file_name=f"{item}_chronos_finetuned.csv",
|
| 263 |
mime="text/csv",
|
| 264 |
)
|
|
|