18.01.2013 г.

Chaos and complex representations for neuroevolution

In this article on my blog I summarized  my views on the proper way to obtain a robust solution through neroevolution.

Basically I question the whole architecture of the neuron when you are going to use  genetic optimization or particle swarm optimization.

I suggest a different architecture, in this architecture we replace the transfer function by more complex mathematical representation and we evolve the weights inside. Doing so we are able to boost the power of the neural network.  


The use of the logistic map as a very complex mathematical representation allow to add much more power to the neural net. By tuning the parameters (r) we can add a portion of chaos and by this  improve the robustness. 



This architecture is useful when no global solution exist and we face multiple local optima. In such case we want to find  practical but robust solution.


What is the basic idea of this neuron architecture. The basic idea is that we are not looking for a global optimum at all. Why? Because we know that this global optimum does not exist.

I would refer to the Hitchiker's guide to universe:

"Narrator: There is a theory which states that if ever anyone discovers exactly what the Universe is for (I replace with the market) and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened."

So we know that we have multiple local optima, and no global optimum at all. In fact to find a local optimum is not a problem at all. What we are looking for is to find a stable solution. And that stable solution can be achieved only if you let the genetic optimizer evolve the weights into a complex mathematical space.

So let see what is all about.

The use of genetic algorithm for training SVM models is not something new. Let start from the standard artificial neuron model. However we are going to do something different. We are not going to map the inputs into a multidimensional space. We are going to put the agents into multidimensional space.

The first thing to do is to have a look a the basic structure of the artificial neuron model. I think the relevant Wikipedia article is a very good reference:

"For a given artificial neuron, let there be m + 1 inputs with signals x0 through xm and weights w0 through wm. Usually, the x0 input is assigned the value +1, which makes it a bias input withwk0 = bk. This leaves only m actual inputs to the neuron: from x1 to xm.

The output of kth neuron is:
y_k =  \varphi \left( \sum_{j=0}^m w_{kj} x_j \right)
Where (phi) is the transfer function.

Artificial neuron.png


The output is analogous to the axon of a biological neuron, and its value propagates to input of the next layer, through a synapse. It may also exit the system, possibly as part of an output vector.

It has no learning process as such. Its transfer function, weights are calculated and threshold value are predetermined."

So this is the basic neuron model and different learning methods can be applied.

A research paper was proposing a another possible structure making the traditional neuron model more complex."The basic idea is in representing the weights, that belong to interconnections in the neural network, by function. The learning process then doesn't happen directly on the level of weights like it is common in normal neural networks, but instead it happens by changing the function that is used to generate the weight  every time when its value is needed."

The resulting neural network is called Hyper neural network. In the paper two approaches are used the representation of a function as a compressed matrix of coefficients used for Inverse Discrete Cosine transformation and representation of a function a a tree composed of elemental operations.

Another possibility is to make something different. We can vary the value of the weight using the formula of a transfer function and by this we may eliminate the use of a transfer function. We can  vary and optimize the weight (using transfer function formula).

In the theoretically the biologically inspired neural networks, there the activation function is an abstraction it represents the rate of action potential firing in the cell. However we may not need this abstraction for some practical problems.

By doing this we diverge from the general neural model. The question is what we can gain from that? What are we going to do?

The simplest thing is to use simple transfer functions and vary them (here we will generate a population from the transfer function), then to multiply the result to the input and that is the output.

In the normal model in its simplest form you take the input you multiply by the weight then you input this result within the transfer function to get the response.

However here you can do something different. You can use complex representations and generate populations from them.

You can watch the video in this link to see a practical implementation of approximation of function by genetic algorithm using the Trading Software Metatrader 5. You can read more how the software works on this link.

Then the learning happens on the level of the transfer function. You may vary also the weights too but here we will not do so.



 This is the Gaussian function. On the next picture you can see how the genetic algorithm approximate that.















From this the neuron model will look like this:


double perceptron()
  {
     double weight1 =  MathExp(gamma*(-x1*x1-y1*y1));
     double weight2 =  MathExp(gamma*(-x2*x2-y2*y2));

 
    double input1 = iCustom(TimeFrame,Symbol(),"PFE",x5,true,5,0,0);
    double input2 = iCustom(TimeFrame,Symbol(),"PFE",x6,true,5,0,0);
    double input3= iCustom(TimeFrame,Symbol(),"PFE",x7,true,5,0,0);
    double input3= iCustom(TimeFrame,Symbol(),"PFE",x8,true,5,0,0);

   return ( weight1* input1 +  weight1* input2 +  weight2*input3 + weight2* input4);
  }


-We use the genetic algorithm to vary the values of the weights:
x1, x2,y1,y2

-You can modify at will the architecture

-This model is different from the classical neuron model. We do not have a transfer function. By doing this we eliminate the need of transfer function, you can add it but it is not necessary.

However we can use even more complex representations: We can use the logistic map as a complex space and vary the parameters of the logistic map.


(1)\qquad x_{n+1} = r x_n (1-x_n)

That is the equation of the logistic map.

What is interesting for us is the parameter r. If we vary the parameter we will have different behaviour (sensitivity of the initial conditions). I keep it short here but we can get some very interesting stretching-and-folding structures.
image

image








image
This is 3d picture of the logistic map. Logistic map as a kernel function. Why not?

We have a very complex representations from a very simple formula and the properties of the logistic map are well known.



  Here we use:


- RECURRENT DIFFERENCE EQUATION: the code is simple however the recurrence is not supported by OpenCL by now.

- TO USE SOME PORTION OF CHAOS: this can be obtained by varying the value of r approximately 3.57 is the onset of chaos, so we can limit from 1 to 3, if we want to add some chaose we can go from 1 to 4 . The use of noise in the neural net training is a common pragmatic approach to increase the robustness of the solution. The x value os from 0.001 to 1 with step size of 0.001 for example. We can vary the number of iterations (limitmap) to as a parameter. As a result we get something terribly complex.

The idea here is that there is not a global optimum and we do not want to find it. It is counter - intuitive.


A sample code of this using the mql4 language (the language is based on C) is like this:


double weight1()
{
double w, j;

w=(r*x*(1-x));
for(j=0;j<=limitmap;j++)
{
w=(r*w*(1-w));
}
return (w);
}

double weight2()
{
double z, i;

z=(r1*x1*(1-x1));
for(i=0;i<=limitmap1;i++)
{
z=(r1*z*(1-z));
}
return (z);
}


double perceptron()
 {
//---
   {
 
   double p1 = iCustom(NULL,0,"PFE",x5,true,5,0,0);// those are inputs
   double p2 = iCustom(NULL,0,"PFE",x6,true,5,0,0);
   double p3 = iCustom(NULL,0,"PFE",x7,true,5,0,0);
   double p4 = iCustom(NULL,0,"PFE",x8,true,5,0,0);
  }

  return(weight1()* p1 + weight1()* p2 + weight2()*p3 + weight2()* p4);
  }


16.01.2013 г.

Why all those complex Artificial intelligence models fail predicting the markets?

The point as I see it is that predicting the markets using any AI brute force (force method in the sense of relying on the abilities of the algorithm by itself) is a dicey business.

The markets are terribly complex they constantly are looking for balance and falling out of balance. The markets are so terribly complex that you may wander if the complex learning paradigms can beat the buy and hold on one hand and the simple linear regression on the other. Most of the time they can't pass the Monte Carlo simulations.

If that was not the case every AI specialist would find easily his way to riches. The problem is not in the AI methods they work fine on normal problems. The slight nuance is that you are asking them to do impossible things. As they can't let you without an answer they will give you an answer to the question as it is in the book Hitchiker guide to the galaxy. They asked a very complex computer what is the purpous of life and the answer was 42.


So the direct and brute force approach of successful and sound and proven AI do not work consistently enough.

So what can be done. From one hand those guys are hired by the HF quantshops where an edge is found in the speed of execution. Then the edge needs deep infrastructure understanding and market structure understanding that are completely different fields of knowledge. Only by combining this meta knowledge those quant shops succeed.

Other possible way is to look towards econometrics and deep market knowledge. Then you may be able to find a good definition of the problem and apply correctly the model. The economist need to define the problem the AI specialist has to apply correctly the model.

Those are two main models I know that lead to an edge. There may be other ways in order to beat the markets but they are fringe like entropy analysis, market states clustering and chaos theory etc.

So then why people do stay?

One possible answer is that beyond profitability the quest is very interesting per se, you learn new things, it is an excellent "game" for smart people. Eventually you find good on-line friends to work together on projects thinking that the grail is right next on the corner. Everything will be fine unless you allow yourself to make a gross loss.

Start small start smart. Take it easy.

14.01.2013 г.

Weekly EUR/USD analysis 14-18

The EUR/USD is now at the same levels that it was in april 2011. That makes a 9 month high. The last week the Euro was up by 2 %.

After the European conference Mr. Mario Draghi made a statement that he sees signs of euro zone economic stabilization, after those statements the volatility rized sharply and the EUR/USD rised with more than 170 pips. There have been also some postive bond auctions in Spain and Italy.

A daily close above 1.3310 confirmed the current medium uptrend. From technical analysis perpsective we see clearly a bullish bias if the Euro is able to sustain momentum.

Even if we have a clear bullish bias we do not recommend deep stops at this moment much below 1.333 for short term traders. As everything depends on the momentum I waited the beginning of the London session in order to publish this weekly analysis.


Despite the fact that the technical analysis is the domain of what you see and not about what you think I advise extreme caution right now. I think that a short term correction is due from those levels and that the market can't sustain momentum easily. I see a possible correction towards 1.30. From that perspective for medium term traders I can recommend either a very short stop just below 1.320 betting for increase of momentum or a deeper stop below 1.30.

Main Weekly Resistence 1.35

Main Weekly Support 1.322, 1.30


5.01.2013 г.

Eureka: genetic programming software

http://creativemachines.cornell.edu/eureqa

Eureqa (pronounced "eureka") is a software tool for detecting equations and hidden mathematical relationships in your data. Its goal is to identify the simplest mathematical formulas which could describe the underlying mechanisms that produced the data. Eureqa is free to download and use.

This software essentially does the same job as the commercial chaos hunter application however the commercial application also transfers the generated mathematical formulas to the trading plateforms.

Here you need to figure out how to do that on your own.

Anyway the simplest thing that can be done is to model the current trend for example.

Here I would suggest for reading two interesting articles:

What will cause the Singularity? : this is very interesting article it appears that Eureka is an oustanding genetic programming software: “That’s a pretty big deal in the world of evolutionary algorithms”

Product review of Chaos hunter from traders.com : this a basic article about the practical use of the genetic programming software in trading strategies: two methods the definition of a treshold or boolean strategy.

Let me summarize in a simple way the neural nets can do the same job as the genetic programming. However the Neural nets will store their solution as a data set of weights that has no meaning for a human. The genetic software forces that the solution is described by mathematical formulas that a human can understand. And that is why so much hype is there in the scientific community.

This is genetic programming, the algorithm evolve basic equations in order to achieve the best fit. As a result we have equations that we can understand and not weights.


In that way you can understand the results. For example if you do the same thing with a neural net you will get weights and if you run the model you will get predictions but you will never know the idea behind even if basically the prediction is the current close ;).


2.01.2013 г.

Weekly EUR/USD analysis 02.01.2013

EUR/USD is currently in a tight consolidation area between 1.3155 and 1.3310. The 1.3155 level is the support, and the 1.33 level is the resistance.

We can expect for the next week a heavy fundamental flow to force an increase of volatility in the pair as the Fiscal cliff deal is heading to House after Senate vote.

A daily close above 1.3310 would confirm the current medium uptrend. The pair is very likely to test the short term resistence level at 1.33. Any downards movement is expected to be capped at the level 1.3.

A daily close below 1.3 would negate the current upward momentum in the EURUSD.

Long term outlook: flat market with complex consolidation patterns

Medium term outlook: unconfirmed up trend with support levels 1.30 and 1.27

Short term outlook: up trend: support: 1.31 resistence: 1.3355

Asirikuy’s First MT4 Genetic Programming Implementation

The search come to me because of a link share in linkedin with a link of advanced trading software developpers arguing the use of genetic programming. This is the original link from linkedin.

The bookmark link here is interesting. It is about using genetic programming instead of genetic optimization in building trading strategies.

So what is it about? Let start start with Wikipedia:

"In artificial intelligence, genetic programming (GP) is an evolutionary algorithm-based methodology inspired by biological evolution to find computer programs that perform a user-defined task. It is a specialization of genetic algorithms (GA) where each individual is a computer program. It is a machine learning technique used to optimize a population of computer programs according to a fitness landscape determined by a program's ability to perform a given computational task."

So the question arise who did that in metatrader. So there are some answers.

There is a commercial software: the genetic builder software. This page on their site is very interesting explaining how this stuff works. The site is very informative and you have a clear idea what you are paying for.

And there is asirikuys' implementation. I hope I could see that but the service is available under a paid subscription.


30.12.2012 г.

Frame doubling interpolation for 1080p x264 mkv's for superfluid 48 fps


Guys I have found something interesting. This will transform your watching experience thanks to the interpolation you can watch 48 fps instead of 24 frames per second.

"It is great for scenes where the camera pans over the scenery at a constant speed. Fast action scenes tend to be more clear as well. The whole movie gets a very realistic feel to it. It's just awesome. Actually IMAX HD is at 48 fps as well. Beware though, it is not easy to get this working. But once you got it, you never want to go back to 24!"

A friend of mine showed me, it is really amazing stuff.

This forum page is important showing how to change the script regarding the number of cores. If you had at least a quad core you should not have a problem, but even on my modest two core laptop with Intel 2.2 Ghz I get it running.

with: SetMTMode(1,2)

No really it is hard but if you get it running you will transform your film watching experience.

28.12.2012 г.

Optimization of trading strategy: is there something wrong Part 2


Is there something wrong with optimizing trading strategies. I think the whole conception of optimizing may be a wrong paradigm. In fact during optimization we make in the same time the strategies very vulnerable to randomness.


That is the whole point. All trading strategies are very  vulnerable to randomness but the problem is that y we do not know to what extent they are vulnerable.

That is why the use of any fancy digital filters or enigmatic time series preprocessing methods: SSA, wavelets, PCA does not add much.

On the other hand the use of different optimization algorithms does not add much too: back propagation, genetic algorithms, particle swarm optimization etc.

So what is the reaction of the big guys. They were investing in infrastructure in order to use the infrastructure edge together with complex data mining methods. And that worked and works. However as many others will do the same the competition will increase in the low latency market. Even more some countries are planning to tax the HFT, in France this is already a reality.Big boys are also using traditional macro strategies but this is another beer.

My point here is that a successful trading strategy needs to balance two pillars:

a. An adequate optimization regarding the market conditions. In practice that means that the strategy needs to learn from the market conditions and not to over - fit the past market conditions. This is a hard stuff.

b. The randomness robust trading strategy. There is a need to secure that the trading strategy is robust regarding the randomness of the market.

There are different ways to achieve it.

- To measure the state of predictability of the market and trade only when the market is sufficiently predictable. This is the core concept of the Spinal Implant EA. In this EA the algorithm takes a trade only if the fractal dimension is below a certain value.

-To apply walk forward testing.
This is a traditional approach and maybe is the state of the art in the trading community. But unfortunately quite a few algorithms pass this test, only to prove later that they are not so good.

-To apply Monte Carlo methods
So I really think that this should be implemented by everybody that seeks consistent results.

The Discussion will be here: only for logged users, sign up for free.


19.12.2012 г.

Kathy's trade and comments


Here I will post a Kathy Lien video about the current situation on 19.12.2012.

She has a long position targeting the break-out (I was talking too about a break-out).

From a fundamental perspective she makes some comments about fiscal cliff and an optimism about Euro crisis and after all she has a long bias.

Anyway, this was the first thread in beathespread, and we somewhat forgot this thread. Now I am reading the posts most of them discretionary analysis. And hey I was right most of the time about big moves coming and Euro going to hell again.

Mostly I was surprised LOL.

Here I want to make a comment  and a warning about the current situation.

What Katy does is classical analysis. The classical analysis has two parts.

a. Short Fundamental analysis

Fundamental analysis of the main driving forces and deriving a bias long or short based on the expert and discretionary knowledge.

Here in this case Katy does so and she has a long bias. From what Jaguar is talking there are others who have the same bias. But I really do not have an opinion on it because I am not a fundamental analysis specialist.

b. Technical analysis

She makes a technical analysis and we are clearly in a break-out situation that is so obvious. And last but not least the technical analysis is giving the risk control for placing the exit stops.


My comment is that that is the traditional way to do things. You can add also some more exotic ways of technical analysis as the Elliott waves for example. Here is a screen shot of an Elliott wave analysis with simplified counting (the simplified counting is used in order that everybody could get the reading and not the specialists alone).



So the Elliott waves picture is that we are in a global complex triangulat pattern in EUR/USD that is really hard to predict on the long term but do have some local predictability.

My additional comments

c. Elliott waves (simplified counting)

Here is the chart and of course regarding the position entry it mirrors the normal technical analysis regarding the break-out opportunities.





However in beathespread some more methods ans approaches have been proposed.

The method we propose is that we identify the market conditions locally.

As for the current situation we can just observe and measure the local market conditions. Thr trchnical analysis may be just smoke and mirrors as we jave observed so much sharp V-turns.

So what can be done is to use an EA model that is adpated locally to this market conditions. So if the break - out continues the EA model will follow it. If there is a sharp tern the EA would reverse just in time and follow the reversal.

I think this is what professionals do, I am simply explaining in plain English.

Have a nice day.


18.12.2012 г.

Optimization of trading strategy: is there something wrong

What is a central question of all trading strategies is the optimization. However is there something wrong with the optimization or at least with our perception of optimization of trading strategies.
I think there is something elusive here.

I think that the main problem is that we look at the market as a problem.
Yes, I think so, we think that the market is a problem and if there is a problem we look for a solution. Applying mathematical models for searching a solution is just the right thing to do.
But what if, there is something wrong in our paradigm?

Of course the trading rule with the highest observed performance is likely to perform in the future provided we have sufficient observations and we do properly performance statistics.

However the problem is that the best rules are highly positively biased. Aronson writes in his book the Objective Technical analysis that technical analysis methods "have the potential to be valid knowledge but only if back-tested results are considered in light if randomness (sampling variability) and data-mining bias.

This screen shot is from the book of Aronson Evidence based technical analysis. Here you can see out-of-sample performance deterioration, that means that the rule which performed well in the past did not perform in out-of-sample trading.

Here in the first part is the in-sample data: the data used for data mining or simply put rule back-testing. In this period you see 50 % Return on on investment. However the out of sample is a different thing. The out-of-sample actually means that the data is not used for data mining and is the actual performance.


The reality is more complex as we may assume. There is not only a problem that needs a solution to be found but there is something else too. That explains why the data - mining normally fails in out of sample trading. I will stop here for the moment.