Gamestudio Links
Zorro Links
Newest Posts
Please consider
by DriftWood
Today at 03:10
Draw stuff from other thread
by Superku
Yesterday at 23:25
Partial fills with MT4 in live trading?
by Sphin
Yesterday at 19:06
New Zorro version 1.83
by DdlV
Yesterday at 13:55
Cubemaps losing mipmaps
by Quad
Yesterday at 12:37
Zorro & virtual desktops & Installation
by jcl
Yesterday at 10:59
ccyStrength() only working for some Currencies
by sdh309795gaas
07/18/18 05:02
AUM Magazine
Latest Screens
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
RPG PARTY
Who's Online
14 registered (brax, 3run, Quad, Hredot, kvm, mk_1, alibaba, jenGs, 3 invisible), 514 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
DJ_Algo, tang, stuvwx210277, refltr, hillab
18002 Registered Users
Topic Options
Rate This Topic
#472101 - 04/07/18 19:30 Equity control based on Rolling expectancy ratio
MatPed Offline
Senior Member

Registered: 02/28/15
Posts: 449
Loc: Milano, Italy
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/
*/


Attachments
mpEquityControl.c (10 downloads)



Edited by MatPed (04/09/18 13:35)

Top
#472113 - 04/09/18 11:48 Re: Equity control based on Rolling expectancy ratio [Re: MatPed]
brax Online
Junior Member

Registered: 08/02/17
Posts: 74
Loc: Spain
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.


Edited by brax (04/10/18 12:40)

Top
#472114 - 04/09/18 13:37 Re: Equity control based on Rolling expectancy ratio [Re: brax]
MatPed Offline
Senior Member

Registered: 02/28/15
Posts: 449
Loc: Milano, Italy
Thank You Brax. Waiting for your comments. Ciao

Top
#472191 - 04/15/18 14:04 Re: Equity control based on Rolling expectancy ratio [Re: MatPed]
luisd Offline
Newbie

Registered: 01/19/18
Posts: 29
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


Edited by luisd (04/15/18 14:08)

Top
#472193 - 04/15/18 16:29 Re: Equity control based on Rolling expectancy ratio [Re: luisd]
MatPed Offline
Senior Member

Registered: 02/28/15
Posts: 449
Loc: Milano, Italy
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

Top
#472196 - 04/15/18 22:20 Re: Equity control based on Rolling expectancy ratio [Re: MatPed]
luisd Offline
Newbie

Registered: 01/19/18
Posts: 29
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

Top
#472197 - 04/15/18 23:27 Re: Equity control based on Rolling expectancy ratio [Re: luisd]
MatPed Offline
Senior Member

Registered: 02/28/15
Posts: 449
Loc: Milano, Italy
Ok, thank you. I will test it. Ciao

Top



Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de