In [1]:
%matplotlib inline
# Imports
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Jupyter")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Market import TradeBar, QuoteBar
from QuantConnect.Jupyter import *
from QuantConnect.Indicators import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


# Create an instance
qb = QuantBook()
print (qb)
QuantConnect.Jupyter.QuantBook
In [2]:
qqq = qb.AddEquity("QQQ")
print(qqq)
QQQ
In [3]:
h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily)
h1.head(5)
Out[3]:
open high low close volume
symbol time
QQQ 2017-02-04 123.870408 124.206073 123.732193 124.077731 10665917.0
2017-02-07 123.821046 124.235691 123.751938 124.215946 6417229.0
2017-02-08 124.452886 124.936639 124.364034 124.670082 10138781.0
2017-02-09 124.502249 125.064982 124.275181 124.907022 8450881.0
2017-02-10 125.015619 125.617843 124.951448 125.351285 9305337.0
In [4]:
QQQ_Closing = pd.DataFrame(h1.close)
QQQ_Closing.head()
Out[4]:
close
symbol time
QQQ 2017-02-04 124.077731
2017-02-07 124.215946
2017-02-08 124.670082
2017-02-09 124.907022
2017-02-10 125.351285
In [5]:
def sample(QQQ_Closing):
    #the number of days
    counter = 0
    i = 0
    while(True):
        previous_close = QQQ_Closing[i]
        current_close = QQQ_Closing[i+1]
        #checks if previous_close is less
        if(previous_close < current_close):
            #goes to next day and increases the day count
            counter = counter+1
            i=i+1
        else:
            #returns the number of days
            return counter