catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Issues with simulated trades in back testing

Open STOpandthink opened this issue 7 years ago • 8 comments

Forked from this conversation.

I'm running a daily algorithm: [2018-04-01] It orders 0.6 BTC at limit price of $6953. I expect that this order will be filled ASAP on 2018-04-02. Which is most likely right at the beginning of that day. [2018-04-02] Bitcoin goes from $6817 to $7053. My order is not filled! And if I remove the limit, the order is filled at $7068. (Why so high???)

STOpandthink avatar May 30 '18 01:05 STOpandthink

I am experiencing the same issue as well. The "limit_price" option does not appear to be working as expected when simulating an order.

quanatee avatar May 30 '18 08:05 quanatee

Thanks @STOpandthink for opening a new ticket for this and @rymdluo for reporting. We are investigating this.

lenak25 avatar Jun 03 '18 08:06 lenak25

Having same issue -- all my orders execute 24h late.

amitvpatel06 avatar Jun 08 '18 02:06 amitvpatel06

Can you confirm that that price is actually available during the time you are putting down the order? The close price might not be available again at the moment you are trying to trade. For example: Yesterdays close might be different from today's open and your data is comprised of trade data not orderbook data if I remember correctly. This means the price of an asset has to achieve the same price of the last close again on the new day to be filled.

untitled

salihkilic avatar Jun 12 '18 14:06 salihkilic

It seems to me that this is not a bug, but a feature. It is not realistic to expect that you can observe a price, place an order and fill it in the same bar. Catalyst correctly allows you to observe the price in some bar, and tries to fill the orders placed in the next bar. Of course, this introduces a large delay at daily frequency. If this is a problem, use minute frequency. IMHO, the daily frequency doesn't really make much sense except for strategies trading very infrequently (like rebalancing every month or so).

sam31415 avatar Jun 20 '18 12:06 sam31415

Well, when I put in an order when context.current_day is January 1st, 2018, it gets executed not at the OPEN price of January 2nd 2018, but at the closing price. It also seems that the data.current results do not match with the data.history results?
screen shot 2018-06-23 at 1 46 53 pm

amitvpatel06 avatar Jun 23 '18 20:06 amitvpatel06

Hi @amitvpatel06 ,

Regarding your first comment: yes, indeed the order get executed with the closing price. We are aware of this behavior (which was inherited from zipline) and after receiving several feedbacks and inquiries from users on this matter (like the current thread) we are currently considering approaches to handle this. Regarding your second observation about data.current and data.history, I think that the origin of the confusion is in looking at the context.current_day instead of data.current_dt.

lenak25 avatar Jun 24 '18 09:06 lenak25

this sounds like a crucial issue for any backtest/paper trading, will running it on minute interval, but using daily data for buy/sell signal calculation help?

gideon-teo avatar Aug 27 '18 09:08 gideon-teo