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.768
Tracking Error
0.165
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);
        
        self.indicator_history = pd.DataFrame()
        self.history_length = 30

        
    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.spreadSMA = self._smaTenyr.Current.Value - self._smaTwoyr.Current.Value
            self.esSMA = self._smaES.Current.Value

            row = pd.DataFrame({'spreadSMA': [self.spreadSMA], 
                                'esSMA': [self.esSMA]})
            self.indicator_history = pd.concat([self.indicator_history, row]).iloc[-self.history_length:]
            if self.indicator_history.shape[0] < self.history_length:
                return
            corr = self.indicator_history[['spreadSMA', 'esSMA']].corr()['spreadSMA'][1]
            self.Plot("Correlation", "Value", corr)