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.

Clone Algorithm
14
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58ac8bcea218bc5e01e1beb4
There was a runtime error.
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?

Clone Algorithm
14
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58accccc8fd4915e407ffa0d
There was a runtime error.