Trading a portfolio of currency pairs - page 9

 
MetaDriver:

They're there for the story. (Really all white, which is totally in line with the advertisement, I confirm).

They only have to be white and fluffy, because according to the von Neumann-Morgenstern theorem the MiniMax value is the price of the game, i.e. the minimum expectation. An optimally diversified portfolio must be profitable irrespective of the directions in which the prices of the selected instruments move. Correspondingly, if the portfolio allows losses at least in one historical period, its expected payoff, according to the above theorem, is negative and it is not optimally diversified.
 
C-4:

And no one in their right mind would use something just because it is open, without understanding how it works.

No one is forced to use it. The source code is open, the basic mathematical theory and algorithms are not secret. Those who are of sound mind and memory are capable of figuring out how it works on their own. The rest of us can rest.
 
kharko:

The implementation requires the enumeration of all variants. The total number of variants is 2 to the power of N, where N is the number of instruments in the portfolio. Maybe someone can help - with ready code. I would be very grateful.

Optimised for the drawdown. The line is now straighter. But in the course of my thinking, a question suddenly arose. How do you calculate the spread? After all, you need to know how many deals will be done and in what volumes! I do not consider the spread in my indicator, but I have tried to count how many points we will lose/gain on swaps. During optimization swaps are not considered.

Warning! I strongly recommend not to use a large number of currency pairs and the number of bars to be analyzed.

When optimizing by drawdown of 10 currency pairs and the parameter Lengh = 100 the indicator initializes about 5 seconds! Have patience :)

 

Example of filling the ET_para.csv file, which should be in the files folder:

Symbol Type
EURUSD1
EURGBP0
EURCHF1
EURJPY1
GBPUSD1
USDCHF0
USDJPY1
AUDUSD1
USDCAD1
NZDUSD0

The first line is used for the header and is not included in the calculations!

Files:
et_para.zip  1 kb
 
EvgeTrofi:

Optimised for the drawdown. The line is now straighter. But in the course of my thinking, a question suddenly arose. How do you calculate the spread? After all, you need to know how many deals will be done and in what volumes! I do not consider the spread in my indicator, but I have tried to count how many points we will lose/gain on swaps. During optimization swaps are not considered.

Warning! I strongly recommend not to use a large number of currency pairs and the number of bars to be analyzed.

When optimizing by drawdown of 10 currency pairs and the parameter Lengh = 100 the indicator initializes about 5 seconds! Have patience :)

Good job...

Spread and swap are not taken into account. The indicator only works with points.

If we take into account volume, spread and pip value, we get a virtual Equity curve, which directly depends on the correct values of these parameters. We need to calculate the pip value on each bar for all instruments in the portfolio in the deposit currency. In many brokerage houses the spread value varies, which will significantly distort the curve.

I am interested in your algorithm for trying all the options. I would be very grateful for your help.

 

The options matrix is formed as follows:

void Sbor(int& Ar[][]){
   //Создание массива вариантов сочитаний действий над валютными парами
   int Begin = 0;
   int Size = MathPow(V, CountSy);
   int min = 0;
   int max = 1;
   if(V==3) min = -1;
   ArrayResize(Ar, Size);
   for(int i = 0; i < Size; i++){ // Варианты (строки)
      for(int j = 0; j < CountSy; j++){ // Инструменты (столбцы)
         if(i==0){
            Ar[i][j]=0;
         }else{
            if(j==0){
               if(Ar[i-1][j]<max){
                  Ar[i][j]++;
               }else{
                  Ar[i][j]=min;
               }
            }else{
               if(Ar[i][j-1]<Ar[i-1][j-1]){
                  if(Ar[i-1][j]<max){
                     Ar[i][j]++;
                  }else{
                     Ar[i][j]=min;
                  }
               }else{
                  Ar[i][j]=Ar[i-1][j];
               }
            }
         }
      }//Next j
   }//Next i
}//Sbor()

To make it easier to understand this code, I have uploaded an Excel spreadsheet with formulas for forming such a private matrix.

Then you just have to run through all the variants by brute force :)

Files:
arvar.zip  5 kb
 
EvgeTrofi:

The options matrix is formed as follows:

To make it easier to understand this code, I have uploaded an Excel spreadsheet with formulas for forming such a private matrix.

All you need to do after that is run through all variants :)

spb

Wrote a simpler code:

void Matrica()
{
   double size = MathPow(2,Num.Para);
   int trend[];
//---
   ArrayResize(trend,Num.Para);
   for(int i=0;i<size;i++)
   {
      int x = i;
      int pos = 0;
      ArrayInitialize(trend,0);
      while(x>0)
      {
         trend[pos] = x % 2;
         pos++;
         x = MathFloor(x / 2);
      }
// Вывод варианта      
   }
}
The variant number is represented as a binary number system.


 

Added a display of drawdown and profit factor (ratio of current balance to maximum drawdown). The bigger this number is, the more stable the chart looks. Optimization is carried out by this value.

The number of seconds spent on the optimization is shown in comments. :)

 

EvgeTrofi:

Attention! I strongly recommend not to use a large number of currency pairs and the number of analyzed bars.

When optimizing the drawdown of 10 currency pairs and the parameter Lengh = 100, the indicator initializes about 5 seconds!!! Have patience :)

Thought about how to bypass the limit on the number of bars. You need to divide the time interval for optimization by a number, for example, 100. If there are 1000 bars in the interval, then we will get 1000 / 100 = 10 time points where we can perform calculations. Thus, the smaller is the number, the higher is the calculation accuracy.
 
kharko:
I have thought of a way to circumvent the limitation on the number of bars. It is necessary to divide the time frame for optimization by a number, for example, 100. If there are 1000 bars in the interval, we will get 1000 / 100 = 10 time points where we can perform calculations. Thus, the smaller is the number, the higher is the calculation accuracy.

I've been scratching my head about this too. It turns out that the fewer sections, the higher the probability of adjustment.

On the other hand, R-Portfolio uses payment matrices, among which the most informative are square ones, i.e. how many financial instruments are analyzed, so many sections should be there.

But the point is that even well correlated instruments can change correlation signs at certain moments. I.e. if you break up the fragments as you see fit, then there is a possibility that the analysis may contain just such bad moments with the changed signs.

In short, I came to a conclusion that we should not divide sections at equal intervals (with the same number of bars), but at extremums of some single instrument (for example, the one having the maximal share in the portfolio). I.e. apply ZigZag or some other algorithm, detect breakpoints of trends and by these points (on these bars only) discount quotes for further feeding to R-Portfolio (or some other portfolio analysis program). It seems to be the most kosher and most informative way. Otherwise, we get some kind of noise analysis between the points of correction changes, for example, in sideways.