Testing AI functions and reinvesting

Posted By: Mithrandir77

Testing AI functions and reinvesting - 04/13/15 21:03

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!
Posted By: jcl

Re: Testing AI functions and reinvesting - 04/14/15 12:48

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.
Posted By: Mithrandir77

Re: Testing AI functions and reinvesting - 04/14/15 14:46

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?
Posted By: Mithrandir77

Re: Testing AI functions and reinvesting - 04/21/15 19:45

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?
Posted By: jcl

Re: Testing AI functions and reinvesting - 04/22/15 08:35

Factors rely on anything else and thus are always trained at the end of the training process.
© 2024 lite-C Forums