6df67ad7ae
Replays the price-derived engine over stored OHLCV: at each weekly as-of date, rebuild the setup from bars <= D (no lookahead) and walk the actual forward bars for the realized outcome. Reports realized hit-rate/expectancy of qualified setups (and all setups, by direction) plus a probability calibration curve (predicted target prob vs realized hit rate). Reuses pure functions throughout; extracted compute_technical_from_arrays / compute_momentum_from_closes from scoring_service so live and backtest stay in sync. Runs as a weekly/triggerable 'backtest' job caching the report in a SystemSetting; GET /backtest/report serves it. Sentiment/fundamentals held neutral (no point-in-time history) — calibrates the price/S-R/probability machinery. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""Market-level endpoints (benchmark regime)."""
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.dependencies import get_db, require_access
|
|
from app.models.user import User
|
|
from app.schemas.common import APIEnvelope
|
|
from app.services.backtest_service import get_backtest_report
|
|
from app.services.market_regime_service import get_market_regime
|
|
|
|
router = APIRouter(tags=["market"])
|
|
|
|
|
|
@router.get("/market/regime", response_model=APIEnvelope)
|
|
async def market_regime(
|
|
_user: User = Depends(require_access),
|
|
db: AsyncSession = Depends(get_db),
|
|
) -> APIEnvelope:
|
|
"""Current benchmark (SPY) trend regime: bullish / bearish / neutral."""
|
|
data = await get_market_regime(db)
|
|
return APIEnvelope(status="success", data=data)
|
|
|
|
|
|
@router.get("/backtest/report", response_model=APIEnvelope)
|
|
async def backtest_report(
|
|
_user: User = Depends(require_access),
|
|
db: AsyncSession = Depends(get_db),
|
|
) -> APIEnvelope:
|
|
"""Latest cached historical backtest report (None until the job runs)."""
|
|
data = await get_backtest_report(db)
|
|
return APIEnvelope(status="success", data=data)
|