I'm coming over from Quantopian, and I am trying to get an algo that was shared there to work on QuantConnect. 

I've attached the backtest of the code, in which I've done a few changes to try to get it to work on QuantConnect. It would be great if someone can help make the remaining adjustments. I'm currently still learning Python, and with the switch from Quantopian, it's been a bit overwhelming. 

The following is the original code from Quantopian:


def initialize(context):
# date_rules.week_start(days_offset=0)
# date_rules.every_day()

set_commission(commission.PerShare(cost=0.00, min_trade_cost=1))
schedule_function(trade, date_rules.week_start(days_offset=0), time_rules.market_open(minutes = 33))

def trade(context, data):

qqq_symbol = symbol('TQQQ')
tmf_symbol = symbol('TMF')
edz_symbol = symbol('EDZ')

prices_qqq = data.history(qqq_symbol,'close', STD,'1d')
prices_tmf = data.history(tmf_symbol,'close', STD,'1d')
prices_edz = data.history(edz_symbol,'close', STD,'1d')

R_qqq = prices_qqq.pct_change()[-W:-1]
R_tmf = prices_tmf.pct_change()[-W:-1]
R_edz = prices_edz.pct_change()[-W:-1]

current_qqq = data.current(qqq_symbol, 'price')

max_qqq = data.history(qqq_symbol, 'price', MAXH, '1d').max()

raw_wt_qqq = 0.50*((max_qqq/current_qqq)**2)/(R_qqq.std()**2)
raw_wt_tmf = 0.20/(R_tmf.std()**2)
raw_wt_edz = 0.30/(R_edz.std()**2)

wt = abs(raw_wt_qqq) + abs(raw_wt_tmf) + abs(raw_wt_edz)
#print("raw vola %.5f, %.5f, %.5f"%(R_qqq.std()**2, R_tmf.std()**2, R_edz.std()**2))
#print("raw wt %.5f, %.5f, %.5f"%(raw_wt_qqq,raw_wt_tmf, raw_wt_edz))

wt_qqq = 1*raw_wt_qqq/wt
wt_tmf = 1*raw_wt_tmf/wt
wt_edz = 1*raw_wt_edz/wt

record(qqq_symbol= wt_qqq)
record(tmf_symbol= wt_tmf)
record(edz_symbol= wt_edz)

if wt_edz > 0.25:

wt = abs(wt_qqq) + abs(wt_tmf) + abs(wt_edz)
wt_qqq = 1*wt_qqq/wt
wt_tmf = 1*wt_tmf/wt
wt_edz = 1*wt_edz/wt

order_target_percent(qqq_symbol, wt_qqq*LEV)
order_target_percent(tmf_symbol, wt_tmf*LEV)
order_target_percent(edz_symbol, wt_edz*LEV)