Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by 7th_zorro. 04/16/24 13:19
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (Quad, alibaba, rki, 7th_zorro), 365 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Equity control based on Rolling expectancy ratio #472101
04/07/18 17:30
04/07/18 17:30
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
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/
*/

Attached Files
mpEquityControl.c (25 downloads)
Last edited by MatPed; 04/09/18 11:35.
Re: Equity control based on Rolling expectancy ratio [Re: MatPed] #472113
04/09/18 09:48
04/09/18 09:48
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
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.

Last edited by brax; 04/10/18 10:40.
Re: Equity control based on Rolling expectancy ratio [Re: Brax] #472114
04/09/18 11:37
04/09/18 11:37
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Thank You Brax. Waiting for your comments. Ciao

Re: Equity control based on Rolling expectancy ratio [Re: MatPed] #472191
04/15/18 12:04
04/15/18 12:04
Joined: Jan 2018
Posts: 29
L
luisd Offline
Newbie
luisd  Offline
Newbie
L

Joined: Jan 2018
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

Last edited by luisd; 04/15/18 12:08.
Re: Equity control based on Rolling expectancy ratio [Re: luisd] #472193
04/15/18 14:29
04/15/18 14:29
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
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

Re: Equity control based on Rolling expectancy ratio [Re: MatPed] #472196
04/15/18 20:20
04/15/18 20:20
Joined: Jan 2018
Posts: 29
L
luisd Offline
Newbie
luisd  Offline
Newbie
L

Joined: Jan 2018
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

Re: Equity control based on Rolling expectancy ratio [Re: luisd] #472197
04/15/18 21:27
04/15/18 21:27
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Ok, thank you. I will test it. Ciao


Moderated by  Petra 

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

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

Powered by UBB.threads™ PHP Forum Software 7.7.1