Overall Statistics
class fading_the_gap(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2018, 7, 19)  # Set Start Date
self.SetCash(100000)  # Set Strategy Cash

# Create an event to run every day 0-minute after the close
from sklearn import linear_model
import numpy as np
import pandas as pd
from scipy import stats
from math import floor
from datetime import timedelta

def Initialize(self):

self.SetStartDate(2018,1,1)
self.SetEndDate(2020,1,20)
self.SetCash(10000)

self.numdays = 250   # set length of the training period
self.symbols = []

self.threshold = 1.
for i in tickers :
for i in self.symbols:

def OnData(self, data):

if not (data.ContainsKey("AMD") and data.ContainsKey("ADBE")): return

for symbol in self.symbol():

price_x = pd.Series([float(i.Close) for i in self.symbols[0].hist_window],
index = [i.Time for i in self.symbols[0].hist_window])

price_y = pd.Series([float(i.Close) for i in self.symbols[1].hist_window],
index = [i.Time for i in self.symbols[1].hist_window])

if len (price_x) < 250: return
#try later the rolling version and see if you can get a better results
# >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
# >>> s.rolling(3).std()

ratio = floor(self.Portfolio[self.symbols[1]].Price / self.Portfolio[self.symbols[0]].Price)
# quantity = float(self.CalculateOrderQuantity(self.symbols[0] , 0.4)

# upper threshold i.e. exit and entry signals
if spread [-1] > mean + self.threshold * std:
if not self.Portfolio[self.symbols[0]].Quantity > 0 and not self.Portfolio[self.symbols[0]].Quantity < 0:
self.Sell(self.symbols[1], 100)

elif spread [-1] < mean - self.threshold * std:
if not self.Portfolio[self.symbols[0]].Quantity < 0 and not self.Portfolio[self.symbols[0]].Quantity > 0:
self.Sell(self.symbols[0], 100)

else:
self.Liquidate()

# Your New Python File