Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, EternallyCurious, Petra, 1 invisible), 788 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Testing AI functions and reinvesting #450398
04/13/15 21:03
04/13/15 21:03
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
I would like to explore the AI functions so I trained and tested with EUR/USD the example from the manual (I am using Zorro 1.28) and I have 3 questions:

Code:
void run()
{
  BarPeriod = 60;
  LookBack = 150;
  TradesPerBar = 2;
  set(RULES|TESTNOW);
  if (Train)
    Hedge = 2;
// generate price series
  vars H = series(priceHigh()), 
    L = series(priceLow()),
    C = series(priceClose());
// generate some signals from H,L,C in the -100..100 range 
  var Signal1 = (LowPass(H,1000)-LowPass(L,1000))/PIP,
    Signal2 = 100*Fisher(C,100);
  Stop = 4*ATR(100); 
  TakeProfit = 4*ATR(100);
  if(adviseLong(DTREE,0,Signal1,Signal2) > 0)
    enterLong();
  if(adviseShort(DTREE,0,Signal1,Signal2) > 0)
    enterShort();
}



Notice that I added if (Train) Hedge = 2; so that it can be properly trained as the manual says, if not, accuracy would result in 0%

Since I am on purpose overfitting it gives 391% AR, 4.14 Sharpe Ratio, 0.91 R2, UI 1%...

Ok, now I add:

NumWFOCycles = 5;

Train and test, and it gives 2% AR, Sharpe of 0.04 and UI of 278%...Not nice.

So, quoting the manual
Quote:
Often a perceptron can be used where a decision tree fails, and vice versa.
I changed the method to PERCEPTRON, trained and tested without WFO and it gave 19% AR, Sharpe Ratio of 0.28 and R2 0.59

First question: why since I am overfitting on purpose it gives low stats?


anyway, now I trained and tested with wfo (same as before, 5 cycles) and I get:

Prediction accuracy: 47%
Rules stored in perceptron1_EURUSD.c


Run perceptron1..
Walk-Forward Test: perceptron1 EUR/USD 2010..2015.
Read perceptron1_EURUSD_1.c perceptron1_EURUSD_2.c perceptron1_EURUSD_3.c. perceptron1_EURUSD_4.c
Monte Carlo Analysis... Median AR 48%
Profit 3982$ MI 157$ DD 2536$ Capital 3993$
Trades 12572 Win 55% Avg +3.6p Bars 27
AR 47% PF 1.15 SR 0.73 UI 13% R2 0.01

Second question: why are the stats of the wfo higher than the ones of the overfitted train? Shouldnīt it be the other way?

Then I added reinvesting with this code:

Code:
void run()
{
  BarPeriod = 60;
  LookBack = 150;
  TradesPerBar = 2;
  NumWFOCycles = 5;
  Capital = 1000;
  set(RULES|FACTORS|TESTNOW);
  
  if (Train)
    Hedge = 2;
// generate price series
while(asset(loop("EUR/USD","USD/JPY"))){
  Margin = OptimalF * Capital * sqrt(1 + max(0,WinTotal-LossTotal)/Capital); 	
  vars H = series(priceHigh()), 
    L = series(priceLow()),
    C = series(priceClose());
// generate some signals from H,L,C in the -100..100 range 
  var Signal1 = (LowPass(H,1000)-LowPass(L,1000))/PIP,
    Signal2 = 100*Fisher(C,100);
  Stop = 4*ATR(100); 
  TakeProfit = 4*ATR(100);
  if(adviseLong(PERCEPTRON,0,Signal1,Signal2) > 0)
    enterLong();
  if(adviseShort(PERCEPTRON,0,Signal1,Signal2) > 0)
    enterShort();
    }
}



trained and tested and I get

Monte Carlo Analysis... Median AR -5%
Profit -19278$ MI -761$ DD 142736$ Capital 113553$
Trades 25050 Win 51% Avg +2.0p Bars 28
CAGR -1% PF 0.97 SR -0.15 UI 39% R2 0.00

perceptron1 run..
Walk-Forward Test: perceptron1 portfolio 2010..2015
Read perceptron1.fac. perceptron1_1.c. perceptron1_2.c perceptron1_3.c. perceptron1_4.c
Monte Carlo Analysis... Median AR -5%
Profit -19278$ MI -761$ DD 142736$ Capital 113553$
Trades 25050 Win 51% Avg +2.0p Bars 28
CAGR -1% PF 0.97 SR -0.15 UI 39% R2 0.00

so,

Third question: Why I am getting a negative result with more assets and reinvesting? Should I train FACTORS and RULES separately? I didnīt find anything in the manual related.

Thanks for your help!

Re: Testing AI functions and reinvesting [Re: Mithrandir77] #450438
04/14/15 12:48
04/14/15 12:48
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I can at least answer the last question: You're getting a negative result when you're reinvesting too much. You're having two assets, but are reinvesting the full capital maximum into any of it - that can work when you have a smooth equity curve, otherwise not.

Re: Testing AI functions and reinvesting [Re: jcl] #450446
04/14/15 14:46
04/14/15 14:46
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: jcl
I can at least answer the last question: You're getting a negative result when you're reinvesting too much. You're having two assets, but are reinvesting the full capital maximum into any of it - that can work when you have a smooth equity curve, otherwise not.


Thanks for your answer jcl, but what do you mean by 'investing the full capital maximum into any of it' ? I thougth that by setting the FACTORS flag and investing the sqrt of the total profit as in workshop 6 I should be fine

Margin = OptimalF * Capital * sqrt(1 + max(0,WinTotal-LossTotal)/Capital);


And is it ok to train RULES and FACTORS at the same time or should one be trained before the other as in training RULES and PARAMETERS?

Re: Testing AI functions and reinvesting [Re: Mithrandir77] #450742
04/21/15 19:45
04/21/15 19:45
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: Mithrandir77
Originally Posted By: jcl
I can at least answer the last question: You're getting a negative result when you're reinvesting too much. You're having two assets, but are reinvesting the full capital maximum into any of it - that can work when you have a smooth equity curve, otherwise not.


Thanks for your answer jcl, but what do you mean by 'investing the full capital maximum into any of it' ? I thougth that by setting the FACTORS flag and investing the sqrt of the total profit as in workshop 6 I should be fine

Margin = OptimalF * Capital * sqrt(1 + max(0,WinTotal-LossTotal)/Capital);


And is it ok to train RULES and FACTORS at the same time or should one be trained before the other as in training RULES and PARAMETERS?


OK, I think I understood. But how can I smooth the equity? either a perceptron can't model the relationship or I have to optimize some parameters. So I Will try optimizing.

Anyway, I am still stuck with how to train FACTORS and RULES. At the same time? Or in what order?

Re: Testing AI functions and reinvesting [Re: Mithrandir77] #450758
04/22/15 08:35
04/22/15 08:35
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Factors rely on anything else and thus are always trained at the end of the training process.


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