Hi everyone.
I've been interested in using evolving algos in trading for a while and created a simple one just so I can have a place t start. However, when I run it, I get a Build Error - Line 29, but no details on the error. I look at Line 29, and there is no error. Any input?
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
sells = [-1, -2, -3]
buys = [1, 2, 3]
buyPoints = [5, 15, 25]
sellPoints = [10, 20, 30]
positions = [0, 0, 0]
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 > sellPoints[i]:
order(context.amat, sells[i])
positions[i]-=((price)*(sells[i])
if price < buyPoints[i]:
#Line above in Line 29, the one with the error
order(context.amat, buys[i])
positions[i]-=((price)*(buys[i])
count++
if count == 7:
temp = 0
best = null
for i in range(0,3):
if positions[i] >= temp:
temp = positions[i]
best = i
bestSell = sells[best]
bestBuy = buys[best]
bestSellPoint = sellPoints[best]
bestBuyPoint = buyPoints[best]
for i in range(0,3):
sells[i] = bestSellPoint*random.randrange(-2,2,.01)
buys[i] = bestBuyPoint*random.randrange(-2,2,.01)
sellPoints[i] = bestSellPoint*random.randrange(-2,2,.01)
buyPoints[i] = bestBuyPoint*random.randrange(-2,2,.01)
count = 0