This is my first day using Quantopian. I am following a simple tutorial from here:
https://pythonprogramming.net/python-programming-finance-back-testing/
The backtest is running extremely slow (at least a couple of hours). I think he using Quantopian 1. Will Quantopian 1 code work in Quantopian 2?
Here is the code. It's just a simple moving average crossover strategy. Why is my backtest taking an extremely long time? Maybe it's because I am using minute data, instead of daily data? Where can I change it to daily data? Thanks!
def initialize(context):
context.security = symbol('SPY')
def handle_data(context, data):
MA1 = data[context.security].mavg(50)
MA2 = data[context.security].mavg(200)
current_price = data[context.security].price
current_positions = context.portfolio.positions[symbol('SPY')].amount
cash = context.portfolio.cash
if (MA1 > MA2) and current_positions == 0:
number_of_shares = int(cash/current_price)
order(context.security, number_of_shares)
log.info("Buying shares")
elif (MA1 < MA2) and current_positions != 0:
order_target(context.security, 0)
log.info("Selling shares")
record(MA1 = MA1, MA2 = MA2, Price= current_price)