GammaRat Forex                                          

Forex Analysis

 

WARNING– Perhaps you are here accidentally & would rather be looking at NAKED BODIES and OTHER FEASTS FOR THE EYE ? Click on the link to escape to something prettier…..

NOTE, all data and commentary on this site is generated for my own use; you can do with it what you want – and I do appreciate feed back on it – but don’t treat any of it as either accurate, or (worse) as a trade recommendation. I am a mathematician and artist – NOT a professional trader or consultant; I do this partly to guide my own trades, and partly because I am taken with the intellectual challenge, but NEVER to guide anyone else’s trades.

 

 

1.             Background

 

Recently I have become fascinated by the use of the Kalman filter as a tool in financial analysis, both as a method of classification, and as a tool in trading for profit. I do my work primarily in foreign exchange (Forex); there is no reason why the same (with appropriate tuning) couldn’t be used on the market of any other financial instrument. However I find the open, relatively unregulated, and high variance nature of Forex more to my liking.

Anyone is free to use the programs and analysis referred to on these pages for their own use, although proper credit would be greatly appreciated. Otherwise, as they say, my karma will run over your dogma.

The reason I am making this work public is to make certain that the ideas remain in the public domain. It is unbelievable what idiots with money combined with lawyers will try to restrict via copyright and patent lawsuits. This application, while by no means a “killer app”, shows a good deal of promise as a supplement to the average retail trader’s toolbox, and I am happy enough to keep it that way. I also like hearing back from those who use it – bugs, errors, possible improvements. Just let me know ( brobeck@ns.sympatico.ca ).

And of course if you just want to send me money so I can carry on this work, I won’t say no. If you want consulting on the application, the implementation of it, or the mathematics, let me know -  though my charge out rate goes pretty high if I have to leave the idylls of Nova Scotia, or if I think you can afford it. On the other hand, I do not provide financial or trading advice or recommendations of any sort.

 

2.             Software

 

All software is located in this repository; notification of changes and additions will be placed on the Global-View International Foreign Exchange forum. This is not commercial software – I use it mostly for my own analysis – so there are no guarantees of quality or consistency. Most of the software is written in the MetaQuotes software language MQL4, and designed to run on MetaQuote terminals.  See http://www.metaquotes.net .

To obtain the software and whatever documentation I have gotten around to writing, see http://www.gammarat.com/Forex/BlackBoxes .

The most up-to-date version is the GRFKalmanAG (Kalman filter with auto-gain). This is simpler to use for most people than the older versions, as the gain of the filter is adjusted automatically (in small increments) according to what the user thinks of as the natural coherency (the time it takes for a big jump to die out, or the natural scale of a trend, etc.) time of a trend. For example, on most pairs, coherency seems to last somewhere between a day or two and a week (or two) on the hourlies; while on the minutes coherency lasts perhaps an hour, or less. The AG is set by the user to represent this number (for example, 24 periods on the hourlies represent one whole day; 120 periods on the hourlies represents 5 days – 1 working week – of trading.). Over a period of that time frame, the filter will try and balance the variation on either side of the of the trend line.

3.             The Kalman Filter

 

Wikipedia has a good basic introduction to the Kalman filter,: see  http://www.wikipedia.org/Kalman_filter.  The math behind the filter is a little complicated (though it should be accessible to anyone with perhaps two years of university science level math and statistics); for those who aren’t interested in that aspect, here’s a simple overview.

Moving averages of various sorts, and tools (like MACD) built from them, are essential in technical trading. The Kalman filter is conceptually similar to the moving average, except that it is designed to “optimally” (n a math sense) adjust itself to the way the data is changing. The filter (and others like it) are the workhorse of automatic control devices, such as autopilots or the little black box that keeps your FM radio from drifting.

The version I am currently using is very simple. There are two data that I look at at each chart update – the current price, and the change in price from the last price. As a side note the ideal situation would be to work with tick data, for most trading environments this isn’t feasible, and (computationally) for anything over a minute period is pretty much overkill. So the code is written to work with time stepped data on regular periods.

Given this arrangement, we consider the current price, and the change in price, in a manner similar to position and speed of a moving target. If we knew these exactly, and assuming there was no acceleration present to change the speed, it would be very easy to estimate what the next position would be.

However there are errors in our estimate of position, bigger ones in our estimate of velocity, and increasingly unpredictable ones in additional moments, like acceleration. In writing this version of the Kalman filter, I have assumed that consistent acceleration (and further moments) doesn’t occur over long periods – this is, it tends to be brief, and unpredictable. This leads to a model that involves fitting a straight line over brief periods, and estimating other effects as noise.

4.              Active Areas

There are a number of active areas of my work at the moment

4.1.         Basic Software

The software for this work, and the analysis behind it, are at very early stages in their development. (The actual theory is quite mature.). There are various taks that need to be done, first of which is translating the implementation from an indicator, to a callable function. Skipping for now what that entails, the idea is that like any other averaging type of tool, the KF could easily be incorporated into standard tools, like MACD, and provide a quicker and more robust response.

In the longer run, I hope to get the software implemented as C, or C++, code, which will be useable as a DLL. This is especially important with respect to the matrix libraries, which are currently very primitive.

4.2.         Development of the AutoGain

The autoGain appears to be a critical element of making thie KF work, at least easily. An auto-gain is simply a manner of letting the filter adapt quickly to a changing environment, driven by the observation that currency pairs react differently in different environments. Currently the gain is set by hand, which means too much hand tooling for the average investor…

4.3.         Classification of Currency Pair Behavior

Observation leads us to believe that the behaviour of different pairs over different time frames can be classified according to the AG necessary to track the pair, nad the local history of the Mahalanobis distance (or deviation from the trend in both price and velocity). This is most strongly defined when comparing most USD pairs with USD/JPY; while the former tends to move with an AG near 0 on the hourlies, the USDJPY needs much more noise suppression. It’s a curious effect that extends across a number of time frames.

Further, the MD appears to be a good pre-indicator of near term high-sigma deviation.. This needs to be classified and expanded. For now, see the next section.

 

4.4.         Front Running, Stop Hunting, and Scalping

 

While (as a client) one can probably never clearly determine why someone would be so foolish as to put a large volume of money through at a time when the liquidity of the market is so low that the trade would be unfavorable to themselves, one can suppose. The easy answer is that the actual client is not concerned about the relatively small amounts gained or lost in such a transaction due to the exchange rate variation, which in turn allows the trader placing the trade to do so advantageously to himself, by “front-running” the trade. For example, if the trader is to put through a large buy order on EUR/USD (ideally at his leisure), then during a highly liquid period, he would buy the pair himself, and when liquidity drops (as it does at certain times of the day), he would put through the client’s order. The combination of low liquidity and the large client order drives up the value of the pair; and when the large order is finished, the trader closes his own orders at a good profit.

Other methods that depend on the informational bias – such as stop hunting – can also be used by large traders to their own profit. Very common times for these moves seem to be lunch hour – especially on Thursdays - in New York (for most pairs), and around 15:00 GMT for EUR/JPY, on Fridays.

The small trader does not have access to the information, and so generally cannot profit directly from it (and some get hurt significantly from it by not paying attention to the nature of the market). However that informational bias is an integral part of the Forex market; those who really don’t like it should go trade stocks, rather than asking for more rules and regulations.

Politics aside, the question remains, how can one profit from such moves? This comes down to what is known as “scalping”. In any such sharp move based on informational bias, the underlying driving force – such as the large volume of currency getting put through, or the stops themselves – eventually get exhausted. At this time the market will tend to first overshoot its value, and then drift to a natural price.

Currently we are using the Kalman filter to identify and classify the behavior of such moves. (insert recent EUR/JPYchart…)

4.5.         Finish and put to bed the Least Squares Estimator

The Least Squares Estimator is a tool similar to the Kalman filter – less responsive (for good and bad), but still quite useful. It works by continually using fixed length least squares regression to determine the trajectory and velocity of a trend. This software has been around for awhile, but not in a cleaned up form. Once it is, I’ll put it on-site (although a number of correspondents already have the code.)

4.6.         To be continued…