import datetime
import numpy as np
import pandas as pd
import mlfinlab as ml
from scipy import stats
class ModulatedHorizontalAutosequencers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 18) # Set Start Date
self.SetEndDate(2019, 1, 19)
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Tick)
self.start = datetime.date(2019, 1, 15)
self.end = datetime.date(2019, 1, 17)
self.features = ["open", "high", "low", "close", "volume"]
self.estado = True
def OnData(self, data):
if self.estado:
h1 = self.History(self.Securities.Keys,
self.start,
self.end,
Resolution.Tick)
data = h1[h1.suspicious == False]
data = data[["lastprice", "quantity"]]
data = data.loc["SPY R735QTJ8XC9X"]
df = pd.DataFrame()
df["date_time"] = data.index.values
df["price"] = data.lastprice.values
df["volume"] = data.quantity.values
df.to_csv('raw_tick_data.csv', index=False)
volume = ml.data_structures.get_volume_bars('raw_tick_data.csv',
threshold=20000,
batch_size=1000000,
verbose=False)
self.Debug(volume.head())
self.estado = False