Skip to main content
This example uses backtest_strategy followed by factor_analysis. It’s the most common two-step workflow: test a strategy, then understand where the returns came from.

User prompt

“I want to test a strategy that buys the top 20% momentum stocks in the Nasdaq 100, rebalanced monthly. How would it have done over the last 2 years?”

Step 1:Backtest

Response:
Agent summary:
  • Total return: +48.1% over 2 years (21.9% CAGR)
  • Sharpe ratio: 1.56:strong risk-adjusted returns
  • Max drawdown: -12.3%:manageable
  • Calmar ratio: 1.77:good return per unit of peak-to-trough risk
  • Turnover: 3.82x/year:fairly active at 412 trades (expected for momentum)

Step 2:Factor decomposition

The user follows up: “Where is the return coming from?”
Response:
Agent interpretation: Alpha is statistically significant:8.2% annualized, t-stat 2.34. There is genuine edge beyond factor exposure. Factor breakdown:
  • Market (1.12):Slightly higher beta than the market. Amplifies both gains and losses.
  • Size (-0.35):Large-cap tilt, expected for Nasdaq 100.
  • Value (-0.29):Anti-value tilt, expected for a momentum strategy that favors expensive growth stocks.
  • Momentum (0.45):Significant momentum loading, as expected. But the stock selection within the momentum bucket is adding extra value beyond the factor alone.
R-squared: 0.82:82% of variance explained by factors. The remaining 18% is idiosyncratic.
The 1.12 market beta means this strategy will significantly underperform in a bear market. The strong backtest period (2023–2025) was largely bullish:consider stress-testing on 2022 data.