- ago
Bug #1: Doesn't save your setting
Take any strategy... use Max Risk Percent Pos Sizer... set Max Risk % value to anything other than default... run & save your strategy... close and reopen... it opens with the default value, not the one you set & saved.

Bug #2: Doesn't respect Margin setting
The best way to expose this is to use a strategy that generates a lot of signals and run it on a large dataset. I used the Seventeen Liner and ran it on S&P 500 (WealthData) with these settings:


After running the backtest open the Equity Curve tab. As long as the Equity Curve is rising it increases margin proportionately but when the curve declines it reduces the Margin initially but then plateaus off; I've highlighted corresponding values in the pic below:


Note: The Pos Sizer is using the default Max Risk Percent setting under Preferences.
0
248
Solved
14 Replies

Reply

Bookmark

Sort
Cone8
 ( 24.57% )
- ago
#1
#1 - yup, it's already fixed for Build 33.

#2 - I'm not so sure that one's a bug. There's a lot going on with the Equity curve there. It looks to me like it couldn't keep trading due to the drawdown and massive borrowing. If WealthLab had margin calls, you'd be called in.
0
- ago
#2
#2: (Putting aside margin calls and just sticking to backtesting for discussion purposes...) It's a serious bug, check it out on *any* strategy you have using non-default values to expose it.
To repeat: As long as the equity rises the margin increases proportionately but when it declines after an initial adjustment it just stops adjusting even as equity plummets.
0
Cone8
 ( 24.57% )
- ago
#3
I looked at this backwards and forwards for hours about 2 weeks ago when [unnamed] thought there was a bug (there was not). It turned out that [they] weren't aware of how to set the max risk stop value. Let's start there. What are you using for the Max Risk Stop Value?
0
- ago
#4
Just discovered this may be a broader issue...

Modified strategy to use 'Percent of Equity' Pos Sizer instead:



The Equity Curve shows the same issue:


Notice that the margin cash is a mirror image of the Equity Curve as long as the curve is rising but when the equity decline is substantial then after an initial adjustment it stops adjusting and plateaus out (actually if you look closely there are other plateaus during previous declines as well).
0
Cone8
 ( 24.57% )
- ago
#5
It's not a bug. It's what going bust looks like. These are periods in the Equity curve where you've borrowed too much and you would get called in. The backtester just waits for the instruments to bounce back enough (or for the strategy to liquidate) to return some buying power to continue.
0
Best Answer
- ago
#6
The margin value (negative) doesn't line up with the account equity value (positive). [I shudder to think what the situation might be if the equity also went negative.]

I have a sneaky suspicion that the basis of this mismatch lies in the following math truism:
If a stock (or equity curve) value drops by, say, 50% it takes a 100% (and NOT 50%) increase to get back to original value.
So if the margin amount is only being adjusted by the decline in equity value it wouldn't be noticed if the declines were small or infrequent but after a cumulative number of small declines OR after a huge decline the math goes completely out of whack - and maybe that is what's happening here.
0
Cone8
 ( 24.57% )
- ago
#7
When your broker lends you 2:1 and you are fully extended, the portfolio cannot withstand losing even $1. Why? Because you've borrowed to the limit and as soon as you lose $1, you get called because you're over 2:1 margin. Listen, your equity can go to zero, but you still owe what you borrowed!

Here's a simple example to illustrate. It buys 200% of NVDA on 3/17/2022 and holds. Look what happens. Do you see why?

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript3 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (bars.DateTimes[idx] == _entry)                PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { } }           DateTime _entry = new DateTime(2022, 3, 16); } }




0
- ago
#8
I am well aware of the risks of margining. But on backtesting we don't take philosophical considerations into account. The backtester has to get the a/c equity (still positive presumably) and cash margin in line, or else stop the testing as soon as negative equity exceeds positive equity. You just *cannot* continue on with margin exceeding a/c value.
My 2 cents.
0
Cone8
 ( 24.57% )
- ago
#9
Trading does stop. You're stuck with what you have until the strategy sells something or the value of the holdings comes back in line. The only other solution is to have the backtester liquidate positions.

That's a feature request. Not a bug.

Imho, there are more important features to concentrate on. Why? Because when you see a strategy perform so poorly that you bust your margin, you need to either move on to another strategy or stop trading with margin.
0
- ago
#10
I use public strategies in my posts so everybody can follow along, not b/c I use them.
--------------------------------------------

A/C Equity = Assets - Liabilities = Value of Positions you own - Margin balance

When the a/c equity falls below zero the backtester must immediately Stop and mark all new signals as NSF, it simply can't carry on with a negative balance. This should be built-in.
0
Cone8
 ( 24.57% )
- ago
#11
Signals for new trades are NEVER marked NSF. NSF Signals are exit signals for NSF positions in the backtest.

Look, trading stops (adding new positions). If any new hypothetical position is created, it obviously is NSF by definition. Now where's that shrug emoji??..
0
Glitch8
 ( 10.41% )
- ago
#12
Sammy, your dogmatic way of stating your opinion is becoming grating. I respect your opinion but you have to realize it’s possible not everyone agrees with your preference?
0
- ago
#13
Just saying backtesting with negative equity is not possible.
That's reality, not dogma.
0
Glitch8
 ( 10.41% )
- ago
#14
And the backtest won’t generate new positions when equity is negative. You may still get signals though because WL8 maintains the integrity of the trading system even when there is not enough equity to take a trade in the simulation.

Of course it all depends on your strategy. If the strategy rules look at equity to base trade decisions on then obviously a new signal wouldn’t be generated.

Despite your attempt to convince me otherwise I think this is the best way to handle things 🤷🏼‍♂️
1

Reply

Bookmark

Sort