Despite reading the documentation and watching the associated YouTube video, I'm still having some issues fully grasping the cause and effect of NSF Positions. If anyone could answer a few general questions, I would appreciate it:
1) Can "legitimate" and effective strategies still result in NSF Positions in backtests? Or does it generally indicate a problem in the strategy's logic/construction?
2) If a strategy produces NSF Positions in backtests, is it still fine to run that strategy in a live trading situation, or is it inadvisable to do so?
3) If I only intend to run strategies in situations where I have no open positions beforehand, can I safely uncheck the "Retain NSF Position" without any downside?
I guess my main concern here is that I don't want my strategy execution or backtests to be non-deterministic. I've tried resolving this with the recommended solutions (position size, fixed equity, market on open, transaction weight) but still have NSF positions in backtests.
1) Can "legitimate" and effective strategies still result in NSF Positions in backtests? Or does it generally indicate a problem in the strategy's logic/construction?
2) If a strategy produces NSF Positions in backtests, is it still fine to run that strategy in a live trading situation, or is it inadvisable to do so?
3) If I only intend to run strategies in situations where I have no open positions beforehand, can I safely uncheck the "Retain NSF Position" without any downside?
I guess my main concern here is that I don't want my strategy execution or backtests to be non-deterministic. I've tried resolving this with the recommended solutions (position size, fixed equity, market on open, transaction weight) but still have NSF positions in backtests.
Rename
I've just discovered that even with "Retain NSF" unchecked, it will still cause the backtest results to change each time the backtest is run. So I would say the answer to my question #3 is "no".
That option cannot eliminate NSF positions, it just causes them to not be retained.
Look at it this way, say you have $1000 and your Strategy is running on two stocks, ABC and DEF. It signals to buy both of them at the same bar at market open.
Your position size is set to $800.
What's going to happen? Only one of the two orders will get filled, the other one will be NSF.
The only way to eliminate this is to reduce the position size to $500.
Now, the reason we retain these NSF positions? It's to preserve the internal integrity of the Strategy. If your Strategy goes long when some technical conditions are met, then by retaining the NSF position, WL7 can know that your Strategy is still in a "long" state, and enter your block of code that is looking to sell.
If you don't preserve the NSF positions, then you might wind up getting another buy signal at some point when the internal state of your Strategy really should be "long".
Make sense?
Look at it this way, say you have $1000 and your Strategy is running on two stocks, ABC and DEF. It signals to buy both of them at the same bar at market open.
Your position size is set to $800.
What's going to happen? Only one of the two orders will get filled, the other one will be NSF.
The only way to eliminate this is to reduce the position size to $500.
Now, the reason we retain these NSF positions? It's to preserve the internal integrity of the Strategy. If your Strategy goes long when some technical conditions are met, then by retaining the NSF position, WL7 can know that your Strategy is still in a "long" state, and enter your block of code that is looking to sell.
If you don't preserve the NSF positions, then you might wind up getting another buy signal at some point when the internal state of your Strategy really should be "long".
Make sense?
QUOTE:
I've just discovered that even with "Retain NSF" unchecked, it will still cause the backtest results to change each time the backtest is run.
You have to assign a Weight to each Transaction and reduce the size as the FAQ says (and as Dion has just suggested).
Hi All,
After reading the FAQ (https://www.wealth-lab.com/Support/Faq) and the various posts on NSF, I have the following questions based on the following scenario which I hope someone can enlighten me on.
Scenario
If i have a Simple Moving Average cross-over strategy on stocks in S&P 500, each position is sized based on 10% of Equity and each transaction is weighted for prioritization, I find that re-running the same strategy over the same period multiple times will yield the same results if I check the option, "Retain NSF Positions".
If I uncheck the option, "Retain NSF Positions", the generated historical result will differ from the one mentioned earlier but it will be the same as the ones generated from multiple re-runs of the same strategy, albeit with the option, "Retain NSF Positions", still unchecked.
Question 1
The reason for the same historical result across multiple re-runs of the same strategy based on the same "Retain NSF Positions" is due to the inclusion of transaction weight for trade prioritziation, right?
Question 2
In this scenario, shouldn't the user uncheck the option "Retain NSF Position" for backtesting since processing time will be shorter and the user would not have traded the historical NSF positions in the first place since they will be deprioritized based on transaction weight?
Hopefully my questions are clear. If anyone needs me to attach a simple code to provide a clearer picture, feel free to let me know.
Thank you,
pmbf
After reading the FAQ (https://www.wealth-lab.com/Support/Faq) and the various posts on NSF, I have the following questions based on the following scenario which I hope someone can enlighten me on.
Scenario
If i have a Simple Moving Average cross-over strategy on stocks in S&P 500, each position is sized based on 10% of Equity and each transaction is weighted for prioritization, I find that re-running the same strategy over the same period multiple times will yield the same results if I check the option, "Retain NSF Positions".
If I uncheck the option, "Retain NSF Positions", the generated historical result will differ from the one mentioned earlier but it will be the same as the ones generated from multiple re-runs of the same strategy, albeit with the option, "Retain NSF Positions", still unchecked.
Question 1
The reason for the same historical result across multiple re-runs of the same strategy based on the same "Retain NSF Positions" is due to the inclusion of transaction weight for trade prioritziation, right?
Question 2
In this scenario, shouldn't the user uncheck the option "Retain NSF Position" for backtesting since processing time will be shorter and the user would not have traded the historical NSF positions in the first place since they will be deprioritized based on transaction weight?
Hopefully my questions are clear. If anyone needs me to attach a simple code to provide a clearer picture, feel free to let me know.
Thank you,
pmbf
Hi,
Can you share the strategy in its entirety? With the strategy you described, entry and exit at market with a condition of moving average crossover ONLY and a transaction weight on entry, I am getting exactly the same results whether Retain NSF is checked or unchecked.
Can you share the strategy in its entirety? With the strategy you described, entry and exit at market with a condition of moving average crossover ONLY and a transaction weight on entry, I am getting exactly the same results whether Retain NSF is checked or unchecked.
Hi Glitch,
Please refer to the sample code and strategy settings shown below.
Screenshot Showing the Strategy Settings for Sample Code
Thank you,
pmbf
Please refer to the sample code and strategy settings shown below.
Screenshot Showing the Strategy Settings for Sample Code
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript1 { //---Strategy Settings--- //Portfolio Backtest: S&P 500 (Wealth Data) //Date Range: 7/13/2013 to 7/13/2023 //Sizing: 100% of Equity, //Starting Capital: 1000000 //Margin Factor: 1.0 public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { //--- Indicators --- sma20 = new SMA(bars.Close, 20); sma40 = new SMA(bars.Close, 40); roc100 = new ROC(bars.Close, 100); StartIndex = 200; } public override void Execute(BarHistory bars, int idx) { //=== Exit === Position p = LastOpenPosition; if(p != null) { CloseAtTrailingStop(p, TrailingStopType.PercentC, 25, "Trailing Stop"); ClosePosition(p, OrderType.Stop, 0.95*p.EntryPrice, "Stop Loss"); } //=== Entry === // Prevents Overlapping Position if (HasOpenPosition(bars, PositionType.Long)) return; // Signal if(!sma20.CrossesOver(sma40, idx)) return; Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0.0, 1, "Long Entry"); //--- Ranking --- t.Weight = roc100[idx]; } // private variables IndicatorBase sma20, sma40, roc100; } }
Thank you,
pmbf
Your strategy is using some stop exits, not the moving average crossover.
So, it's possible that a moving average crossover ENTRY signal could occur multiple times for a symbol before the exit is achieved.
With Retain NSF Positions turned on, such a secondary entry would not be acted upon because the Strategy still is tracking the original theoretical (NSF) position.
With Retain NSF Positions turned off, the secondary entry is allowed so the results do not match.
So, it's possible that a moving average crossover ENTRY signal could occur multiple times for a symbol before the exit is achieved.
With Retain NSF Positions turned on, such a secondary entry would not be acted upon because the Strategy still is tracking the original theoretical (NSF) position.
With Retain NSF Positions turned off, the secondary entry is allowed so the results do not match.
Hi Glitch,
Thanks for responding to my post.
I do understand the rationale for the difference in performances between the same strategy with and without "Retain NSF Positions".
Can I ask for your thoughts to the two questions shown below?
Question 1
The reason for the same historical result across multiple re-runs of the same strategy (with "Retain NSF Positions" check-box checked) is due to the inclusion of transaction weight for trade prioritziation, right?
Question 2
If multiple re-runs of the same strategy (with "Retain NSF Positions" check-box checked)will generate the same historical result, shouldn't the user uncheck the option "Retain NSF Position" for backtesting since processing time will be shorter and the user would not have traded the historical NSF positions in the first place since they will be deprioritized based on transaction weight?
Thank you,
pmbf
Thanks for responding to my post.
I do understand the rationale for the difference in performances between the same strategy with and without "Retain NSF Positions".
Can I ask for your thoughts to the two questions shown below?
Question 1
The reason for the same historical result across multiple re-runs of the same strategy (with "Retain NSF Positions" check-box checked) is due to the inclusion of transaction weight for trade prioritziation, right?
Question 2
If multiple re-runs of the same strategy (with "Retain NSF Positions" check-box checked)will generate the same historical result, shouldn't the user uncheck the option "Retain NSF Position" for backtesting since processing time will be shorter and the user would not have traded the historical NSF positions in the first place since they will be deprioritized based on transaction weight?
Thank you,
pmbf
1. Yes.
2. it depends on if you care about maintaining the internal consistency. I don’t think either way is right or wrong, but they do produce different results. Unchecking it will indeed speed up processing.
2. it depends on if you care about maintaining the internal consistency. I don’t think either way is right or wrong, but they do produce different results. Unchecking it will indeed speed up processing.
The question to answer is, "do you want to give the strategy every opportunity to enter a new position?"
If the answer is yes => Do not Retain
otherwise => Retain
A simple example to understand the concept, imagine a strategy that buys ANYTIME the Close "IS ABOVE" the moving average and sells when the Close "CROSSES BELOW" the MA. When the Close first crosses over the MA, assume the position is rejected for NSF.
Option 1 - DO NOT Retain NSF Positions
The strategy discards the NSF Position and will continue to signal and try to buy ANY bar on which the Close is still above the MA.
Option 2 - Retain NSF Positons
The strategy has hypothetically entered an NSF position and will only signal to sell it when Close crosses below the MA. There will be no new signal to enter a position while the Close "IS ABOVE" the MA - because the strategy is holding that position as an NSF Position.
If the answer is yes => Do not Retain
otherwise => Retain
A simple example to understand the concept, imagine a strategy that buys ANYTIME the Close "IS ABOVE" the moving average and sells when the Close "CROSSES BELOW" the MA. When the Close first crosses over the MA, assume the position is rejected for NSF.
Option 1 - DO NOT Retain NSF Positions
The strategy discards the NSF Position and will continue to signal and try to buy ANY bar on which the Close is still above the MA.
Option 2 - Retain NSF Positons
The strategy has hypothetically entered an NSF position and will only signal to sell it when Close crosses below the MA. There will be no new signal to enter a position while the Close "IS ABOVE" the MA - because the strategy is holding that position as an NSF Position.
Hi Cone and Glitch,
Thanks for providing clear answers. Assuming transaction weights have been assigned for all the trades, here are my follow up questions:
Option 1
If the Starting Capital and Position Sizing specified for the backtesting are close proxies to what would be used for live trading, then wouldn't the historical performance of Option 1 be more relevant for the user who wishes to eventually take the backtested strategy live?
Option 2
As for Option 2, I'm not sure how retain NSF positions would be relevant for the backtester who eventually wishes to take the strategy live since the NSF position does interfere with the buy signal though it is only a hypothetical position?
Thank you,
pmbf
Thanks for providing clear answers. Assuming transaction weights have been assigned for all the trades, here are my follow up questions:
Option 1
If the Starting Capital and Position Sizing specified for the backtesting are close proxies to what would be used for live trading, then wouldn't the historical performance of Option 1 be more relevant for the user who wishes to eventually take the backtested strategy live?
Option 2
As for Option 2, I'm not sure how retain NSF positions would be relevant for the backtester who eventually wishes to take the strategy live since the NSF position does interfere with the buy signal though it is only a hypothetical position?
Thank you,
pmbf
Both are relevant. It's a preference. That's it.
Your Response
Post
Edit Post
Login is required