backtesting

Backtest trading strategies with 30+ risk ratios, event-driven engine, and forward simulation.

Updated Aug 13, 2026
One-click install
npx skills add https://github.com/Martino17x/Sentinel-Invest --skill backtesting-martino17x
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backtesting
Source: https://github.com/Martino17x/Sentinel-Invest/tree/main/.agents/skills/backtesting
Command: npx skills add https://github.com/Martino17x/Sentinel-Invest --skill backtesting-martino17x

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, pandas, scipy, statsmodels, pytest, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? Evaluating a trading strategy requires more than a single Sharpe ratio: you need risk metrics, parameter optimization, out-of-sample validation, and forward-looking risk projections. This Skill implements the full 5-stage backtesting methodology (Data → Research → Metrics → Parameterisation → Validation) in flat numpy/pandas Python, so quantitative researchers can rigorously test strategies without heavy dependencies. ## Core Features & Use Cases - 30+ Risk and Performance Ratios: Sharpe, Sortino, max drawdown, VaR/cVaR (empirical, normal, Johnson SU), Kelly fraction, Rachev A/B/C, profit factor, risk of ruin, all as flat vectorized numpy functions. - Event-Driven Engine with 8 Strategies: SMA crossover, RSI mean-reversion, Bollinger contrarian, MACD, ADX trend, momentum, and more, with commission and slippage modeling and proper signal shifting to avoid look-ahead bias. - Validation and Simulation: Walk-forward cross-validation with IS/OOS splits, parameter sweeps, Monte Carlo search, Markowitz portfolio optimization, and forward simulation using Johnson SU marginals with t/Gaussian/Clayton/Gumbel/Frank copulas. - Use Case: Load a CSV of SPY prices, run a walk-forward validation of an SMA(50/200) crossover strategy, compare in-sample vs out-of-sample Sharpe ratios, then project 10,000 forward wealth paths to estimate the probability of a 30% drawdown. ## Quick Start Run the backtesting CLI on the bundled S&P 500 returns CSV to compute all 30+ risk and performance ratios, then execute the 4-level validation suite to verify mathematical correctness.

Frequently Asked Questions about backtesting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I backtest a trading strategy in Python?▼

Load OHLCV data into the BacktestEngine class, choose one of 8 built-in strategies like sma_crossover, and call run() with your parameters. The engine returns trades, per-trade summaries, and a full metrics dictionary including Sharpe, max drawdown, and CAGR.

How to run walk-forward validation on a trading strategy?▼

Use the walkforward CLI mode with a prices CSV, specifying the number of splits and gap size. It generates expanding in-sample and out-of-sample windows and reports IS vs OOS Sharpe and CAGR per split to detect overfitting.

What Python libraries are needed for this backtesting framework?▼

Only numpy, pandas, and scipy are required for all ratios, indicators, the engine, and simulations. Statsmodels is optional for STL decomposition, and pytest is needed only to run the Level 4 regression tests.

Why use Johnson SU distribution instead of Normal for VaR?▼

The Normal distribution consistently underestimates VaR because equity returns have skewness and heavy tails. Johnson SU has four parameters that capture arbitrary skew and kurtosis, producing VaR errors near zero on equity data as verified by KS tests.

Can I simulate correlated multi-asset portfolios with copulas?▼

Yes, the simulations CLI fits marginal distributions per asset, transforms them to uniform via CDF, then fits a t, Gaussian, Clayton, Gumbel, or Frank copula. It samples correlated paths and back-transforms them into synthetic returns for portfolio risk analysis.

What are the limitations of this backtesting framework?▼

The engine is long-only and bar-by-bar, so it does not model intraday execution, short selling mechanics, or market impact. Clayton, Gumbel, and Frank copula fitting is limited to two assets, and sentiment and exogenous indicator classes have no code implementation.