Trading Strategies
Explore how each strategy selects and ranks assets for portfolio construction.
Momentum Strategy
Selects assets with the strongest recent price momentum, betting that recent winners will continue to outperform.
Momentum(i) = P(i, today) - P(i, today - t)
Where P(i,t) is the price of asset i at time t, and t is the lookback period (default: 20 days)
Parameters
| Name | Type | Description |
|---|---|---|
t | int | Lookback period in trading days (default: 20) |
prices | DataFrame | DataFrame of historical prices with datetime index |
How It Works
- Fetch historical closing prices for all assets in the universe
- Calculate momentum = current price - price t periods ago
- Rank assets by momentum score (highest first)
- Select top N assets for the portfolio
- Pass selected assets to the optimizer for weight allocation
Live Demo — Ranking Output
Ranked using 252 days of generated sample data for AAPL, MSFT, GOOGL, AMZN, TSLA
| Rank | Symbol | Name | Score | Signal |
|---|---|---|---|---|
| #1 | MSFT | Microsoft Corp. | 13.3631 | Buy |
| #2 | AMZN | Amazon.com Inc. | 1.6091 | Buy |
| #3 | GOOGL | Alphabet Inc. | -0.7583 | Buy |
| #4 | TSLA | Tesla Inc. | -5.6844 | Hold |
| #5 | AAPL | Apple Inc. | -6.3859 | Hold |
Sample Backtest Performance
When to Use
Best for trending markets with clear directional moves. Commonly used in cross-sectional equity strategies.
Pros
- Simple and intuitive
- Well-documented academic support
- Works in trending markets
- Easy to implement and backtest
Cons
- Suffers in mean-reverting markets
- Can lead to high turnover
- Momentum crashes during regime changes
- Lookback period sensitivity
Code Example
from tradepilot.ranking import momentum_ranking
# Rank assets by 20-day momentum
scores = momentum_ranking(prices, t=20)
# Higher score = stronger momentum
selected = scores.nlargest(5).index.tolist()Mean Reversion Strategy
Identifies oversold assets trading below their moving average, betting they will revert to the mean.
Deviation(i) = P(i, today) - SMA(i, t)
Where SMA(i,t) is the Simple Moving Average of asset i over t periods. Most negative = most oversold.
Parameters
| Name | Type | Description |
|---|---|---|
t | int | Moving average window in trading days (default: 20) |
prices | DataFrame | DataFrame of historical prices |
How It Works
- Calculate t-period Simple Moving Average for each asset
- Compute deviation = current price - SMA
- Rank assets by deviation (ascending — most oversold first)
- Select top N most oversold assets
- Allocate weights via the chosen optimizer
Live Demo — Ranking Output
Ranked using 252 days of generated sample data for AAPL, MSFT, GOOGL, AMZN, TSLA
| Rank | Symbol | Name | Score | Signal |
|---|---|---|---|---|
| #1 | AAPL | Apple Inc. | -7.2355 | Buy |
| #2 | TSLA | Tesla Inc. | 0.0636 | Buy |
| #3 | GOOGL | Alphabet Inc. | 0.3388 | Buy |
| #4 | AMZN | Amazon.com Inc. | 1.2165 | Hold |
| #5 | MSFT | Microsoft Corp. | 10.6061 | Hold |
Sample Backtest Performance
When to Use
Best for range-bound or mean-reverting markets. Pairs well with the GMV optimizer for risk management.
Pros
- Contrarian approach captures rebounds
- Works well in range-bound markets
- Can identify undervalued assets
- Natural buy-low mechanism
Cons
- Can catch falling knives
- Underperforms in strong trends
- Requires accurate mean estimation
- Risk of value traps
Code Example
from strategies.mean_reversion import mean_reversion_strategy
# Find assets below their 20-day moving average
ordered = mean_reversion_strategy(prices, t=20)
# First assets are most oversold
selected = ordered[:5]Smart Beta Strategy
Ranks assets by their risk-adjusted returns (return per unit of risk), similar to a per-asset Sharpe ratio.
SmartBeta(i) = mean(R_i) / std(R_i)
Where R_i are the returns of asset i. Higher ratio = better risk-adjusted performance.
Parameters
| Name | Type | Description |
|---|---|---|
prices | DataFrame | DataFrame of historical prices |
How It Works
- Calculate daily returns for each asset
- Compute mean return and standard deviation for each
- Calculate ratio: mean / std (risk-adjusted return)
- Rank by ratio descending (highest risk-adjusted return first)
- Select top N assets and optimize weights
Live Demo — Ranking Output
Ranked using 252 days of generated sample data for AAPL, MSFT, GOOGL, AMZN, TSLA
| Rank | Symbol | Name | Score | Signal |
|---|---|---|---|---|
| #1 | MSFT | Microsoft Corp. | 0.0858 | Buy |
| #2 | TSLA | Tesla Inc. | 0.0081 | Buy |
| #3 | AAPL | Apple Inc. | -0.0034 | Buy |
| #4 | GOOGL | Alphabet Inc. | -0.0054 | Hold |
| #5 | AMZN | Amazon.com Inc. | -0.0755 | Hold |
Sample Backtest Performance
When to Use
Best for investors seeking risk-adjusted returns. Works well for long-term portfolio construction.
Pros
- Risk-aware selection
- Favors consistent performers
- Less volatile portfolios
- Academic Sharpe ratio foundation
Cons
- Backward-looking (past ≠ future)
- Penalizes high-growth volatile stocks
- Sensitive to estimation period
- May underperform in bull markets
Code Example
from strategies.smart_beta import smart_beta_strategy
# Rank by risk-adjusted return (mean/std)
scores = smart_beta_strategy(prices)
selected = scores.nlargest(5).index.tolist()