Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 1.301 Tracking Error 0.158 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
from AlgorithmImports import * from scipy.stats import stats import numpy as np class BasicTemplateContinuousFutureAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 1, 1) ###self.SetEndDate(2014, 1, 1) self._continuousContract = self.AddFuture(Futures.Indices.SP500EMini, dataNormalizationMode = DataNormalizationMode.BackwardsRatio, dataMappingMode = DataMappingMode.LastTradingDay, contractDepthOffset= 0) self._continuousContractTwoyr = self.AddFuture(Futures.Financials.Y2TreasuryNote, dataNormalizationMode = DataNormalizationMode.BackwardsRatio, dataMappingMode = DataMappingMode.LastTradingDay, contractDepthOffset= 0) self._continuousContractTenyr = self.AddFuture(Futures.Financials.Y10TreasuryNote, dataNormalizationMode = DataNormalizationMode.BackwardsRatio, dataMappingMode = DataMappingMode.LastTradingDay, contractDepthOffset= 0) self._currentContract = None self._smaES = self.SMA(self._continuousContract.Symbol, 5, Resolution.Minute) self._smaTwoyr = self.SMA(self._continuousContractTwoyr.Symbol, 5, Resolution.Minute) self._smaTenyr = self.SMA(self._continuousContractTenyr.Symbol, 5, Resolution.Minute) self._currentContractTwoyr = None self._currentContractTenyr = None self.AddEquity('SPY') self.AddEquity('QQQ') self._smaSPY = self.SMA('SPY', 5, Resolution.Daily) self._smaQQQ = self.SMA('QQQ', 5, Resolution.Daily) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.Midnight, self.PlotPrices); def PlotPrices(self): if not self._smaSPY.IsReady or not self._smaQQQ.IsReady: return if self._continuousContract.HasData and self._continuousContractTwoyr.HasData and self._continuousContractTenyr.HasData: #self.Plot(self._continuousContract.Symbol.ID.Symbol, self._continuousContract.Symbol.ID.Symbol, self._continuousContract.Price) #self.Plot(self._continuousContract.Symbol.ID.Symbol, "_smaES", self._smaES.Current.Value) #self.Plot(self._continuousContractTwoyr.Symbol.ID.Symbol, self._continuousContractTwoyr.Symbol.ID.Symbol, self._continuousContractTwoyr.Price) #self.Plot(self._continuousContractTwoyr.Symbol.ID.Symbol, "_smaTwoyr", self._smaTwoyr.Current.Value) #self.Plot(self._continuousContractTenyr.Symbol.ID.Symbol, self._continuousContractTenyr.Symbol.ID.Symbol, self._continuousContractTenyr.Price) #self.Plot(self._continuousContractTenyr.Symbol.ID.Symbol, "_smaTenyr", self._smaTenyr.Current.Value) #self.spreadPrice = self._smaTenyr.Current.Value - self._smaTwoyr.Current.Value #self.spreadSMA = self._smaTenyr.Current.Value - self._smaTwoyr.Current.Value #self.esPrice = self._continuousContract.Price #self.esSMA = self._smaES.Current.Value #self.Plot("spread" , "spreadPrice" , self.spreadPrice) #self.Plot("spread" , "spreadSMA" , self.spreadSMA) self.spreadSMA = self._smaTenyr.Current.Value - self._smaTwoyr.Current.Value self.esSMA = self._smaES.Current.Value #To Do #================================================================================================================ #How to calculate Divergence and Convergence between spreadSMA and esSMA #How to calculate Correlation of spreadSMA and esSMA #================================================================================================================ #================================================================== #Correlation Coeficient between spreadPrice and esPrice #================================================================== #if self.spreadPrice is None: return #if self.esPrice is None: return #r1 = np.corrcoef(self.spreadPrice , self.esPrice) #self.Debug(r1) #r = stats.pearsonr(self.spreadPrice , self.esPrice) #self.Debug(r) def OnOrderEvent(self, orderEvent): self.Debug("Purchased Stock: {0}".format(orderEvent.Symbol)) def OnSecuritiesChanged(self, changes): self.Debug(f"{self.Time}-{changes}")