Suppose I have the prices of an action XXXX at the second for three years. I want to use the data to train my Deep Neural Network model for standard day trading purposes (i.e. High Frequency Trading). However, I have to label each second of the data file with "-1", "0", "1" for sale order, do nothing or a buy order. I don't want to label each row manually because it will take a year to do this task. How could I parse the data with python to label each row by "-1" if it is a good time to sell, "0" for doing nothing or "1" for a buy order? For a time X, we know precisely the past prices and the future prices, so it could be doable to label all of them I figure.

Be aware that for a standard trading, we have to take into account the transaction fees. In my case, I pay \$4.95 for a buy and \$4.95 for a sell. For instance, if I buy 100 shares at $1, then in order not to lose money, I must at least cover the loss related transaction costs. Hence, the selling price much be at least \$1 + (\$9.90/100) = \$1.099 ~ \$1.1

Another important aspect is that my market making strategy is order flow. So I don't want to trade on low price changes. In fact, I want the machine assists me to trade at the beginning. So I need the machine to trade as a trader normal would do on a normal day trading.

2018-04-02 17:59:33.643    0.8400
2018-04-02 18:08:58.808    0.8420
2018-04-02 18:09:50.003    0.8400
2018-04-02 18:09:50.003    0.8400
2018-04-02 18:12:27.183    0.8400
2018-04-02 18:16:04.064    0.8400
2018-04-02 18:25:07.933    0.8450
2018-04-02 18:25:41.331    0.8450
2018-04-02 18:26:54.375    0.8400
2018-04-02 18:26:54.376    0.8300
2018-04-02 18:37:39.056    0.8250
2018-04-02 18:38:23.336    0.8250
2018-04-02 18:38:23.339    0.8250
2018-04-02 18:51:15.689    0.8449
2018-04-02 19:04:41.140    0.8449
2018-04-02 19:17:38.169    0.8450
2018-04-02 19:26:59.634    0.8450
2018-04-02 19:27:47.407    0.8450
2018-04-02 19:37:19.775    0.8449
2018-04-02 19:37:29.165    0.8449
2018-04-02 19:41:05.906    0.8449
2018-04-02 19:54:18.236    0.8400
2018-04-02 19:54:20.944    0.8449
2018-04-02 19:54:20.946    0.8449
2018-04-02 19:56:32.848    0.8412
2018-04-02 19:56:32.851    0.8412
2018-04-02 19:57:04.354    0.8400
2018-04-02 19:57:04.355    0.8400
2018-04-02 19:58:02.221    0.8400
2018-04-02 19:59:31.622    0.8400


The mid-price at time $t$ is denoted by $$p_t = \frac{s_t^{a,1} + s_t^{b,1}}{2}.$$

This mid-price can evolve in minimum increments of half a tick but is almost always observed to move at increments of a tick over time intervals of a millisecond or less. In our feature set, each limit order book update is recorded as an observation. Each observation is labelled bases on whether the mid-price will increase, decrease or remain over a horizon $h$: $$Y_t = \Delta p^t_{t+h},$$ where $\Delta p^t_{t+h}$ is the forecast the discrete mid-price changes from time $t$ to $t+h$, given measurement of the predictors up to time $t$. The forecasting horizon $h$ can be chosen to represent a fixed number of events or can be a fixed time interval.

This definition is from A High Frequency Trade Execution Model for Supervised Learning (https://arxiv.org/pdf/1710.03870.pdf).


You haven't stated what the criteria are for assigning labels of -1, 0, or 1. Also, if you are trading on the second time scale, then the price change per bar will be quite low. If the price change is +0.01 for a bar, and the asset price is \$1 per share (\$100 per trade for 100 shares), then then your profit will be \$1 from that trade, which won't cover the \$4.95 commission. If you are trading 100 shares per second, where on Earth are you going to find a brokerage that will process your Sell trade alerts/signals for a given second and settle the trade in milliseconds, so that if the next bar (second) is a Buy, the proceeds will be available to make the purchase?

Overall, for very low price changes on short time scales (seconds, ticks) you have trade thousands of shares for each alert in order to be profitable. But trading so many shares on a short time scale can result in a lack of sufficient funds very quickly since sell and cover trades won't get filled as quickly as the unit of time scale you are on.

Next, if you are training a deep learning ANN with several hidden layers, which will require hundreds of iterations to determine whether to go long (Buy) or short for each second's bar, how are you going to be able to run your input through the ANNs architecture and trained connection weights to make the prediction before the next bar?

Overall, there are some trading issues which could be disastrous based on what you want to do, such that trade settlements will become clogged up and insufficient funds will occur for future trades (selling shares can take many seconds).

  • $\begingroup$ I don't want to trade at very low price changes. I would like to trade with the machine as a normal trader would. My market making strategy is order flow, littlefishfx.com/forex-education/…. How with python could I tell which price would be sell, buy or do nothing (1, -1, 0)? $\endgroup$ – Jeremie Apr 14 '18 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.