Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
optimize and PARAMETERS|RULES - in asset() & algo #476099
01/26/19 14:08
01/26/19 14:08
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline OP
Junior Member
laz  Offline OP
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Hi, guys...

I want to do the following:

Code:
while(asset(loop(ASSETS))) 
while(algo(loop(ALGOS))) {

   TakeProfit = optimize(1,1,4,1) * ATR(100);
   Stop       = TakeProfit / 2.0;

   advise()...

}


I want to see which TP/SL the model can train better - with a custom Objective depending on the TP/SL.

Combining rules and parameters - https://zorro-project.com/manual/en/training.htm

case 1 - "Parameters depend on rules" <- wrong here
case 2 - "Rules depend on Parameters" <- true here
case 3 - "Rules and parameters affect each other." <- true here

For every parameter step a new set of rules needs to be generated.

BUT 2 PROBLEMS:

1.) problem:
Code:
case 2 - "Rules depend on Parameters" 

if(is(TRAINMODE)) set(RULES|PARAMETERS); else set(RULES);


Quote:
[...]In [Test] and [Trade] mode set the RULES flag only, not PARAMETERS, as the parameter only affects rule generation and has no further relevance for the script.

I need the optimized value here. In this case the parameter affects rule generation
and has no further relevance for the script. So i can't use case 1 & 2.

2.) problem:

Code:
solution 3 - Rules and parameters affect each other

set(RULES|PARAMETERS);


the manual still says:

Quote:
Training rules and parameters at the same time only works with single assets, not with a portfolio system that contains loops with asset or algo calls.

Here i found an old post (2014), telling us that Zorro will support that in the future...
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=441154#Post441154
Quote:
But a future Zorro version will support this with portfolio systems also.

So i can't use any of this methods confused ?

Or is it possible meanwhile?

What is the best way?

Last edited by laz; 01/28/19 01:24.
Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: laz] #476103
01/27/19 01:46
01/27/19 01:46
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Seems to me a clear case 1, entry rules should be not affected by stop and takeprofit. Entry rules and exit rules are normally completely separate.

Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: Spirit] #476112
01/28/19 00:34
01/28/19 00:34
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline OP
Junior Member
laz  Offline OP
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Hi Spirit and thanks for your answer, can we discuss it?

If you have Workshop7 in mind I would agree with you. Fixed patterns are searched first (Step 1) and in Step 2 the best matching parameters to catch the learned patterns. A subsequent change of the parameters does NOT change the patterns found here.

In NEURAL training the "next Trade Return / Result" or custom objectives that looks different (to me). Maybe I'm wrong but I think it does not make sense to train an ML model first on certain rules - if you then change these rules after training again. I'll post some code parts, let's see what you (or others) think about this approach.

PEEK is used and DataHorizon = 30...

Code:
while(asset(loop(ASSETS))) 
while(algo(loop(ALGOS))) {

   TakeProfit = optimize(1,1,4,1) * ATR(100);
   Stop       = TakeProfit / 2.0;

   vars dat = series(price());
   vars rsi = series(RSI(dat,5));

   int pos = 0;            // future bar pos
   var fhv = priceHigh(0); // future highest high value
   var flv = priceLow(0);  // future lowest low value
   var obL = -1.0;         // custom objective long, never 0
   var obS = -1.0;         // custom objective short, never 0
		
   if(Train && !is(LOOKBACK)) {

      for(pos=1; pos <= DataHorizon; pos++) {

         fhv = max(fhv,priceHigh(-pos));
         flv = min(flv,priceLow(-pos));		
					
      }

      if(valley(rsi) && flv > (priceClose(0) - Stop) && fhv > (priceClose(0) + TakeProfit)) obL=1.0;
      if(peak(rsi)   && fhv < (priceClose(0) + Stop) && flv < (priceClose(0) - TakeProfit)) obS=1.0;

   }

   var avL = adviseLong(NEURAL+BALANCED,obL,INP,12);
   var avS = adviseShort(NEURAL+BALANCED,obS,INP,12);

}


Starting from the current position (Bar) I'm scanning the next 30 bars for it's lowest and highest values. After that i create a custom objective, if price starts from valley/peak and hits the Takeprofit but not the Stoploss, take this trade / objective = 1 else -1.

Question 1: Changing the TP/SL after i have trained the model with a custom objective makes no sense here?

Question 2: If you use Objective = 0, you will train your model for every positive trade. These often win only by chance, not because a rule is behind these entry's. I have never achieved meaningful results with this method (open a trade on every bar + learning all positive trade returns). What should an ML model generalize here?

Last edited by laz; 01/28/19 02:09.
Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: laz] #476115
01/28/19 03:45
01/28/19 03:45
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
In your script the rules are indeed affected by stop and takeprofit. So you have a case 3 here. The question is only if this generates a good model.

In our experience, a machine learning model usually deteriorates with the complexity of the objective. The best models use 0, the price difference, or the price sign for the objective. The "bad" system of your question 2 is in fact one of the best.

Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: jcl] #476116
01/28/19 05:04
01/28/19 05:04
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline OP
Junior Member
laz  Offline OP
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Hi jcl, i was also thinking that - but in the manual is still written:

Quote:
Training rules and parameters at the same time only works with single assets, not with a portfolio system that contains loops with asset or algo calls.

I'm not sure what happens if i do it with set(RULES|PARAMETERS); in Asset/Algo loops ? Will it work correctly?

Quote:
In our experience, a machine learning model usually deteriorates with the complexity of the objective.

I agree... But using every possible next trade return (enter on every bar/input signal) is not complex?

Quote:
The best models use 0, the price difference, or the price sign for the objective. The "bad" system of your question 2 is in fact one of the best.

How is that possible? Imagine a simple Perceptron, if we change the Input, we also change the Output. In Training (by using Trade returns) we move the weights to separate our classes. We want the perceptron to fire if the input/s is(are) "in range X to Y".

But if we use Trade Returns from all possible entry's - no matter how small or big the profits are, f.i. 0.01 to 200 - trades starting from random/different Input values - aren't we confusing the TRAIN process here? What is our target? And if we use all the "next Trade returns" we train so many entry points which have no meaning? (bad or no local minima)

A Perceptron or NeuralNet is not a Support Vector Machine.

Quote:
An SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible.

Am I thinking wrong?

Thank you, I do not know anybody else I could ask such questions wink

PS: Maybe your models didn't train well (with a custom objective) because +BALANCED does not work with extreme unbalanced classes. I have seen it with that example and did the up-sampling in R.

Last edited by laz; 01/28/19 05:36.
Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: laz] #476118
01/28/19 06:54
01/28/19 06:54
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
I think the single asset restriction is still in place, at least I have no otherwise notice. And yes, you're confusing the training process when you use stops and then train trade returns. Train the system only with plain returns or with the price curve or other fundamental data, but not with artificial values generated with stops or other algorithms.

Your conception of a SVM looks correct.

Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: jcl] #476120
01/28/19 08:44
01/28/19 08:44
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline OP
Junior Member
laz  Offline OP
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Ok thanks for the information, maybe you can add this feature in the future wink...

So for me the only way to get this running is to do it in separate for loops?

Quote:
... train all portfolio components separately and combine the resulting .c files. The Combine.c script can be used as a template for automatically combining parameters and rules from different assets or algos. Machine learning models (.ml files) can be combined with an appropriate R function.

I'll later look into Combine.c and i can do the R part, no problem.

When i use separate for loops, i can use every option? For WFO nothing changes?

1. Parameters depend on rules.
2. Rules depend on parameters.
3. Rules and parameters affect each other.

Quote:
And yes, you're confusing the training process when you use stops and then train trade returns. Train the system only with plain returns or with the price curve or other fundamental data, but not with artificial values generated with stops or other algorithms.

I have to think about it wink thanks

with the price curve = regression?

But one question comes up again, in neural.train() you cast every positive return to 1 and everything else to 0.
How do you define the targets/close of your trades? What am I missing here? confused ?

Last edited by laz; 01/28/19 17:50.
Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: laz] #476132
01/28/19 19:03
01/28/19 19:03
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
The Combine script is for .c files, but when you use R you have .m files and must handle the combining on the R side.

WFO works. You'll then get several .m files.

Trades for training have normally no target, but a fixed lifetime. Instead of 0/1, you can also scale the result to an analogue 0..1 range - what is better depends on your ML algo.

Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: jcl] #476134
01/28/19 23:50
01/28/19 23:50
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline OP
Junior Member
laz  Offline OP
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Thanks for the feedback, I have looked at the combine script. And I already have loaded the .ml files in R, I am familiar with R. In R I just have to load the ml files and create a new (per WFOCycle) list and save it. I will post the R code here, if someone needs it again.

Quote:
Trades for training have normally no target, but a fixed lifetime. Instead of 0/1, you can also scale the result to an analogue 0..1 range - what is better depends on your ML algo.

I do not quite understand this approach yet but I will think about it. So far, I have tried using forecasting/regression rather than classification, because of the question: How to train an ML-Algo on a target (class) that I can not clearly define. If I had a trainer that could produce accurate train-signals, I would not need to teach ML-Algos crazy ...

I do not understand with this principle, which of the many different training signals the net should learn. And what should it learn from it. Is there somewhere more detailed information on the subject?

Re: optimize and PARAMETERS|RULES - in asset() & algo [Re: laz] #476144
01/29/19 02:37
01/29/19 02:37
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
There are many online informations or books about machine learning. In finance the goal is normally predicting the future price direction or trade result. I suppose that's also the intention of your script. In special cases you want to predict other parameters such as volatiliy or market efficiency.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1