I'm trying out the Quantopian backtester with illiquid/thinly traded securities and running into problems. I can build the algorithm but the Full Backtest generates "There was a runtime error" with no additional details. All of the securities in the list appear to be active over the period of the backtest, based on Google finance.
Seems to be some trickiness to running Quantopian on securities that don't trade every minute/day...
Algorithm runs with
context.stocks = [sid(8554),sid(19920),sid(22739)]
but not with
context.stocks = [sid(41290),sid(41425),sid(39479),sid(33972),sid(41159)]
Here's the algorithm, in case it doesn't get posted:
import datetime
import pytz
def initialize(context):
#Full Backtest outputs "There was a runtime error"
context.stocks = [sid(41290),sid(41425),sid(39479),sid(33972),sid(41159)]
#Full Backtest completes without errors
#context.stocks = [sid(8554),sid(19920),sid(22739)]
context.price = {}
context.volume = {}
context.max_notional = 1000000.1
context.min_notional = -1000000.0
utc = pytz.timezone('UTC')
context.d=datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=utc)
def handle_data(data, context):
notional = 0.0
for stock in context.stocks:
price = data[stock].price
volume = data[stock].volume
notional = notional + data.portfolio.positions[stock].amount * price
tradeday = data[stock].datetime
log.debug(stock)
log.debug(tradeday)
log.debug(volume)
if (context.d + datetime.timedelta(days=1)) < tradeday:
log.debug(str(notional) + ' - notional start ' + tradeday.strftime('%m/%d/%y'))
context.d = tradeday