# 3rd generation NN, deep learning, deep belief nets and Restricted Boltzmann Machines

#### fralo

##### Active member
104 0
Initially I wondered why we use the SVM on such apparantly trivial estimation problems. Bayes shows us that the best decision we can make uses the conditional pdf p(y/x) where y is output and x is input. So in effect, we are using the SVM to estimate this pdf. Another way to estimate it would be to count the number of times x results in y (Num(y/x)), and count the number of times x occurs. Then a good estimate i s Num(y/x)/Num(x). This is probably pretty good if we have 60 counts or so in each counting bin. So, for 1000 samples, as used in these examples, we could accommodate maybe 16 bins.

In fact, for the Explosivepip strategy there are only 3 conditions and 2 outputs, so we would need only 16 bins, and 1000 samples are probably enough.

However in the pipMaximizer strategy there are 9 conditions and 2 outputs, so we would need 256 bins, and with 1000 samples we have only 4 counts in each bin on average, so the estimate would probably be poor indeed if the pdf is at all spread out.

It would be interesting to compare the performance of an SVM to a histogram at least for the ExplosivePip strategy.

We might simply use more samples and return to counting things, but then we might run up against the inherent non-stationarity in Fx series. By the time we got to 25600 samples we might have lost the local pdf, and find only a pdf averaged over too much time. So maybe the SVM is a good idea after all. It will be a particularly good idea if we ever get to continuous inputs and outputs.

Incidentally, I have been trying to understand the hasline.m code. It seems to me that this is a count of the number of bars that cross a line defined by the mid of a bar. This is not the same as the article referenced in the code comments, where the idea is to find price lines with the minimum number of crossings. Furthermore, the result is counted over a period from 1 to t-1 which increases with t. So as t increases this count will increase, and the likelihood that it will exceed M will increase, until after a couple of hundred samples it seems that this indicator is very likely to be 1 and carry no information. Can someone check me on this please?

#### fralo

##### Active member
104 0
Indicator builder uses open for BBands and all MA's. If we use close for entry/exit (as we should) then I suggest that all indicators use close as input.

##### Legendary member
10,850 1,234
Listened to the first few minutes of one of these out of curiosity..and I have to say it sounds like a pile of sh1t..... deliberately vague and pseudo -complicated ..maybe it gets better further on in...anyone else have more patience ?

I like the way you circled the problem and then decided to call a spade a spade!

They'll be feeding us prawnsandwiches next!

#### Krzysiaczek99

##### Well-known member
430 1
Indicator builder uses open for BBands and all MA's. If we use close for entry/exit (as we should) then I suggest that all indicators use close as input.

Yes it must be changed otherwise is a mess for example in this code
he compares pSAR with Close and checks MACDSign which is calculated on Open

Code:
``````cond(1) = pSAR(i) < close(i); % parabolic SAR below
cond(2) = (price(i) > stop) || (price(i) < limit);
cond(3) = (MACDSign(i)) > 0 && (MAhist(i) > 0); %TODO: cross over above``````

I will make a document where i will collect all changes and solutions

#### Krzysiaczek99

##### Well-known member
430 1
You should not waist your time on this kind on nets. I have implemented several kinds and realized that the reasons they work so well at classifying stuffs are the very reasons they don’t work when applied to markets:

They are very sensitive to the number and the size of layers which make them impractical in market environments.

For the training stage to converge properly they need many thousands input occurrences:
- Even in optimized C++ training takes several hours,
- Even with feature extraction, it is hard or even impossible to find such high number of input occurrences from market data.

These networks have several hundred million neurons the majority on them placed on the first layer. The reason Deep networks work so well in classification is that they encode each possible solution to the problem in the first layer. It is then just a matter to pick the most appropriate one from higher level representations just as it happens in the brain. Deep networks fit the problem at hand very well though raising the question of generalization. Neural nets do not adapt but I was expecting them to pick recurrent market states so that I could trade the deviation. Well, it was quite a disappointment for me to realize that they don’t. It was argued that deep networks infer new solutions after learning but I did not see it.

My conclusion after 3 years investigating deep architectures. They are not appropriate to trading at the moment. To address the generalization issue we need incremental versions with online learning. I am currently looking into dynamic factored structures which use similar RBM building blocks. I believe they are more promising but still in a very early stage of development.

My advice: carry out due diligence before spending time on this.

My 2 pips.

Very interesting mail. Is your research a public domain ?? Is it possible to have a look ??
What sort of models you examined ?? Did you try Hilton's autoencoder model with pretraining, training and fine tuning ?? What learning algorithms you used ??

Krzysztof

#### Prawnsandwich

##### Well-known member
339 30

I like the way you circled the problem and then decided to call a spade a spade!

They'll be feeding us prawnsandwiches next!

Maybe I was just being lazy and jumping to conclusions.....or maybe not..:cheesy:

#### Krzysiaczek99

##### Well-known member
430 1
Incidentally, I have been trying to understand the hasline.m code. It seems to me that this is a count of the number of bars that cross a line defined by the mid of a bar. This is not the same as the article referenced in the code comments, where the idea is to find price lines with the minimum number of crossings. Furthermore, the result is counted over a period from 1 to t-1 which increases with t. So as t increases this count will increase, and the likelihood that it will exceed M will increase, until after a couple of hundred samples it seems that this indicator is very likely to be 1 and carry no information. Can someone check me on this please?

Yes, the code is wrong

Code:
``````its called from here in explosivePip

54  for t=1:length-1
price = open;
cond = zeros(1,NUM_COND);
cond(1) = hasLine(low,high,t,'SUP');

function x = hasLine(low, high, t, type)
% A Method for Drawing Support and Resistant Line
% a suport line is present if there at least previous M bar that cross
% its price.
% We added that past high must not below current line for support
% and past low must not above current line for resistant
% In this simplified version, we choose:
M = 4;
x = 0;
if (t >= M)
cross_count = 0;
mid = (low(t) + high(t))/2;
last = t-1;
for i = 1:last  [B]<----- range will increase on every call[/B]
if (low(t-i) < mid) && (high(t-i) > mid)
cross_count = cross_count + 1; % first cross is itself
if (cross_count >= M)
break;
end``````

the range in 'for' statement will increase but it should be fixed. Perhaps instead of this we can use another solution. See this.

Krzysztof

430 1

#### fralo

##### Active member
104 0
Here is a question for philosophers and thread poets. Care to answer?

There is inherent structure in the images and speech that have been the targets of most DBN research... most children can do better than most machines because they have learned the structure. The machines try to extract the structure. Some do it well for images and speech. Can they do it for markets?

Is there structure to some representation of the markets? Certainly not recognizable by most adults. Probably not recognizable by majority of traders. Do supertraders recognize structure, or are they just defying the odds?

DBN machines make sense for robotic applications. Do they make sense for the market?

#### Highfreq

##### Junior member
47 2
Here is a question for philosophers and thread poets. Care to answer?

There is inherent structure in the images and speech that have been the targets of most DBN research... most children can do better than most machines because they have learned the structure. The machines try to extract the structure. Some do it well for images and speech. Can they do it for markets?

Is there structure to some representation of the markets? Certainly not recognizable by most adults. Probably not recognizable by majority of traders. Do supertraders recognize structure, or are they just defying the odds?

DBN machines make sense for robotic applications. Do they make sense for the market?

Here are features from patches of weights in the second layer of a DBN trained with contrastive divergence and fine tuned with conjugate gradients. These features are high level representations of price patterns. Very powerful stuff. The only concern and not the least would be to devise an online version of the training process so that we can use them in trading. I am not aware that online learning exists for deep structures.

Sorry got to close a position...

#### Attachments

• Feature 5-50.gif
13 KB · Views: 571
• Feature 12-50.gif
12.6 KB · Views: 483
• Feature 10012.gif
12.6 KB · Views: 406

#### fralo

##### Active member
104 0
I found several bugs that were future leaks, and some that were due to stop and limit exit prices not correctly evaluated. I changed these to fix the bugs, and ran a strategy evaluation on the new code. The results are very different. e.g. For instantpip I get profit = -\$1724 on 461 trades.

I did not test the other strategies, since I do not have confidence in my ability to code fixes in MatLab. The modified code is contained in the zip file below. You will find that there are changes in spotFX.m,hasline.m, indicatorBuilder.m, and the four exits. All of my future leak changes are marked by a comment beginning with scf, so they are easily found; however, to fix the problem with stop and limit exit prices I had to make larger changes, so not all those are commented. But they are obvious on comparison to earlier versions.

The code I used to train and evaluate the instantpip strategy is in the zip file. Anyone interested please do not take my word, but look at the code and find any errors that I have made. I hope you find some.

If you find no errors, then I suggest that most of the good results reported in TradeFX are due to future leaks and incorrect exit price evaluation. We must do the work over!

#### Attachments

10.7 KB · Views: 403

#### Krzysiaczek99

##### Well-known member
430 1
Here are features from patches of weights in the second layer of a DBN trained with contrastive divergence and fine tuned with conjugate gradients. These features are high level representations of price patterns. Very powerful stuff. The only concern and not the least would be to devise an online version of the training process so that we can use them in trading. I am not aware that online learning exists for deep structures.

Sorry got to close a position...

So are you using this autoencoder setup with pretraining and fine tuning ?

Did you or somebody else try Convolutional Neural Networks for market data ??

Krzysztof

#### fralo

##### Active member
104 0
Here are features from patches of weights in the second layer of a DBN trained with contrastive divergence and fine tuned with conjugate gradients. These features are high level representations of price patterns. Very powerful stuff. The only concern and not the least would be to devise an online version of the training process so that we can use them in trading. I am not aware that online learning exists for deep structures.

Sorry got to close a position...

I don't see why an online version could not be done. Conceptually you could do it with two Dll's, one to train and one to classify as follows:
Arrays/structures:
Rates array.. contains OHLCV for each bar
Target array..contains results if entry on a given bar
Input array
Net
MT4
Allocates memory for all structures (This is so that strategy tester will work. )
Maintains rates and Target array
Calls Net_Train with pointers to arrays
Calls Net_Classify with pointers to arrays
Net_Train
Calls feature_builder to build input array
Uses target array to label input array
Trains Net
Net_Classify
Calls feature_builder to update input array
Applies net to determine prediction
Feature_Builder
Calculates input to net .. indicators, conditions to build input array

Operation:
MT4 initializes the net by calling Net_Train
At end of each bar:
If a new label has been determined, MT4 calls Net_Train to update input array and retrain the net.
MT4 calls Net_Classify to get a prediction

This all assumes that a net_train dll could run in 1 bar time. If not, then the training would have to go on in the background while new input was collected. Would require some double buffering.

Those are intriguing pictures of hidden structure.:clap: What is the nature of the input price patterns, and the DBN used to find them? I assume unsupervised learning for this level?

#### Krzysiaczek99

##### Well-known member
430 1
I found several bugs that were future leaks, and some that were due to stop and limit exit prices not correctly evaluated. I changed these to fix the bugs, and ran a strategy evaluation on the new code. The results are very different. e.g. For instantpip I get profit = -\$1724 on 461 trades.

I did not test the other strategies, since I do not have confidence in my ability to code fixes in MatLab. The modified code is contained in the zip file below. You will find that there are changes in spotFX.m,hasline.m, indicatorBuilder.m, and the four exits. All of my future leak changes are marked by a comment beginning with scf, so they are easily found; however, to fix the problem with stop and limit exit prices I had to make larger changes, so not all those are commented. But they are obvious on comparison to earlier versions.

The code I used to train and evaluate the instantpip strategy is in the zip file. Anyone interested please do not take my word, but look at the code and find any errors that I have made. I hope you find some.

If you find no errors, then I suggest that most of the good results reported in TradeFX are due to future leaks and incorrect exit price evaluation. We must do the work over!

After three small changes in the scripts (twice change open to close and transaction_fee set) accuracy seems to be 68.1% for instantPip strategy for EURUSD30_1_16Apr09.csv.

Missing funcionality in all those scripts seems to be spread handling. Spread must be considered both in profit calculation and entry/exit conditions calculation.

Krzysztof

Replies
8
Views
3K
Replies
3
Views
1K
Replies
27
Views
19K
Replies
382
Views
69K