Adisri99's picture
Upload 13 files
e98cfad verified
Raw
History Blame Contribute Delete
1.22 kB
from typing import List, Dict
from pydantic import BaseModel, Field
class PortfolioRequest(BaseModel):
tickers: List[str] = Field(min_length=2, max_length=20)
lookback_days: int = Field(default=365, ge=120, le=1500)
risk_aversion: float = Field(default=8.0, ge=0.1, le=50.0)
max_weight: float = Field(default=0.35, ge=0.05, le=1.0)
sector_limit: float = Field(default=0.70, ge=0.10, le=1.0)
beta_limit: float = Field(default=1.20, ge=0.50, le=3.0)
class WeightItem(BaseModel):
ticker: str
weight: float
class MetricCard(BaseModel):
label: str
value: float
class FactorExposure(BaseModel):
factor: str
exposure: float
limit: float
class QuoteItem(BaseModel):
ticker: str
price: float
day_change_pct: float
class ShapItem(BaseModel):
feature: str
contribution: float
class PortfolioResponse(BaseModel):
tickers: List[str]
weights: List[WeightItem]
metrics: List[MetricCard]
factor_exposures: List[FactorExposure]
quotes: List[QuoteItem]
monte_carlo_quantiles: Dict[str, float]
backtest_points: List[Dict[str, float]]
shap_top_features: Dict[str, List[ShapItem]]
notes: List[str] = Field(default_factory=list)