| Overall Statistics |
|
Total Orders 593 Average Win 0.56% Average Loss -0.05% Compounding Annual Return 42.148% Drawdown 22.900% Expectancy 9.737 Start Equity 100000 End Equity 300424.15 Net Profit 200.424% Sharpe Ratio 1.119 Sortino Ratio 1.292 Probabilistic Sharpe Ratio 61.464% Loss Rate 12% Win Rate 88% Profit-Loss Ratio 11.18 Alpha 0.264 Beta 0.07 Annual Standard Deviation 0.238 Annual Variance 0.057 Information Ratio 0.8 Tracking Error 0.281 Treynor Ratio 3.8 Total Fees $628.86 Estimated Strategy Capacity $5200000.00 Lowest Capacity Asset OEF RZ8CR0XXNOF9 Portfolio Turnover 1.79% |
#region imports
from AlgorithmImports import *
#endregion
#https://chat.openai.com/share/923ff83d-011b-4416-b37f-3f586510e37d
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect import Resolution
class VXXMOMENTUMPredictsStockIndexReturns(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 3, 1)
self.SetEndDate(2025, 4, 15)
self.SetCash(100000)
self.oef = "OEF"
self.vxx = "VXX"
self.AddEquity(self.oef, Resolution.Daily)
self.AddEquity(self.vxx, Resolution.Daily)
# Set OEF as the benchmark
self.SetBenchmark(self.oef)
# Parameters
params = ['ema-slow', 'ema-fast', 'leverage_up', 'leverage_down']
self.params = {p: int(self.GetParameter(p)) for p in params}
# Indicators
self.emaFast = self.EMA(self.vxx, self.params['ema-fast'])
self.emaSlow = self.EMA(self.vxx, self.params['ema-slow'])
# To simulate a full investment in OEF from the start
self.initialOEFPrice = None # This will be set on the first available price
self.hypotheticalOEFInvestment = self.Portfolio.Cash
def OnData(self, data):
if not data.ContainsKey(self.vxx) or data[self.vxx] is None or data[self.vxx].Close is None:
self.Log("VXX data is missing or incomplete.")
return
if not data.ContainsKey(self.oef) or data[self.oef] is None or data[self.oef].Close is None:
self.Log("OEF data is missing or incomplete.")
return
vxx_close = data[self.vxx].Close
oef_close = data[self.oef].Close
self.PlotIndicators(vxx_close, oef_close)
self.EvaluatePositions()
def PlotIndicators(self, vxx_close, oef_close):
self.Plot("My Indicators", "slow Signal", self.emaSlow.Current.Value)
self.Plot("My Indicators", "Fast Signal", self.emaFast.Current.Value)
self.Plot("My Indicators", "VXX", vxx_close)
# Initial OEF price setting
if self.initialOEFPrice is None:
self.initialOEFPrice = oef_close
# Hypothetical investment value
hypotheticalValue = self.hypotheticalOEFInvestment / self.initialOEFPrice * oef_close
# Plot Strategy Equity and Benchmark with two scales
self.Plot("Strategy Equity", "Portfolio Value", self.Portfolio.TotalPortfolioValue)
self.Plot("Strategy Equity", "Hypothetical OEF Investment", hypotheticalValue)
def EvaluatePositions(self):
if self.emaFast.Current.Value > self.emaSlow.Current.Value:
self.SetHoldings(self.oef, -1.5 * self.params['leverage_up'])
elif self.emaFast.Current.Value < self.emaSlow.Current.Value:
self.SetHoldings(self.oef, 1.5 * self.params['leverage_down'])
else:
self.SetHoldings(self.oef, 1.0)