I posted this before and thought I had it resolved, but it still doesn't work. The code below keeps giving me a runtime error on line 47 but doesn't tell me what the error is and it doesn't seem as if there is any error.
CODE:
import random
def initialize(context):
context.base_order = 100
context.sec_id = 24
context.amat = sid(24)
context.max_notional = 1000000.1
context.min_notional = -1000000.0
context.sells = [-1, -2, -3]
context.buys = [1, 2, 3]
context.buyPoints = [5, 15, 25]
context.sellPoints = [10, 20, 30]
context.pos = [0, 0, 0]
context.count = 0
def handle_data(context, data):
mavg = data[context.amat].mavg(20)
price = data[context.amat].price
notional = context.portfolio.positions[context.amat].amount * price
# if price > mavg:
# order(context.amat, -25)
# if price < 450:
# order(context.amat, +20)
for i in range(0, 3):
if price > context.sellPoints[i]:
order(context.amat, context.sells[i])
context.pos[i] -= (price * context.sells[i])
if price < context.buyPoints[i]:
#Line above in Line 29, the one with the error
order(context.amat, context.buys[i])
context.pos[i] -= (price * context.buys[i])
context.count += 1
if context.count == 7:
temp = 0
best = 0
for i in range(0,3):
if context.pos[i] >= temp:
temp = context.pos[i]
best = i
bestSell = context.sells[best]
bestBuy = context.buys[best]
bestSellPoint = context.sellPoints[best]
bestBuyPoint = context.buyPoints[best]
for i in range(0,3):
context.sells[i] = bestSellPoint*random.randrange(-2,2,1)
context.buys[i] = bestBuyPoint*random.randrange(-2,2,1
context.sellPoints[i] = bestSellPoint*random.randrange(-2,2,1) <-----This is the line with the error
context.buyPoints[i] = bestBuyPoint*random.randrange(-2,2,1)
context.count = 0
Thank you so much ahead of time!