Back to Community
code for getting minute data into before_trading_start

Here's code for getting a trailing window of minute data into before_trading_start, including the closing prices from the prior day. Seems sorta circuitous, but this is the only way I could code it. Maybe pipeline could be used to pull in the closing price from the prior day, in a more elegant fashion (e.g. a numpy vector)?

Clone Algorithm
27
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: 56df688d136b720fcdf28aaa
There was a runtime error.
4 responses

Here's an incremental improvement. Arrays are pre-allocated, and by inspection of the output, one can confirm that it is working.

Clone Algorithm
27
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: 56dff88f014acf0f3ff2757e
There was a runtime error.

Here's another incremental improvement (thanks to Alan Coppola on https://www.quantopian.com/posts/get-data-as-vector-instead-of-scalar).

Clone Algorithm
27
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: 56e3461a0351c70e03e065cb
There was a runtime error.

Wow, that is clean code. Thank you for sharing Grant. Following and testing (found from your post here: https://www.quantopian.com/posts/pipeline-classifiers-are-here#5704dbaaf3b71d2097000158).

Thanks Marc,

There is a more general case with a dynamic universe. I haven't sorted that one out yet. The fundamental problem, I think, is that the analyses would be done in before_trading_start on the prior day's universe, then the universe would be updated, doing an add/drop for the current day. But the analyses would have been done on the prior universe, so orders opening new positions for stocks no longer in data would fail. But maybe I haven't thought everything through carefully enough...

Grant