Overall Statistics |
Total Orders 3856 Average Win 0.17% Average Loss -0.16% Compounding Annual Return 7.149% Drawdown 30.300% Expectancy 0.433 Net Profit 246.745% Sharpe Ratio 0.378 Sortino Ratio 0.416 Probabilistic Sharpe Ratio 1.490% Loss Rate 31% Win Rate 69% Profit-Loss Ratio 1.07 Alpha 0.01 Beta 0.451 Annual Standard Deviation 0.091 Annual Variance 0.008 Information Ratio -0.191 Tracking Error 0.104 Treynor Ratio 0.076 Total Fees $4484.21 Estimated Strategy Capacity $83000000.00 Lowest Capacity Asset TLT SGNKIKYGE9NP Portfolio Turnover 2.51% |
from AlgorithmImports import * class DynamicAssetAllocationWithVIXAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2005, 1, 1) # Set Start Date self.SetEndDate(2023, 1, 1) # Set End Date self.SetCash(100000) # Set Strategy Cash # Adding Equity and VIX self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol self.tlt = self.AddEquity("TLT", Resolution.Daily).Symbol self.vix = self.AddData(CBOE, "VIX", Resolution.Daily).Symbol # VIX Thresholds for allocation self.vix_threshold_low = 15 self.vix_threshold_high = 30 self.Schedule.On(self.DateRules.EveryDay(self.spy), self.TimeRules.AfterMarketOpen(self.spy, 30), self.RebalancePortfolio) def RebalancePortfolio(self): # Get the current VIX value vix_value = self.Securities[self.vix].Price # Log the current VIX value self.Log(f"Current VIX: {vix_value}") # Adjust allocations based on VIX value if vix_value > self.vix_threshold_high: # High VIX, perceived higher risk, increase TLT allocation self.SetHoldings(self.spy, 0.4) self.SetHoldings(self.tlt, 0.6) elif vix_value < self.vix_threshold_low: # Low VIX, perceived lower risk, increase SPY allocation self.SetHoldings(self.spy, 0.9) self.SetHoldings(self.tlt, 0.1) else: # Moderate VIX, balanced allocation self.SetHoldings(self.spy, 0.7) self.SetHoldings(self.tlt, 0.3)