Once again, arbitrage, pair trading. - page 2

 
Maxim Dmitrievsky:

The first thing to do is to find the coefficients of the linear relationship between the instruments and calculate the spread, for example, I sketched it out like this:

We got the spread between eurusd and usdchf:


Next, we need to do some kind of residuals stationarity test, and in case the residuals are stationary then we can already proceed with the trading logic and open trades.

The issue should be analyzed, if someone is not too lazy to do so... in order to come to a common understanding and general notation. I'm just lazy and bored of doing it :)

Maxim, cool, here we go.

I would build two spreads, i.e. between the major and the corresponding cross for hedging reliability.

I.e. spread(usdchf<->eurchf) and spread(eurchf<->eurusd).

Can you fix the code?

We will get two charts and then we will use this spread:

spread(spread(usdchf<->eurchf) and spread(eurchf<->eurusd))

i.e. between two synthetics

This is a reliable spread in my opinion. The drawdown is almost certainly excluded

We'll be left with one final spread chart.

What do you think?
 
Renat Akhtyamov:

Maxim, cool, here we go.

I would build two spreads, i.e. between the major and the corresponding cross for hedging reliability.

I.e. spread(usdchf<->eurchf) and spread(usdchf<->eurusd).

Can you modify the code?

We will get two charts and then we will build the spread:

spread(spread(usdchf<->eurchf) + spread(usdchf<->eurusd))

i.e. between two synthetics

I think this spread will be reliable. The drawdown will surely be excluded.

What do you think?

Yes, I want to add any number of symbols and build spreads for them. I may do it later. For now I've added Dickey-Fuller stationarity test from here https://www.mql5.com/ru/code/13072

Not sure why it keeps returning true, need to look into it. Mb who understands statistics will help me.

In the terminal log in the tester shows the result of the test... and in the visualizer you can see how spreads are changing

You can add any number of symbols separated by commas to SymbolsList and it will build a synthetic symbol for the current symbol. It's only necessary to calculate the spreads for each symbol from the list, and you'll get the full picture.

Statistical Functions
Statistical Functions
  • votes: 32
  • 2015.07.03
  • Haruna Nakamura
  • www.mql5.com
Набор статистических функций, которые позволяют рассчитывать некоторые значения, описывающие таймсерии, такие как корреляция между двумя таймсериями, линейная регрессия, стандартное отклонение и т.д. Набор также включает в себя более сложные функции, такие как определенный интеграл. Заголовочный файл "Statistics.mqh" содержит следующие функции...
 
Maxim Dmitrievsky:

Yes, I want to make it possible to add any number of symbols and build spreads for them, maybe later... for now I added Dickey-Fuller stationarity test from here https://www.mql5.com/ru/code/13072

Not sure why it keeps returning true, need to look into it. Mb who understands statistics will help me.

In the terminal log in the tester shows the result of the test... and in the visualizer you can see how spreads are changing

You can add any number of symbols separated by commas to SymbolsList and it will build a synthetic symbol for the current symbol. It's enough to calculate the spreads for each symbol from the list and get the whole picture

Pretty cool. I should use it.

I have modified my post. If you continue coding, please pay attention to the changes.

 
Renat Akhtyamov:

That's pretty cool. I'll have to use it.

I have fine-tuned my post. If you continue coding, please pay attention to the changes.


Yes, I need to add an option to plot any number of spreads on the 1st chart and normalise them into a range for clarity... I will do it in the evening

i.e. i can open trades by hand based on divergences and then add an algomodul

 
Maxim Dmitrievsky:

Yes, we need to add an option to plot any number of spreads on the 1st chart and normalise them into a range for clarity... I will do it in the evening

i.e. i may open deals by hand based on divergences and then use an algomodul

i.e. i may open trades by hand based on divergence and then an algomodulus may be added.

I've shown you the picture. You may have seen what happened to the pound.

The only salvation was to pay attention to the pound cross

That's why I suggest an arbitrage scheme using crosses,

I.e. in addition it is necessary to impose a cross on each major, proportional to the price of the major most likely

and of course to test that night when the pound fell over 1000 pips.

The price of the pound and not of euro should be chosen accordingly, and the chiff may be left.

 
Renat Akhtyamov:

between the majors alone is a lost cause.

I showed you the picture, you must have seen what happened to the pound.

The only salvation was to pay attention to the pound cross

that's why I offer an arbitrage scheme using crosses


so it makes no difference, you can even between stocks and indices, anything you want... it's kind of a testing space )

I think it's better to make a cointegrated portfolio, in which weights of each individual instrument will be insignificant, and deductibles of any one instrument will not be so critical.

in short, we just need a universal blanket for any tests

 
Maxim Dmitrievsky:

it makes no difference, you can do anything between equities and indices... it's kind of a testing space )

I think it would be better to make a cointegrated portfolio where weights of each individual instrument would be insignificant, then spikes of one instrument would not be so critical.

I think it would be better to make a co-integrated portfolio where the weights of each individual instrument would be negligible.

 
Renat Akhtyamov:

i can't use an ordinary ratchet or pairwise trading - my deposit will go down the drain


If you want to trade in this way, you have to use some other tests/statistics.

i.e. it's a market neutral strategy. it should always be a hedge. in short, Fuller almost always detects a spread chart as stationary, with few exceptions, so it's not very useful.

i've never done pair trading before, i don't know what they use... how to correctly assess spread chart

I'll do it with R^2 for now... so the bot can somehow estimate dispersion and not trade sloppy spreads

 
Renat Akhtyamov:

Maxim, cool, here we go.

I would build two spreads, i.e. between the major and the corresponding cross for hedging reliability.

I.e. spread(usdchf<->eurchf) and spread(eurchf<->eurusd).

Can you modify the code?

We will get two charts and then we will build the spread:

spread(spread(usdchf<->eurchf) and spread(eurchf<->eurusd))

i.e. between the two synthetics

This is a reliable spread in my opinion. The drawdown has been surely excluded

There will be one final spread chart

What do you think?

carefully read - it's a regular triangle, spreads add up to 0... triangular arbitrage doesn't work

the drawdown and trades will be for sure excluded, there will be none :D have already written many times about it

i deleted the sources, since no one will understand anything with this level of "awareness", i'll just do it for myself and i'll invite to a closed project :)

 
Maxim Dmitrievsky:

I've read it carefully - it's a regular triangle, spreads add up to 0... triangular arbitrage does not work

we will surely exclude drawdowns and trades too, they simply will not happen :D have already written many times on this subject

ok!

and pair trading here:

i.e. it doesn't and can't be!