Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Getting Value from Trailing Window

Hello everyone,
I have been having trouble getting just the twelve minute price from a trailing window of data. I didn't start having trouble getting the value from the trailing window until I implemented pipeline. Now every time I try to get the [0] value I get a key error. I want to get the twelve minute price to perform a calculation please help.

2 responses

I believe your problem is with this statement

    context.assets = context.output.index

Change it to

    context.assets = context.output.index.tolist()

By just using the index, 'context.assets' becomes a Pandas index object. The 'current' and 'history' methods really expect a list. Turning 'context.assets' into a list with the 'tolist()' method ensures those methods work the same when using either pipeline results or a static list of securities.

That worked for retrieving the value, but now I am having issues using the value in a calculation. I am trying to subtract the current price from the price twelve minutes ago in order to produce a momentum value. Any thoughts?