-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delayed order #149
Comments
Thanks @mike-mik for posting here. I have taken a quick look and debugged this strategy through the various stages of the quantstrat strategy execution path. Im not sure, but i suspect delay is not meant to be used as you have used it here. Using a market order will look to execute at the next observation. Perhaps |
Without any additions to the order that's true. But my original problem is: How do you tell quantstrat to close a position at the end of the day when you test on intra-day data? This order can be either a market-on-close (MOC) or a good-after-time (GAT). Since I think quantstrat doesn't support MOC I tried to simulate it with GAT using MOC would be far more elegant here. Does quantstrat support MOC? |
No, I don't believe there is a MOC ordertype. You could request that as a feature. Would be interested to hear feedback on the idea. Thoughts on a MOC ordertype @braverock? |
No, there is no MOC ordertype, since very few investors actually have access to the closing auction or the equivalent TAS for derivatives. Broker MOC order types are typically "we'll fill you at whatever price we can get away with". Those investors who do have access to the closing auction would likely test with tick data anyway, which follows a completely different code path. Now, onto the issue at hand here. I see two potential problems in the code, but need to dig a bit deeper. The price for a
I'm not sure I'm also not sure why this order is in the
Right now I'm guessing that the most likely root cause is that |
Is the closing auction the reason for the EOD close often differing from the intra-day close? Because EOD close does contain the closing auction and the intra-day close does not? So if my strategy uses the previous day's close as a trigger for today's trade and today's close for executing this trade/calculating the P/L, do you think I should use EOD close as the trigger and intra-day close for the P/L? |
What do you mean by intra-day close...the last price printed before the start of the closing auction? P&L should be marked to the actual closing price (ignoring nuances related to after-hours trading).
Your portfolio value will be marked to the close price. How you execute your strategy is up to you. If you would like to trade at the close, then it appears you will need to use daily bar data for your signal, as there is no MOC ordertype and using a delay seems to not work as expected right now. There could be 2 pieces of work out of this:
Not sure when we get to 1 and/or 2. If the impact is big enough the effort will be more worth while. |
I tested two providers of intra-day data:
So I mean the close of the 1min bar starting at 15:59 (or 12:59 for shortened sessions). This is the first time I deal with intra-day data and I was surprised about the differences in close prices. So my question is: Are Firstrate's and Polygon's intra-day data of mediocre quality or are these differences in close prices quite normal, e.g. because the closing auction's results are calculated shortly after 16:00 and therefore can hardly be included in the 15:59 bar?
If
this should be used for the P&L. I'm only interested in testing the main session.
I wrote my strategy after Brian had suggested to test it with intra-day data instead of daily data. This is the strategy (with 30min bars):
The minimal reproducible example of the strategy is available here.
Would 2. be a special case of 1. (with fixed time)? |
I would query any perceived discrepancies with the vendor. It would appear that in the Line 533 in f9e4ea1
delay is meant to work with market orders. However, when testing ordertype=stoplimit we still get a transaction at the next bar (10am) instead of at the end of the day (15:30) which makes me think we may need to update the dindexOrderProc() function in applyRules() , specifically Line 461 in f9e4ea1
|
If i add 2 instead of 1 to the curIndex in > out<-try(applyStrategy(strategy='str1' , portfolios='str1'))
[1] "2021-01-26 09:30:00 SYM 100 @ 61.2"
[1] "2021-01-26 10:30:00 SYM -100 @ 60.445"
>
> print(getOrderBook('str1'))
$str1
$str1$SYM
Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Prefer Order.Set Txn.Fees Rule
2021-01-25 15:30:00.0000 "100" "60.58" "stoplimit" "long" NA "closed" "2021-01-26 09:30:00" "High" NA "0" "EnterLONG"
2021-01-26 15:30:00.0000 "all" "61.2" "market" "long" NA "closed" "2021-01-26 10:30:00" "Close" "ocolong" "0" "CloseLONG"
Time.In.Force
2021-01-25 15:30:00.0000 "2021-01-26 15:29:00.000000"
2021-01-26 15:30:00.0000 "" |
Description
The
delay
parameter inruleSignal
seems to have no effect on execution time.Expected behavior
The sample data contains a long signal at 2021-01-25 15:30:00.
The following strategy I would expect to issue an order at the next bar (2021-01-26 09:30:00) but to delay execution by one day.
Although the order is being delayed in the order book index the trade is still executed at time of order issue (2021-01-26 09:30:00) without any delay.
Output of example code (one day delay):
Minimal, reproducible example
My sample data SYM.csv:
Session Info
The text was updated successfully, but these errors were encountered: