Equity control based on Rolling expectancy ratio

Posted By: MatPed

Equity control based on Rolling expectancy ratio - 04/07/18 17:30

Hi,
I have written a small package in order to control the equity of a portfolio strategy applied to each portfolio component and for the global Portfolio based on Rolling expectancy ratio.

The package improve the results of the test script disabling trading when the ReR drop below the given limit.

I am an average coder, learned programming at school and very influenced by the Pascal approach. I need help for testing and improve efficiency. Any "code upgrade "in this area is more than welcome.

The file includes a test script based on Zorro's WorkShop.

/*
Requires Zorro version >= 1.80.6
Equity control applied to each portfolio component and for the global Portfolio
based on Rolling expectancy ratio: ReR = ((AvgWin / AvgLoss) * WinRate) – (1 – WinRate)

Usage:
int checkAAEquity(int allAA, int sAA, var limit);

where
int allAA, # of trades used for ReR calculation all Algo/Asset considered - 0, no ReR Check
int sAA, # of trades used for ReR calculation for each Algo/Asset combination - 0, no ReR CCheck
var limit, Above limit: normal trading. Below limit, phantom trading

Example: checkEquity(30, 15, 0.0); // See run function below
For testing:
1 - Uncomment: #define TESTcheckAAEquity
2 - Train
3 - Test with checkAAEquity(0, 0, 0.0);
4 - Test with checkAAEquity(30, 15, 0.0);
5 - Enjoy

Reference:
https://www.financemagnates.com/forex/bloggers/equity-curve-trading-part-2-rolling-expectancy-ratio/
*/

Attached File
mpEquityControl.c  (25 downloads)
Posted By: Brax

Re: Equity control based on Rolling expectancy ratio - 04/09/18 09:48

Good contribution MatPed!

I've taken a brief glimpse to the code and it indeed looks quite good to me. I hope to test it in the upcoming weeks, so i'll tell you later.

These approaches work better with clearly losing streaks, but they still can improve lots of other situations.

Again, good job.
Posted By: MatPed

Re: Equity control based on Rolling expectancy ratio - 04/09/18 11:37

Thank You Brax. Waiting for your comments. Ciao
Posted By: luisd

Re: Equity control based on Rolling expectancy ratio - 04/15/18 12:04

fascinating code Mat!

as to the formula for ReR I was curious and did some math.

It turns out that ReR is the expected gain normalized over the expected loss.

Code:
RER = E[Gain]/E[Loss]

where 

 E[Gain] = E[Win] - E[Loss] 


 E[Win]  = <Win> * p(win) (read: 'expected win = average win * prob win)
 E[Loss] = <Loss> * p(loss)


then <win>, <loss> and p(win) are estimated using the previous N trades.
Assuming for simplicity <Win> and <Loss> are constants, then ReR uses the outcome of the previous N trades to estimate probability of win over the next trade.

Using the last N trades to estimate the prob win of the next one does not seem particularly innovative, but I find interesting that the figure of merit (ReR) normalizes the Expected Gain (W-L) to the Expected Loss (L) as it allows to weight the potential benefit to the risk.

It is similar to normalizing the average/mean to the variance I guess.

To reap the benefit of such normalization one should use a threshold Th > 0. Setting Th = 0 eliminates the normalization.

very well done Mat. Ciao wink
Posted By: MatPed

Re: Equity control based on Rolling expectancy ratio - 04/15/18 14:29

Thank You Luisd,
The Algo is not built to forecast the behavior of the TS but to block bad trading systems.
In the article linked in the first post, value below 0.0 were used for testing purposes. Why are you saying that the formula will work only for th >0. I Would appreciate if you articulate your statement a little more.

Thank you in advance
Posted By: luisd

Re: Equity control based on Rolling expectancy ratio - 04/15/18 20:20

Hi Mat,

to me the idea behind that formula is the following:

I will keep trading if, in the last N trades, my net profit is not only positive (in this case you would need no normalization) but sufficiently big when compared to the average loss (here is where you need the normalization).

For example, if in the last 10 trades you Won $10 and your average loss was 100$, the ratio of what you won ($10) over your average risk ($100) is too small and maybe you want to pull out.

Depending on the number of trades and their distribution, your E[Win] could still be statistically significant. Let's not try to dig into this. I think the formula is heuristic, let's keep it there.

I think that the bonus of that formula is that it allows to pull you out before your E[Win] drops below zero: you would get out when you are still winning, but your wins are too small compared to your risk.

That's why I would use it with a threshold positive and big enough, maybe close to 1.


ciao
Luigi
Posted By: MatPed

Re: Equity control based on Rolling expectancy ratio - 04/15/18 21:27

Ok, thank you. I will test it. Ciao
© 2024 lite-C Forums