Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trying to find the highest, or max value within a window, getting an error

This is the first time I've really given python a shot.

If I replace

dist = max_data[(midline - hl2)]  

with
dist = max_data[context.stock] It compiles fine.

I don't fully understand what it needs from me, I guess you could say, any help (or explanations) would be appreciated!

Thank you

6 responses

Hello,

I've attached an example that may be helpful. It'll only run on minute data, but as-written, it'll just execute at 10:00 am. and skip all other minutes

I couldn't tell from your description and code what you are needing to compute, but hopefully you can tweak the attached code for your purposes.

Grant

Thanks so much for the reply/help here, the LR from scipy and numpy.amax seem to be behaving much more as expected than the built in ta. functions.

I still don't fully comprehend what

prices = history(15, '1d', 'price').ix[:-1] # 14-day trailing window, daily closing prices  

is doing. I looked at the documentation and even that is a little over my head. Can you (or someone) break this down for me a bit more?
My guess:
history( ) is is my window
15 is the length of my window going back
1d is this taking all of the minute data into account for each day and compiling it as a single OHLC daily bar?
price returns the last price of that bar?
.ix I'm not sure.
[:-1] returns the current day(bar)?

And by setting it up like this, it will naturally give the linregress, and amax (or whatever else calls upon it) a window of 15?

Oh, and by setting up the trading time, is that essentially telling it when to compile the minute data into daily data?
Example, if I wanted to compile 15 minute bars, could I use this method?

Hello Tony,

The history method is described on the help page: https://www.quantopian.com/help#ide-history. It returns a Python Pandas DataFrame. The .ix[:-1] just drops the last row, which corresponds to the data for the most recent minute of the current day. This way, you are dealing only with daily closing prices for 14 prior days.

Regarding the trading time, it just restricts algorithm execution. You can change it so that execution is more frequent, up to every minute.

You could sorta use the history method to compile your own 15-minute bars, but you might want to wait until the full history method is released that should provide a trailing window of minutely bar data. Why do you want 15-minute bars?

Grant

Thanks for another good reply.
I have no real reason for 15 minute bars currently, I am just trying to better understand how it all works. I'm more accustom to languages that are specifically built for stock analysis, and have a lot of built in features that make things like counting back bars, dealing with time frames, indicators etc. a lot more simple. So just really trying to figure it all out. I realize python is a lot more powerful than the others (using arrays and functions etc), so there's a tradeoff that's worth the exploration for me

Hey Tony,

The only frequency that the history() method currently supports is "1d," so you would need to write a few of your own functions to get minute-level bars (i.e. 15-minute bars). Quantopian tools are continuously being developed and improved, and a new version of the history() method should support minute-level analysis.

Ryan

Good to hear things are in development still, I'll be looking forward to some of the additions!