@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.
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.
Rename
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.
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.
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.
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)
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)
Your Response
Post
Edit Post
Login is required