Quant Buffet API
Templates
Pre-built make_* factories in backtest.templates.
`backtest.templates` provides reusable **make_*** functions that return (on_day, ready) — the same contract as your own make_on_day body. Import and delegate instead of rewriting common patterns.
Pattern
from backtest.templates import make_sma_trend
ASSETS = ["SPY", "QQQ", "IWM"]
def make_on_day(prices: pd.DataFrame):
return make_sma_trend(prices, ASSETS, {"sma_days": 200})Available factories
| Function | Idea | Key params |
|---|---|---|
make_sma_trend | Long assets above SMA | sma_days (default 200) |
make_dual_ma | Fast MA > slow MA | fast, slow |
make_abs_momentum | Rank by trailing return, top N | lookback, top_n, cash_symbol |
make_dual_momentum | Absolute + relative momentum filter | lookback, top_n |
make_momentum_rotation | Monthly rotate into winners | lookback, top_n |
make_equal_weight | Static equal weight rebalance | rebalance cadence in params |
make_mean_reversion | Buy recent losers (z-score) | lookback, entry_z |
make_vol_target | Scale exposure to vol target | lookback, target_vol |
make_risk_parity | Inverse-vol weights | lookback |
Custom params
from backtest.templates import make_abs_momentum
ASSETS = ["SPY", "EFA", "EEM", "TLT", "GLD", "BIL"]
def make_on_day(prices: pd.DataFrame):
return make_abs_momentum(
prices,
ASSETS,
{"lookback": 126, "top_n": 3, "cash_symbol": "BIL"},
)