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.

Formula
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

NameTypeDescription
tintLookback period in trading days (default: 20)
pricesDataFrameDataFrame of historical prices with datetime index

How It Works

  1. Fetch historical closing prices for all assets in the universe
  2. Calculate momentum = current price - price t periods ago
  3. Rank assets by momentum score (highest first)
  4. Select top N assets for the portfolio
  5. 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

RankSymbolNameScoreSignal
#1MSFTMicrosoft Corp.13.3631Buy
#2AMZNAmazon.com Inc.1.6091Buy
#3GOOGLAlphabet Inc.-0.7583Buy
#4TSLATesla Inc.-5.6844Hold
#5AAPLApple Inc.-6.3859Hold

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.

Formula
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

NameTypeDescription
tintMoving average window in trading days (default: 20)
pricesDataFrameDataFrame of historical prices

How It Works

  1. Calculate t-period Simple Moving Average for each asset
  2. Compute deviation = current price - SMA
  3. Rank assets by deviation (ascending — most oversold first)
  4. Select top N most oversold assets
  5. Allocate weights via the chosen optimizer

Live Demo — Ranking Output

Ranked using 252 days of generated sample data for AAPL, MSFT, GOOGL, AMZN, TSLA

RankSymbolNameScoreSignal
#1AAPLApple Inc.-7.2355Buy
#2TSLATesla Inc.0.0636Buy
#3GOOGLAlphabet Inc.0.3388Buy
#4AMZNAmazon.com Inc.1.2165Hold
#5MSFTMicrosoft Corp.10.6061Hold

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.

Formula
SmartBeta(i) = mean(R_i) / std(R_i)

Where R_i are the returns of asset i. Higher ratio = better risk-adjusted performance.

Parameters

NameTypeDescription
pricesDataFrameDataFrame of historical prices

How It Works

  1. Calculate daily returns for each asset
  2. Compute mean return and standard deviation for each
  3. Calculate ratio: mean / std (risk-adjusted return)
  4. Rank by ratio descending (highest risk-adjusted return first)
  5. 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

RankSymbolNameScoreSignal
#1MSFTMicrosoft Corp.0.0858Buy
#2TSLATesla Inc.0.0081Buy
#3AAPLApple Inc.-0.0034Buy
#4GOOGLAlphabet Inc.-0.0054Hold
#5AMZNAmazon.com Inc.-0.0755Hold

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()