Run and analyze backtests for trading strategies. Use when testing strategies, optimizing parameters, comparing timeframes, or generating performance reports.
82%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
This skill provides patterns for running backtests and analyzing results in the wicktrade system.
from wicktrade.core.data_manager import DataManager
from wicktrade.strategy.wick_strategy import WickStrategy
from wicktrade.backtest.engine import BacktestEngine
from wicktrade.metrics.reporter import Reporter
# Get data
dm = DataManager()
candles = dm.get_candles("SPY", "15Min", use_cache=True)
# Run backtest
strategy = WickStrategy()
engine = BacktestEngine(strategy, initial_capital=100000)
result = engine.run(candles, "SPY")
# Report
reporter = Reporter()
reporter.print_summary(result)Before running a backtest, verify data availability:
Use get_stock_bars for SPY with timeframe 15Min and limit 10 to check datadm = DataManager()
candles = dm.get_candles("SPY", "15Min", use_cache=True)result = engine.run(candles, "SPY")
reporter.print_summary(result)
reporter.print_trades(result.trades)from wicktrade.backtest.engine import run_backtest
timeframes = ["5Min", "15Min", "30Min", "1Hour"]
results = {}
for tf in timeframes:
candles = dm.get_candles("SPY", tf)
results[tf] = run_backtest("SPY", candles, WickStrategy())
reporter.compare_timeframes(results)config = {
"min_trend_length": 7,
"wick_confirmation_ratio": 0.6,
"stop_loss_multiplier": 2.0,
}
strategy = WickStrategy(config=config)m = result.metrics
# Performance
print(f"Return: {m['total_return_pct']:.2f}%")
print(f"Sharpe: {m['sharpe_ratio']:.2f}")
print(f"Max DD: {m['max_drawdown_pct']:.2f}%")
# Trade quality
print(f"Win Rate: {m['win_rate']:.1f}%")
print(f"Profit Factor: {m['profit_factor']:.2f}")reporter.print_success_criteria(result)winners = result.winning_trades
losers = result.losing_trades
for reason, count in m['exit_reasons'].items():
print(f"{reason}: {count}")from itertools import product
param_grid = {
"min_trend_length": [3, 5, 7],
"wick_confirmation_ratio": [0.4, 0.5, 0.6],
"stop_loss_multiplier": [1.0, 1.5, 2.0],
}
best_sharpe = -float("inf")
best_params = None
for params in product(*param_grid.values()):
config = dict(zip(param_grid.keys(), params))
strategy = WickStrategy(config=config)
result = run_backtest("SPY", candles, strategy)
if result.metrics["sharpe_ratio"] > best_sharpe:
best_sharpe = result.metrics["sharpe_ratio"]
best_params = configtrain_end = int(len(candles) * 0.7)
train_candles = candles[:train_end]
test_candles = candles[train_end:]
train_result = run_backtest("SPY", train_candles, strategy)
test_result = run_backtest("SPY", test_candles, strategy)
print(f"In-sample Sharpe: {train_result.metrics['sharpe_ratio']:.2f}")
print(f"Out-of-sample Sharpe: {test_result.metrics['sharpe_ratio']:.2f}")# Run single backtest
python scripts/run_backtest.py --symbol SPY --timeframe 15Min
# Compare timeframes
python scripts/run_backtest.py --symbol SPY --compare-timeframes
# With custom parameters
python scripts/run_backtest.py --symbol SPY --min-trend-length 7 --show-trades| Issue | Cause | Fix |
|---|---|---|
| Low win rate | Trend detection too loose | Increase min_trend_length |
| High drawdown | Stops too wide | Reduce stop_loss_multiplier |
| Few trades | Entry too strict | Lower confirmation_ratio |
| Negative Sharpe | Strategy not viable | Try different timeframe/symbol |
import json
report_dict = reporter.generate_report_dict(result)
with open("backtest_result.json", "w") as f:
json.dump(report_dict, f, indent=2)Gillinghammer/wicktrade
17cfc8c
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.