Hi all,
I am a complete beginner when it comes to Python/Quantopian (which will quickly become evident to anyone who continues reading...). I am wondering whether anyone would be kind enough to explain where I am going wrong with the below code. I am getting a Syntax Error on the first order, however I have no idea how to fix this..
Many thanks,
Dean
# Put any initialization logic here. The context object will be passed to
# the other methods in your algorithm.
def initialize(context):
context.securities = symbol('SPY', # SPDR S&P 500 ETF
'TLT') # iShares 20+ year treasury bond ETF
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
record ('cash', context.portfolio.cash, 'leverage', context.portfolio.leverage,
'SPY', data.symbol('SPY').price, 'TLT', data.symbol('TLT').price,
MA = data[symbol('SPY')].mavg(100),
current_price = data[symbol('SPY')].price
# If current price of SPY is greater than its MA, buy SPY.
if current_price > MA
order_target_percent(symbol('SPY'), 1)
order_target_percent(symbol('TLT'), 0)
log.info ('Long SPY'),
# If not, buy TLT
elif current_price <= MA:
order_target_percent(symbol('TLT'), 1)
order_target_percent(symbol('SPY'), 0)
log.info ('Long TLT')
```.