Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Get the past price??

Hi,

I just learned how to use initialize and handle_data function. The handle_data function can only extract the specific trading event, yet what I need is past prices. I am going to run my strategy by comparing past 3 prices, so how can I do so by using handle_data? Or I have to use other functions?

Thanks

3 responses

I think you have two choices to achieve what you are asking.

1) use a Batch Transform

2) store the current price in a variable and refer to it again a day later

I tried the batch transform, like this

@batch_transform(window_length=10)
def get_averages(datapanel):
prices = datapanel['price']
# to get the lastest price
return prices[-1]

HOWEVER, it didn't work....

Hello Chiu-Hao,

I prefer to return the data from the batch transform as a numpy ndarray, for subsequent analysis. Have a look at the attached code and its log output (you'll need to run it again). It returns a trailing window of 390 minute bars, updated every minute. You can play around with the various settings, look at the log output, and get a feel for what's going on. The code will also execute with daily data.

Once you get your code working, feel free to post it here (you can just cut out any proprietary parts that you don't want to share).

Grant