stock_prediction_daily, stock_prediction_hourly, stock_prediction_15min) apply when RollingCreditsService is used.
1. Overview
Code:
app/services/stock_prediction_service.py, app/services/chronos_model_manager.py, app/services/market_data_service.py, app/stock_prediction_core/backtesting.py, modal_app/app.py, app/api/stock_prediction_routes.py
2. Configuration
2.1 Feature and Lookback
2.2 Market Data (OHLCV for Prediction and Backtesting)
Market data is provided by MarketDataService: Alpaca first (when enabled), then yahooquery.
Config (Alpaca as data source):
Same keys are used for trading (place/cancel orders, portfolio). Base URL:
ALPACA_BASE_URL (e.g. https://paper-api.alpaca.markets for paper).
2.3 Chronos: Modal vs Local
Local Chronos (
STOCK_PREDICTION_USE_LOCAL=true):
STOCK_PREDICTION_USE_LOCAL=false):
Modal image:
modal_app/image.py (chronos-bolt, torch, alpaca-py, pandas, etc.).
3. APIs and UI
UI: Trading Dashboard → Predictions (run prediction, Chronos model dropdown, chart, order recommendation), Backtest (form, equity curve, trades table).
4. Backtesting
- Strategies:
combined,trend,mean_reversion,momentum,volatility,stat_arb - Timeframes:
1d,1h,15m(mapped to 1D, 1H, 15Min for data) - Data:
MarketDataService.get_historical_data(Alpaca or yahooquery). Requires ≥130 bars; for 1d, typically ≥6 months of history. - Request:
symbol,start,end(YYYY‑MM‑DD),strategy,timeframe,initial_capital(default 100_000) - Response:
total_return,sharpe_ratio,max_drawdown,win_rate,n_trades,equity_curve,trades,metadata
5. Rolling Credits (Stock Prediction)
WhenRollingCreditsService is used, stock_prediction_daily, stock_prediction_hourly, stock_prediction_15min are deducted. Tier allocation is in Rolling Credits Setup. If the user has no balance, prediction may be refused depending on service wiring.
6. Quick Start
- Set
STOCK_PREDICTION_ENABLED=true. - Market data: either
ALPACA_DATA_ENABLED=trueandALPACA_API_KEY,ALPACA_API_SECRET(andALPACA_BASE_URLfor trading), or- Rely on yahooquery (
pip install yahooquery).
- Chronos:
- Modal:
pip install modal,modal token new; deploy/run withMODAL_USE_GPU=1if you want GPU. SetMODAL_TOKEN_ID/MODAL_TOKEN_SECRETonly if the server needs to spawn Modal runs. - Local:
STOCK_PREDICTION_USE_LOCAL=true,pip install chronos-bolt torch, setCHRONOS_DEVICE(e.g.cudaif GPU).
- Modal:
- Open Trading → Predictions and Backtest.