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
-0.578
Tracking Error
0.278
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
import numpy as np 

class SquareLightBrownPanda(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021,1,1)
        self.SetCash(100000)
        self.pep = self.AddEquity("PEP", Resolution.Daily).Symbol # Add data for PEP
        self.coke = self.AddEquity("COKE", Resolution.Daily).Symbol # Add data for COKE
        
        self.sma_pep = self.SMA(self.pep,5,Resolution.Daily) #create 5 simple moving average indicator
        self.sma_coke = self.SMA(self.coke,5,Resolution.Daily) #create 5 simple moving average indicator
        self.log_ratio_spread_sma = SimpleMovingAverage(5)
        
        self.SetWarmUp(10)

    
    def OnData(self, data):
        # Check if the price SMAs are ready
        if not self.sma_pep.IsReady or not self.sma_coke.IsReady:
            return
        
        # Check if we have data
        if self.pep not in data.Bars or self.coke not in data.Bars:
            return
        
        # Calculate log ratio spread
        log_ratio_pep = np.log(data[self.pep].Price / self.sma_pep.Current.Value)
        log_ratio_coke = np.log(data[self.coke].Price / self.sma_coke.Current.Value)
        log_ratio_spread = log_ratio_pep - log_ratio_coke
        
        # Update and plot SMA of log ratio spread
        if self.log_ratio_spread_sma.Update(data.Time, log_ratio_spread):
            self.Plot("Spread", "log_ratio_spread", log_ratio_spread)
            self.Plot("Spread", "log_ratio_spread_sma", self.log_ratio_spread_sma.Current.Value)