Hey everyone,
I'm new to Python and Quantopian. I got this error when I build the algo.
AttributeError: 'SIDData' object has no attribute 'IsInside'
...
USER ALGORITHM:32, in Entry
if (context.S[stock].IsInside):
Can anyone help me out please?
Below is my sample strategy:
import zipline
Inside_bar_min = 5
def initialize(context):
set_symbol_lookup_date('2015-09-01')
context.zyc = symbols('spy','aapl','nflx')[0]
beg_min = 20
end_min = 40
for i in xrange(beg_min,end_min,5):
schedule_function(ReconcileData,date_rules.every_day(),time_rules.market_open(minutes=i))
schedule_function(InsideBar,date_rules.every_day(),time_rules.market_open(minutes=i))
schedule_function(Entry,date_rules.every_day(),time_rules.market_open(minutes=i))
context.S = {}
def handle_data(context,data):
record(Leverage = context.account.leverage)
if (context.zyc in context.S and 'IsInside' in context.S[context.zyc]):
record(InsideBar_count = 2 if context.S[context.zyc].IsInside else 0)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def Entry(context, data):
positions = context.portfolio.positions
openPositions = [stock for stock in positions if positions[stock].amount != 0]
eligible = []
for stock in context.S:
if (stock in openPositions):
continue
if (get_open_orders(stock)):
continue
if (context.S[stock].IsInside):
eligible.append(stock)
eligible += openPositions
eligibleCount = float(len(eligible))
for stock in eligible:
order_target_percent(stock, (1.0 / eligibleCount))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def ReconcileData(context, data):
# Reconcile available stocks into context.S
for stock in data:
if (stock not in context.S):
context.S[stock] = zipline.protocol.SIDData(stock)
# Reconcile backwards for securities we can no longer trade
removeThese = []
for stock in context.S:
if (stock not in data):
removeThese.append(stock)
for stock in removeThese:
del context.S[stock]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def InsideBar(context,data):
highDeck = history(2*Inside_bar_min+1, "1m", "high").dropna(axis=1)
lowDeck = history(2*Inside_bar_min+1, "1m", "low").dropna(axis=1)
highDeck = highDeck[[sid for sid in highDeck if sid in data]]
lowDeck = lowDeck[[sid for sid in lowDeck if sid in data]]
for stock in context.S:
context.S[stock].IsInside = False
isInsideTestFailed = False
context.S[stock].outside_high = max(highDeck[stock].iloc[-10:-6])
context.S[stock].outside_low = min(lowDeck[stock].iloc[-10:-6])
context.S[stock].inside_high = max(highDeck[stock].iloc[-5:-1])
context.S[stock].inside_low = min(lowDeck[stock].iloc[-5:-1])
if context.S[stock].outside_high < context.S[stock].inside_high or context.S[stock].outside_low >context.S[stock].inside_low:
isInsideTestFailed = True
break
if (not isInsideTestFailed):
context.S[stock].IsInside = True
Thank you