Scalar Field
Backtest a contrarian sentiment-based rebalancing strategy using historical data. The strategy adjusts portfolio allocation based on the VIX (CBOE Volatility Index) to exploit extreme market sentiment. The portfolio consists of SPY (S&P 500 ETF) and TLT (U.S. Treasury Bond ETF). The allocation rules are: if VIX < 15, allocate 50% to SPY and 50% to TLT; if VIX > 25, allocate 90% to SPY and 10% to TLT; otherwise, maintain a 60% SPY and 40% TLT allocation. Rebalancing occurs monthly on the first trading day. Consider transaction costs of 0.1% per trade. Evaluate performance using CAGR, max drawdown, Sharpe ratio, and volatility. Compare the results to a standard 60/40 stock-bond portfolio.

I'll help you backtest this VIX-based contrarian strategy. Let me outline the steps and confirm the approach:

  1. First, we'll need to get historical data for:

    • VIX (^VIX)
    • SPY (S&P 500 ETF)
    • TLT (Treasury Bond ETF)
  2. The strategy rules are clear:

    • VIX < 15: 50% SPY, 50% TLT
    • VIX > 25: 90% SPY, 10% TLT
    • Otherwise: 60% SPY, 40% TLT
  3. We'll need to:

    • Get monthly dates for rebalancing
    • Check VIX levels on each rebalancing date
    • Create portfolio weights based on VIX levels
    • Use backtest_portfolio function with monthly rebalancing
    • Compare with a static 60/40 portfolio

Before proceeding, I should confirm:

  1. What period would you like to analyze? (I suggest using 5 years of data from 2020-01-01 to 2024-12-31 for a comprehensive analysis)
  2. Would you like to see the portfolio weights at each rebalancing date in addition to the performance metrics?

Please confirm these details or provide your preferred specifications.

do it for last 10 years rest use defaults

I'll proceed with generating the procedure for a 10-year backtest (2015-01-01 to 2024-12-31). The logic is clear and I'll batch all data requests. Here's the procedure:

  • VIX-Based Strategy Performance:

    • Total Return: -125.67%
    • Annualized Return: NaN
    • Volatility: 328.01%
    • Sharpe Ratio: 0.28
    • Max Drawdown: -124.83%
    • Final Portfolio Value: -$2,564.49
  • Static 60/40 Strategy Performance:

    • Total Return: 47.16%
    • Annualized Return: 3.95%
    • Volatility: 53.23%
    • Sharpe Ratio: 0.26
    • Max Drawdown: -66.16%
    • Final Portfolio Value: $14,701.40
  • VIX Level Distribution at Rebalancing Dates:

    • Medium VIX: 51 occurrences
    • Low VIX (<15): 50 occurrences
    • High VIX (>25): 19 occurrences

Suggested next analyses:

  • Compare the VIX-based strategy with other volatility-based strategies.
  • Analyze the impact of different transaction costs on the VIX-based strategy.
  • Evaluate the performance of the VIX-based strategy in different market conditions (e.g., bull vs. bear markets).