QuantRocket

Prices_to_signals -- Intraday Trading


#1

Hi there!

I read the documentation on intraday trading, but I’m still a little unclear on how frequently prices_to_signals gets invoked (in general, but particularly when using a 1 minute bar intraday strategy).

Assuming I want to use 1 minute bars, would that mean prices_to_signals will be called every 1 minute with the new bar’s data? Put another way, what determines the frequency for which prices_to_signals is called?

I’d love to see an example of a basic intraday strategy that acts on the current bar’s OHLC, in relation to the preceding 1 minute bars’ data of that same day… (an intraday strategy that trades throughout the day).

Thanks!


#2

Regardless of bar size, prices_to_signals is called once per backtest. It produces a DataFrame of signals, where each row of the DataFrame is the signal for that day or minute (in your case minute). I recommend loading a DataFrame of minute prices into a notebook and producing a DataFrame of minute signals, as this is all that prices_to_signals does. (See docs on interactive development.)

For live trading, you would schedule Moonshot to run every minute. Each time it runs prices_to_signals is called once, produces a DataFrame of signals, and the last row is used to generate orders. An example of scheduling an intraday strategy can be seen in the docs.

If you’re confused by intraday start with daily. Intraday works exactly the same way, the only difference is the timestamps of your bars and how frequently you would schedule it to run for live trading.


#3

Thanks @brian, that is a lot more clear now. Just one follow-up question. Since prices_to_signals is called only once per backtest, it seems there will be a substantial difference between the backtest code and the live trading code. For example, in live trading, we’d act only on the last row of data, as you mentioned. But for a good backtest, we’d want to simulate intraday trading over all the days in the backtest.

Does Moonshot have an elegant way to handle that, or do I need to manage two sets of logic? i.e. (a) backtest code that iterates over the DataFrame, and (b) live trading code that acts only on the last row.

Hope my question makes sense to you.

Thanks,
Ernie


#4

No split logic, just make a DataFrame and Moonshot will use it differently for backtesting vs live trading. I suggest working through this intraday tutorial which includes live trading: https://www.quantrocket.com/code/?repo=fx-bizday


#5

Cool will do. Thanks Brian!