- ago
@Cone
In example 6 at https://www.wealth-lab.com/blog/backtest-auto-trade-options if there is an open position held overnight and WL restarts, are the _hash1 and _hash2 values lost? In that case, when the strategy starts up for the next day, _hash1 and _hash would = -1 and the open positions will not be found. I don't see an exit positions at end of day.

My question is specific to the use of hash for finding open positions (when using external symbols / pairs trading) vs. another method of detection when positions can be held overnight, and WL is restarted daily.
0
383
3 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.92% )
- ago
#1
The _hashes are just numerical representations of [option] symbols to use as the Position.Tags. It's [almost guaranteed to be] a 1:1 unique reference.
The _hash will only be -1 because it hasn't been assigned, i.e., no trades. You have to make sure to load sufficient history to create the hypothetical trades for the previous day.
0
- ago
#2
QUOTE:
You have to make sure to load sufficient history to create the hypothetical trades for the previous day.

I hadn't thought about that. Then the hash values will be recreated, assuming no variables have been changed that would result a different derivative position. E.g., if I change the expiration days variable for options before the next day run, it could choose a different option and generate a different hash than the one that matches the symbol that is live at the broker. While it would report there is an open position based on backtest data, the symbol would not be usable to close the position at the broker.

Maybe it's safer to actually query the broker positions on the last bar to see what's open. I only have one open position at a time for a given underlying so I can test for underlying associated with it using the option helper features.
0
Cone8
 ( 4.92% )
- ago
#3
Correct. And even more subtly, the valid strikes can change from day-to-day which could create different backtest positions even if you didn't change a parameter. Procedure:

1. Detect the Positions in the broker account.
2. Use that as [another] condition to enter the exit logic
3. Use PlaceTrade() instead of ClosePosition() so that:
a) you can assign the Transaction.Quantity to the exit signal, and,
b) it won't be required for the backtest to have created a trade (no history required)
0

Reply

Bookmark

Sort