Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Unknown Issue With Algo

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!

4 responses

You need a close parens at the end of line 46 (the line above the one giving you the error).

Sorry about the misleading line number - that's something we'll have to investigate in our code validation system.

thanks,
Jean

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks so much!!

Actually, one more quick question.

In the following line:

 returns = context.portfolio.returns()  

I get an error: "Runtime exception: TypeError: 'float' object is not callable"

No parens on that one

 returns = context.portfolio.returns  

more info: portfolio object

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.