Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Interpreter only recognizes three functions

What am I doing wrong? The IDE is only recognizing two of the three functions. I have initialize(), handle_data(), and my_transform(). If I put my_transform() last, it won't recognize the call to it in the handle_data() method. If I put handle_data() last, the error says I need to implement a handle_data method.

Has anyone experienced this before? It might be a problem due to my inexperience with Python.

6 responses

You should probably organize your layout w/ something along these lines:

def initialize(context):
# choose the top two percentile of DollarValue rankings
set_universe(DollarValueUniverse(98.0, 99.0))
# construct a new batch transform, tuck it into the context
# call the function my_transform every two days, keeping 7 days of history in the data panel
context.a_batch_transform = BatchTransform(func=my_transform, refresh_period=2, delta=timedelta(days=7))

def handle_data(data, context):
# update the transform with the current data events
transform_results = context.a_batch_transform.handle_data(data)
# place orders, rebalance portfolio, etc.
order(transform_results.buys[0], 10)

def my_transform(data_panel):
prices_dataframe = data_panel['price']
# do work on prices...
# return the data your algorithm will need to make buy/sell choices
return transform_results

Obviously this won't run any result, but I hope it generalizes some "flow of concept" :P

Taylor B,
Sounds like you have an indentation bug. If you post the source code I can help you find the issue.
thanks,
fawce

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.

that's what I figured, but I'd rather not post the code.

Google's telling me to change tabs to four spaces, get rid of extra space at the ends of lines, and end the last line with a newline. I don't get that last bit of advice.

The easiest way to make sure you have a newline at the end of the last line of code is to put a blank line at the end of your script.

Hello Taylor B.,

You could try one of the IDEs like IDLE than have an "un-tabbify" option. This can help.

Regards,

Peter

the problem: I wrote @batch_transform instead of @batch_transform(stuff = 1, stuff2 = 2). Weird. When I was using zipline without quantopian this wasn't a problem.

Not it starts running but I get this: TimeoutException: Too much time spent in handle_data call

edit: seems fine now