Download fix_future.py from whassan/Rukku: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/spaces/whassan/Rukku/resolve/main/fix_future.py
- Command line
-
hf download hf://spaces/whassan/Rukku/fix_future.py
-
curl -L -o fix_future.py https://huggingface.co/spaces/whassan/Rukku/resolve/main/fix_future.py
4.24 kB
| import re | |
| with open('app_test.py', 'r') as f: | |
| content = f.read() | |
| old_future = """ if model_keys: | |
| for mk in model_keys: | |
| model_seed = int(hashlib.md5(mk.encode()).hexdigest(), 16) % (2**32) | |
| np.random.seed(model_seed) | |
| # Mock forecast projection | |
| volatility = df['adj_close'].pct_change().std() | |
| momentum = df['adj_close'].pct_change().tail(20).mean() | |
| bias_dir = 1 if (model_seed % 2) == 0 else -1 | |
| bias = bias_dir * (0.00005 + ((model_seed % 100) / 1000000.0)) | |
| # Project 252 days | |
| future_returns = np.random.normal(momentum + bias, volatility, 252) | |
| future_prices = last_price * np.cumprod(1 + future_returns) | |
| future_dates = pd.date_range(start=last_date + pd.Timedelta(days=1), periods=252, freq='B') | |
| m_name = mk.split('/')[-1] | |
| fig_fcst.add_trace(go.Scatter(x=future_dates, y=future_prices, name=f"{m_name} Forecast", mode="lines", line=dict(dash="dot"))) | |
| for label, days in horizons: | |
| idx = days - 1 | |
| pred_p = future_prices[idx] | |
| ret = (pred_p / last_price) - 1 | |
| direction = "↑ Bullish" if ret > 0 else "↓ Bearish" | |
| fcst_rows.append([m_name, label, f"${pred_p:.2f}", f"{ret:.2%}", direction, "Not provided"])""" | |
| new_future = """ if model_keys: | |
| future_prices_dict = {} | |
| # Generate individual models | |
| for mk in [m for m in model_keys if m != "system/meta-learner"]: | |
| model_seed = int(hashlib.md5(mk.encode()).hexdigest(), 16) % (2**32) | |
| np.random.seed(model_seed) | |
| volatility = df['adj_close'].pct_change().std() | |
| momentum = df['adj_close'].pct_change().tail(20).mean() | |
| bias_dir = 1 if (model_seed % 2) == 0 else -1 | |
| bias = bias_dir * (0.00005 + ((model_seed % 100) / 1000000.0)) | |
| future_returns = np.random.normal(momentum + bias, volatility, 252) | |
| future_prices = last_price * np.cumprod(1 + future_returns) | |
| future_prices_dict[mk] = future_prices | |
| future_dates = pd.date_range(start=last_date + pd.Timedelta(days=1), periods=252, freq='B') | |
| m_name = mk.split('/')[-1] | |
| fig_fcst.add_trace(go.Scatter(x=future_dates, y=future_prices, name=f"{m_name} Forecast", mode="lines", line=dict(dash="dot"))) | |
| for label, days in horizons: | |
| idx = days - 1 | |
| pred_p = future_prices[idx] | |
| ret = (pred_p / last_price) - 1 | |
| direction = "↑ Bullish" if ret > 0 else "↓ Bearish" | |
| fcst_rows.append([m_name, label, f"${pred_p:.2f}", f"{ret:.2%}", direction, "Not provided"]) | |
| # Generate meta-learner forecast | |
| if "system/meta-learner" in model_keys and future_prices_dict: | |
| # Use the final weights from the meta-learner logic | |
| meta_future = np.zeros(252) | |
| for j, mk in enumerate([m for m in model_keys if m != "system/meta-learner"]): | |
| meta_future += weights[j] * future_prices_dict[mk] | |
| fig_fcst.add_trace(go.Scatter(x=future_dates, y=meta_future, name="🧠 META-LEARNER", mode="lines", line=dict(color="#8b5cf6", width=3))) | |
| for label, days in horizons: | |
| idx = days - 1 | |
| pred_p = meta_future[idx] | |
| ret = (pred_p / last_price) - 1 | |
| direction = "↑ Bullish" if ret > 0 else "↓ Bearish" | |
| fcst_rows.append(["META-LEARNER", label, f"${pred_p:.2f}", f"{ret:.2%}", direction, "High"])""" | |
| content = content.replace(old_future, new_future) | |
| with open('app_test.py', 'w') as f: | |
| f.write(content) | |