Updated statistical arbitrage results

+173 USD right now, results had been mixed. i have that feeling that to long trades are most of the times lossers. i can probably implement a new exit after some bars has passed, maybe after 250 (half of bars used to calculate mean). as this is just a feeling i don’t have any math prove, for now statistical arbitrage experts advisors will continue russing as usual.

Updated 2011/01/12 Statement

Tags: , , , ,

Forex quant end of the week

After the 100 usd made on tuesday the markets deviated again 3 std devs so more trades were open. We had an audusd-nzdusd open from tuesday, this trade was closed at the mean yesterday with losses, the australian side ended at -23 while the new zealand at -6 usd.

Euro and Cable against the dollar and against the yen were also opened, the yen trades ended at the mean earning 6 usd and the dollar trades earned 21 usd. counting the 3 pairs i  ended up losing 2 bucks.

Even if smaller, the euro and the sterling still made earnings against the dollar and the yen; but aussie and kiwi made losses even if the mean reversion was given. This behavior is something to study mathematically; after long time inside the trade not even a mean reversion can drop profits because the mean moved so much that have nothing to do with the mean we had when we get inside the trade. The mean is dynamic, it moves as the markets advance and deserves a quant study even if i don’t know how to make it yet.

Statement

Tags: , , , , , , ,

Statistical Arbitrage more Calibration

Calibration means to make changes in the models to make it fit the markets. What i saw in the trades from the beginning of last week, more precisely in the losser ones is that the 3 std dev stop loss gets touched with ease. So i removed the stop loss and moved it to 4 and -4 standard deviations. So trades start when 2 std is reached and we get out at the mean or at 4 std deviations.

This strategy worked pretty good in the last 2 days of the week, even if the expert code is not perfect yet, i had to close one leg of the trade manually at a given time, not sure why yet. The important thing is that the strategy is dropping positive results.

I also closed 2 trades manually on friday after the US market close as they were winner trades and i knew the mean was not going to be reached before the weekend.

Statement

130 usd made in 2 days of trading with this strategy, not bad at all.

For the week starting i am going to make another change, i am going to m0ve the entry to 3 and -3 std devs instead of 2. i think it is a better bet, the chances of reverting back to the mean are bigger but we will get a lot less signals for sure. I will study how much signals i can get in the week starting, probably i will move the entry back to 2 and -2 if no signals are given on Wednesday. Tuesday and Wednesday are the most active days in the forex market, if i expect a 3 or -3 deviation from the mean it can happen at those days.

Tags: , , , ,

Programming + design errors in strategy

Programming or strategy design errors can lead to big losses of our accounts specially if you trade with expert advisors. the advantage  of don’t have to look at the market all the time can became a real tragedy if there are errors. There are obvious errors, an expert advisor with syntax errors will not even let you compile the program, this kind of errors aren’t dangerous as they are found even before the expert can start running in an account.

Another kind of error is a silent error, this errors are viewed for example at only certain conditions, this conditions are only met from time to time. This is the case of  errors on my statistical arbitrage experts advisors found last week.

Statement Dec 7

There are a lot of trades opened and closed immediately, why this was happening ? The answer is a logic error in the design of the program. Trades are open when the differential is passing the 2 or -2 std devs. When the differential touch the 3 or -3 std devs a stop loss is triggered but the differential is still greater than 2 or smaller than -2 which makes a new order open.
The program gets trapped on a loop and it is only going to stop doing that when the differential gets smaller than 3 standard deviations.

To fix this situation i added an additional pice of code to block any trade to open at 3(or greater) and -3(or smaller) standard deviations.

But this don’t fix it all, sometimes the differential oscillates between the -3 and 3 std levels, going up and down, breaking the line one side to the other several times.
To avoid this i created the following strategy:
- get the history of orders.
- search the last trade with symbol base or hedge.
- get close time.
- get current time.
If the current time is greater than the history closed trade + 1 hour then i allow a new trade to open. This will block a lot of the trades done between that mean, it is probably not the best solution but it is something.

With this i can conclude that running expert advisors in demo accounts are not only good to get an estimate of trade results but it is also a way to find errors with no real harm.

The 3 statistical arbitrage experts are now running again on a new opened account, lets see how they do this week.

Tags: , , , , , ,

Additional statistical arbitrage expert advisors

To have more and quicker signals i have now 2 additional expert advisors using statistical arbitrage strategy running at the same time.

EA1: trading gbpusd-eurusd
EA2: trading gbpjpy-eurjpy
EA3:trading audusd-nzdusd

Statistical arbitrage Expert advisor 2 and 3 are the new ones, EA 1 was already trading.

Stat arb EA2 – the yen trade:

Stat arb EA 3 – asia pacific trade:

Tags: , , , , , , , , ,

First Statistical Arbitrage Trade using mql

Now that i have the basics (much more than i posted in the blog) i can start to test this on more real life examples. so using my mql skills i made an expert advisor to calculate mean and standard deviations and send me trade signals. For testing purposes i will make the first trade manually, then i will let the expert make all the work.

First signal, differential is at -2 std deviations so we get in expecting to earn profits at mean reversing. It is friday, we will have to probably leave the trade open during the weekend.As we are at -2 and GBP goes first in our calculations, it is our base symbol, so we buy GBP.

Market traded all day between -2 and -3 std deviations:

The day pass and the session ends for the week.

On monday the mean reversed happened early, check the numbers on the left top panel, the differential is now trading between the mean and positive 1 standard deviation.

As expected the mean reversion dropped a profit, the amount wasn’t calculated yet, i don’t even think it will be possible to estimate it as this is a very dynamic situation, the only advantage i have is that at 2 std deviation there is a big chance that the prices will start to head to the mean again.

Meta trader trade statement

Tags: , , , , , , ,

Data Sources and Excel

To make statistical calculations we need to get some data. For the 5 minutes timeframe i will use data exported from the history center of the meta trader.

I will use the last 3 months of data for each pair,  here is a piece of data for the gbpusd pair:

2010.11.18 20:20 1.60325 1.6034 1.60286 1.60328 212
2010.11.18 20:25 1.6033 1.60367 1.60305 1.6033 206
2010.11.18 20:30 1.60326 1.60362 1.60325 1.60341 213
2010.11.18 20:35 1.60344 1.60348 1.60316 1.60345 197
2010.11.18 20:40 1.60344 1.60387 1.60344 1.60387 205
2010.11.18 20:45 1.6039 1.60467 1.60364 1.60453 189
2010.11.18 20:50 1.60453 1.60465 1.60413 1.60462 237
2010.11.18 20:55 1.60468 1.60482 1.60382 1.60434 285
2010.11.18 21:00 1.60438 1.6047 1.60435 1.6047 153
2010.11.18 21:05 1.60469 1.60491 1.60403 1.60426 221
2010.11.18 21:10 1.60424 1.60425 1.60387 1.60394 129

And here the same period for the euro usd:

2010.11.18 20:20 1.36205 1.36206 1.36139 1.36163 175
2010.11.18 20:25 1.36165 1.36222 1.36146 1.36211 109
2010.11.18 20:30 1.36211 1.36281 1.36211 1.36272 128
2010.11.18 20:35 1.36277 1.36335 1.36272 1.36315 168
2010.11.18 20:40 1.36315 1.36341 1.36294 1.36341 120
2010.11.18 20:45 1.36335 1.36405 1.36321 1.36371 196
2010.11.18 20:50 1.36367 1.36382 1.36316 1.36345 193
2010.11.18 20:55 1.36349 1.36354 1.3629 1.36335 197
2010.11.18 21:00 1.36341 1.36352 1.3631 1.36335 158
2010.11.18 21:05 1.36335 1.36404 1.36335 1.3635 132
2010.11.18 21:10 1.36349 1.3635 1.36334 1.36336 53

I am interested in the date, the time and the closing price for each candle which is the 6th column(F in excel).

So exporting the last 3 months will end in 2 csv files with aprox 15000 lines. One big problem i faced is that sometimes one of the sources haves missing data, so i had to make the tedious task of fix the errors, witch they are a lot for some pairs. Helping me with excel i was able to make this task a little quicker.

Excel will be my main tool as statistician, we will get out at least for now from the mql programming language field and use excel built in statistical functions to make our lifes easier.

Tags: , , , ,

Neutral Hedge end of the week

For the end of the week only 1 more trade was opened, again the expert advisor opened only one side of the hedge, buying gbpjpy when the normalized deviation indicator was at -100:

The trade ended here with $30.31 of profits:

$115 since the test started, in 3 trades, all winners, not bad: Statment

The errors to fix are clear after this week of test:

- try to make sure both sides of the trade opens, the code right now says if one side is open do nothing, this haves to change to if one side is open open the other. if both sides are open do nothing.

- automatic date change in the indicator, it can’t be done by hand and the expert can’t stop working.

- check stop loss and profits targets, check if they get executed correctly.

Tags: , , , , , ,

First Neutral Hedge Conclusions

Finally the test for the neutral hedge strategy in the linux machine started this sunday (october 3th) with the asia session opening, the expert advisor using forex.com as broker is currently running since then trading eur-jpy and gbp-jpy.

Only 2 times since the test started the criteria to open trades was met, it sound as to little but it is enough for taking some conclusions.

The first trade was made on monday:

The oscilator pass the -100 limit and a hedge trade should be open, unfortunatly the expert advisor some times fails on opening the 2 trades and open just one, in this case only GBP-JPY was opened in the long side. It is expected to this pair to go up sooner or later, this is what happened and the trade was closed with 30 pips of profits.

At that point the trade was closed with a profit of  $30.01. As a first fix i will have to change the expert to make sure that both trades are open and not just one.

A second trade was opened by the expert, this time both trades were open, long gbp, short euro:

See how it looks like the oscilator touched the -100 before and no trade was opened, this is because meta trader zooms in or out the screen as the market advances depending on the volatility of the market. I didnt saw this trade in real time but i think that the oscilator never really touched that -100 while running and that is why no trade was opened.

It was a wild movment after the entry as we can see in the image of the close of the trade:

On this trade the gbp made $34.63 and the euro made $20.31. I am suspecting that the expert code exit the trade when one  pair is at 30 and not when the overall profit is 30. The movemt looks very wild in the charts, this can be another explanation for this, i will see what happens in future trades. The bank of japan made statments this week, they cutted interest rates to virtually 0, maybe this was at the time of that announcement.

Another thing is that the oscillator needs a starting date to work, i am working with about 10 days in the past but i am updating the date manually as time pass. this is because the oscillator stop working when the starting date is to far away in time. As a modification of the expert i have to make the expert update this date automatically to feed the oscillator.

Here is the statement of this 2 trades:  statement

Finally, i got an email today from forex.com, i contacted them and they told me i will need around 280 USD on the account just to be able to open a mini lot of euro-usd … for a hedge trade probably double of that should be in the account just to open the trade. That is just the minimum, i think i will need at least 1000 usd now to trade this strategy instead of the just 250 needed before.
This situation will make me search for investors when the moment of trading in real came, at the moment the strategy gets defined and the chances of success are high. The other option i have is to try to look for other broker.

If someone is interested on investing with me and with this strategy in the future please use this contact form.

from forex.com

We contacted you last week to inform you of an upcoming change to your FOREX.com account. Effective Monday, October 18, 2010 a new CFTC regulation will go into effect that limits the maximum leverage in the retail forex markets to 50:1.

The new margin requirement is 2% (50:1 leverage) for the major currencies and 5% for all other currencies (20:1 leverage). Metals will be offered at 100:1. View full list of currency pairs.

The new CFTC regulation is intended to protect retail investors in the US by preventing excessive use of leverage by traders who may not have an adequate understanding of the associated risks. We support their intention and have always provided customers with the ability to employ lower leverage ratios, based on their

Tags: , , , , , , , ,

Neutral hedge important test

A new important test of the final pairs trading strategy started today on a linux machine with meta trader installed. The test will consist on a neutral hedge expert advisor running from today (wed 29 of september) to friday 1st of october 24 hours a day. This way i will be able to make modifications to the expert variables and functionality if needed plus know how much real money i can make or loss using this strategy.

One radical change i am making for this test is the use of forex.com as broker instead of the default alpari. i already have a live account in forex.com and i will like to operate with them when the moment of live trading came again.

The pairs used will be gbpjpy and eurjpy, when the neutral hedge oscillator is at 100 or at -100 the hedge trade will be open. I will try to catch just 30 usd of profit while the stop loss will be -77. the expert advisor will make a screenshot of the situation when a new hedge trade opens and another one when finished whatever is with profits or with losses. This will give me a overall view of the situation of the moment when actions are taken even if i am not in front of the linux machine.

here a screenshot of that is happening in the linux machine with the expert advisor working, no trade was made at the moment of writing:

Tags: , , , ,