Hi,
I trade on multiple periods of time and want to set up various daily static calculations during the initialisation function of Quantopian.
As I'm quite a novice python programmer, I'm having a little difficulty and would like your assistance.
Here's my code:
import math
import talib as ta
import pandas as pd
import numpy as np
def initialize(context):
context.aapl = sid(24)
context.max_notional = 100000.1
context.min_notional = 0
historical_closes = history(bar_count=365, frequency='1d', field='close_price')
context.daily = historical_closes[context.aapl] ###### line 14
context.sma50_daily = ta.SMA(context.daily, timeperiod=50)
context.sma200_daily = ta.SMA(context.daily, timeperiod=200)
macd_daily = ta.MACD(context.daily, fastperiod=12, slowperiod=26, signalperiod=9)
context.macd_daily = macd_daily
context.macd_ema30_daily = ta.EMA(macd_daily, timeperiod=30)
weekly = historical_closes
context.weekly = weekly.resample('1W')
context.sma50_weekly = ta.SMA(np.array(context.weekly), timeperiod=50)
context.sma200_weekly = ta.SMA(np.array(context.weekly), timeperiod=200)
macd_weekly = ta.MACD(np.array(context.weekly), fastperiod=12, slowperiod=26, signalperiod=9)
context.macd_weekly = macd_weekly
context.macd_ema30_weekly = ta.EMA(np.array(macd_weekly), timeperiod=30)
But I'm getting this error in the IDE:
14 Error Runtime exception: KeyError: u'no item named Security(24 [AAPL])'
What am I doing wrong and how should it be done please?
Thanks in advance for your help.
Andrew