Skip to main content
Stock prediction provides daily, hourly, and 15‑minute forecasts (Chronos or technical strategies), backtesting over OHLCV, order recommendations, and market-status. It depends on market data (Alpaca or yahooquery) and optionally Chronos via Modal or locally. Rolling credits (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):
Modal (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)

When RollingCreditsService 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

  1. Set STOCK_PREDICTION_ENABLED=true.
  2. Market data: either
    • ALPACA_DATA_ENABLED=true and ALPACA_API_KEY, ALPACA_API_SECRET (and ALPACA_BASE_URL for trading), or
    • Rely on yahooquery (pip install yahooquery).
  3. Chronos:
    • Modal: pip install modal, modal token new; deploy/run with MODAL_USE_GPU=1 if you want GPU. Set MODAL_TOKEN_ID/MODAL_TOKEN_SECRET only if the server needs to spawn Modal runs.
    • Local: STOCK_PREDICTION_USE_LOCAL=true, pip install chronos-bolt torch, set CHRONOS_DEVICE (e.g. cuda if GPU).
  4. Open Trading → Predictions and Backtest.

7. Troubleshooting