I would like to ask the following regarding the Limit Monthly Drawdown. First of all, when I backtest a strategy on a portfolio level using this position sizer (multiple securities in dataset or watchlist), does this apply to portfolio equity curve or to the individual instruments equity curve. Secondly, if I set a 1% threshhold for the drawdown should that mean that if I breach that on a particular day then all open positions are closed at that particular day (or the next) so as to prevent furhter losses (or gains) for the month? If not, then how easy would it be to implement this kind of modification. It would be also very helpful if possible to have that on a weekly and quarterly basis at the same time (or individually). Finally what is the proccess I should follow for modifying this position sizer on my own?
Size:
Color:
QUOTE:
First of all, when I backtest a strategy on a portfolio level using this position sizer (multiple securities in dataset or watchlist), does this apply to portfolio equity curve or to the individual instruments equity curve.
Applies to portfolio equity curve when backtesting on a portfolio level.
QUOTE:
Secondly, if I set a 1% threshhold for the drawdown should that mean that if I breach that on a particular day then all open positions are closed at that particular day (or the next) so as to prevent furhter losses (or gains) for the month?
Definitely not. PosSizers only can
size positions. (When monthly drawdown exceeds some value, "Limit Monthly Drawdown" rejects a trade by returning a zero size).
QUOTE:
If not, then how easy would it be to implement this kind of modification.
A modification can't be considered: by design, closing a position with a PosSizer isn't possible.
(As an unsupported, arcane workaround you could try this procedure to access the portfolio equity and then have the complete control over which trades to close:
Interacting Dynamically with Portfolio Level Equity)
QUOTE:
Finally what is the proccess I should follow for modifying this position sizer on my own?
You'll have to write one from scratch. The PosSizer library is closed code.
Size:
Color:
Eugene,
Thanks for your quick reply. I suppose that the arcane workaround can definitelly help me with what I am trying to achieve. Would you consider this solution (assuming that I will work under a fixed dollar position sizing scheme) reliable in WL 6.1. Do you consider an easier way of accessing portfolio equity curve in the upcoming WL version (any indication regarding the release date of WL 6.2?)?
Size:
Color:
The other possibility is to use SetShareSize in a script that processes DataSetSymbols and keep track of Portfolio Equity manually, bar by bar. One of these days I need to create an example of this.
Size:
Color:
Christos,
Excluding the Override/PosSizer options, it will even work in 6.2 (it does in a beta, probably this Summer if everything goes as planned) -- let alone 6.1.
Be prepeared for the following inherent problems: slowness on long data ranges, imprecision (discrepancy between the portfolio equity as reported by Wealth-Lab and its derivative DataSeries produced by the strategy) -- getting worse with Stop/Limit orders, and no Alerts.
Size:
Color:
Cone,
Posting an example like this could be extremely useful.
Eugene,
My only concern is imprecision... Can the discrepancy be big enough to significantly alter a systems risk return characeristics (relative to what it should be if there was no discrepancy) and if so in what kind of systems assuming that one uses only market orders?
Size:
Color:
Just try it in your environment and see if it suits or not.
Size:
Color:
Cone,
QUOTE:
The other possibility is to use SetShareSize in a script that processes DataSetSymbols and keep track of Portfolio Equity manually, bar by bar.
I am more inclined to use a solution like yours. I am trying to implement that in a strategy that takes multiple positions so I suppose that in order to calculate the equity curve bar by bar I should use three loops:
1. For Each Bar 2. For Each Symbol in DataSetSymbols 3. For Each Position of Symbol. and use the NetProfitAsOfBar
function in order to get the equity curve as I execute my strategy. Since I have used SetShareSize the daily (open) P/L for each bar would be the NetProfitAsOfBar for each day times the amount of shares set.
Do you agree with this kind of approach or you think I am missing something?
One way or another I am still looking forward to your example code! If and when you post that will that be done in this topic or should I search somewhere else?
Thanks,
Christos
Size:
Color:
See the RSI Rotation script for a basic structure - outer loop through Bars.Count and inner loop thru DataSetSymbols.
The coded solution is probably more complicated than I originally thought; you have to keep track of cash, open and closed equity, prioritize Positions and execute only the signals for which you have cash in the order of your priority. The way I'd attempt to do it is through a class object that performed all of these functions, but the devil is in the details as they say.
Size:
Color:
Cone,
I have made an attempt to do that but it seems to me that I certainly need some help in order to get to the desired result. Could you please provide some help with the example code you initially suggested? As you understand I am completely indifferent to the system that will be traded except from the fact that I would like the system to develop more than one simultaneous open positions on a single Symbol. The target is to create one dataseries for the cash, one for the open equity and one for the closed equity.
Size:
Color:
I don't have any example code, but I will work on getting this done in the next couple weeks. Like I said, to do it right, it's a much larger effort than I had originally thought.
Size:
Color:
Just finished (I think). Don't overlook the instructions. Try running the script "as is" by compiling and clicking on just 1 symbol in the Dow 30. The strategy is just a moving average crossover entry and a time-based exit.
Note! It's important that the Position Size Control's Starting Equity match the Starting Equity StrategyParameter value.
CODE:
Please log in to see this code.
Size:
Color:
Hi Cone,
Thanks for the code.
I have been checking this code which seems to be exactly what I was looking for. However I do have some questions:
1. If you run this code in different symbols within the same DataSet should't the results be exactly the same. correct?
2. I assume that "Slippage Settings" and "round lots" should be set to inactive in the preferences menu, correct?
3. The results in the chart tab regarding the equity curve and the cash curve should be exactly the same, correct?
4. Would it pose any additional difficulty to add code for ShortAtMarket , CoverAtMarket, BuyAtClose, SellAtClose, ShortAtClose, CoverAtClose?
Apologies for not posting earlier but was busy with other (boring) staff!
Many thanks again for your help
Size:
Color:
I think I have found a small mistake in line 170:
CODE:
Please log in to see this code.
Shouldn't this be
CODE:
Please log in to see this code.
...?
Size:
Color:
I'd have to say you're correct. Thanks. Here's an update for PortfolioTracker to handle short positions too.
CODE:
Please log in to see this code.
Size:
Color:
Thanks for the additional functionality regarding the Portfolio Tracker class.
I tried to replace the demo strategy with the one below but it doesn't seem to work as it should. The results are dependent on the symbol selected within the dataset when I attempt to run(which I suppose shouldn't be so). Can you help me with this one?
CODE:
Please log in to see this code.
Size:
Color:
Any backtest that you run by clicking on one symbol means that other symbols that are trade have to be synch'd to the clicked symbol for trading. If the series do not have the same dates/bars, then the results will depend on the clicked symbol. So the first thing to do is to check for missing bars - use the Bad History Data Check Rev. A (downloaded to the Utilities folder) and follow the instructions in the Summary.
Size:
Color:
I used the utility you mentioned by my data seemed to be fine - all of the bars had exactly the same gap of 2 days at the exact same bar. Therefore, I believe that I have made a code error somewhere in the symbol loop.
What I am trying to do is change the code of the below strategy (which I normally run on dataset of 10 stocks) to a "rotation style" strategy (applied just by selecting a single symbol) so as to correctly calculate the pt.Equity pt.Cash and pt.Drawdown.
I tried to do that by myself as it appears in my last post but not very successfully.
Could you possibly help me with that?
CODE:
Please log in to see this code.
Size:
Color:
Cone,
I am successfully running pt to get access to (I think) portfolio cash, but I am having trouble reconciling the pt outputs for _cashRemaining and openEquity with the Performance results. So I'm guessing I either don't have some settings correct or I am missing some fundamental understanding of the basics of what this is doing. To start with, I am assuming that _cashRemaining + openEquity = Ending Capital in the Performance tab, but that is not the case (Ending Capital is much higher than the sum of the two variables at final simulation bar). However, if I click on a single symbol to show the custom charting you created _cashRemaining + openEquity it is consistent with your custom chart (as I'm sure you already realize). So I'm trying to understand the disconnect and whether I have to change a setting to "sync" the two or I just don't understand what these variables represent. I have 10 positions and have set WL Override for sizer and adjusted slider starting capital to match Starting Capital in position sizer window. It appears to be buying the right number of shares and the open position value upon entry & exit appears generally consistent with the value of the transaction shown in the Trades tab. I just don't know where the profit has gone since it is not completely represented in the sum of _cashRemaining and openEquity, at least according to the Performance results. A few other questions:
1, When I click on a specific symbol I notice the cash / equity chart changes value. Why is that?
2. Are the equity and cash curves supposed to represent the entire portfolio or a single (selected) position?
3. Is it showing trading signals for just the selected symbol?
Size:
Color:
Cone,
I realized that I had "Apply interest rates..." box checked in Preferences and that was where the discrepancy was coming from. (I thought of this when I re-read your note about not calculating interest). I would appreciate if you could still answer my questions at the end of my previous reply:
QUOTE:
1, When I click on a specific symbol I notice the cash / equity chart changes value. Why is that?
2. Are the equity and cash curves supposed to represent the entire portfolio or a single (selected) position?
3. Is it showing trading signals for just the selected symbol?
Size:
Color:
I here answer my own questions:
QUOTE:
1, When I click on a specific symbol I notice the cash / equity chart changes value. Why is that?
Because not all the symbols in the data have the same amount of history. The max bars are determined by whichever symbol you click on. Reducing the back-test period so it is less than the bars in the symbol with the shortest history eliminates this effect.
QUOTE:
2. Are the equity and cash curves supposed to represent the entire portfolio or a single (selected) position?
Now that I made the change noted above, I can see that it does represent the entire portfolio.
QUOTE:
3. Is it showing trading signals for just the selected symbol?
Yes.
Cone - Thank you for the excellent and comprehensive example. I only require a piece of your creation (the cash accounting by bar) so I will attempt some surgery.
Size:
Color:
This simplified version takes the starting equity from the data panel so no need to set it in parameters or code. Instead of a percent equity it uses a parameter for maximum number of positions which is used internally to calculate shares. It is assumed the max number of positions is at 100% cash usage with no margin.
A control is available to use either total equity or cash remaining for position sizing.
You will notice that when hold time is extended to say 100 days the equity method may not be able to fill the last position due to insufficient capital so only 6 of 7 positions max may fill. This is expected. However unlike standard percent equity position sizing adding margin factor will not enable that last position. Switching to cash remaining mode will fill the max positions.
I've often used position rebalancing to manage outsized positions. Portfolio Tracker cash remaining method has some advantages.
Note that dividends are not included in Portfolio Tracker and if accrued are never reinvested.
CODE:
Please log in to see this code.
Size:
Color:
Excellent. This looks great !!!. Many Thanks for sharing, KGo.
Size:
Color:
You're welcome. Hope it helps.
Size:
Color: