2
$\begingroup$

Hi fellow mathemagicians,

let's say that I have 3 series of numerical results (they represent 'drawdowns') :

S1   S2   S3
 0    0    0
 0   -5    0
 0  -10  -10
-5    0  -15
 0   -5   -5

We can determine their correlation matrix :

          S1          S2          S3
S1            1  -0.534522484 0.771743633
S2 -0.534522484             1 0.045834925
S3  0.771743633   0.045834925           1

and then I would need some function that will "minimize the overall correlation" depending on unknown yet weightings to apply to each series.

In other words, I would like to find the best combination of weightings to apply to each series so that the sum of the 3 adjusted values for each line is 'the lowest possible over all the results'.

I would like to use an optimizer that will "minimize their overall correlation" and for that, I need an objective function which I just described. There would also be a constraint on the sum of the weightings to be equal to 1 and another constraint for achieving a minimum profit level.

So I would need help writing the objective function (in AMPL ideally) of my problem, that will minimize the overall correlation between my drawdowns series :)

Thanks in advance


Although I am am still interested in using an optimizer,

Following T.K's answer, I decided to try removing the correlation with the linear transformation he kindly pointed at on wikipedia's page :

I have my matrix X and I am able to find the matrix D. However, I am encountering a problem with the matrix square root operator...I don't know how to compute it :\

Here is what I got so far :

Removing correlation

In order to get $T$, I need to apply the matrix square root operator on the matrix presented at the bottom right of the image, which is the inverse matrix of $D^TD$.

2 Answers 2

3

For the last (and important) edit/answer see the text after the last horizontal line


I'm pretty sure, the formula for the correlation as given by Wikipedia helps you a lot: https://secure.wikimedia.org/wikipedia/en/wiki/Correlation

Especially the sample correlation coefficient. As well it might be helpful to use the linearity of the expected value: $$\mathrm{E}[\alpha X]=\alpha \mathrm{E}[X]$$ and the variance: $$\mathrm{Var}(\alpha X)=\alpha^2 \mathrm{Var}(X)$$

From these three formulas (sample correlation coefficient, expected value and variance) you should be able to derive your objective function.


Some more details (formulas mainly taken from above link):

The correlation of random variables ($corr(X,Y)$) is their covariance ($\mathrm{Cov}(X,Y)$) divided by the product of their standard deviation ($\sigma_X\sigma_Y$), which is the product of the square roots of their variances ($\mathrm{Var}(X)=\sigma_X^2$, $\mathrm{Var}(Y)=\sigma_Y^2$), thus $$\mathrm{corr}(X,Y)=\frac{\mathrm{Cov}(X,Y)}{\sqrt{\mathrm{Var}(X)}\sqrt{\mathrm{Var}(Y)}}$$

The covariance of two random variables can be rewritten in terms of the expected value: $$\mathrm{Cov}(X,Y)=\mathrm{E}[(X-\mathrm{E}[X])(Y-\mathrm{E}[Y])]=\mathrm{E}[XY]-\mathrm{E}[X]\cdot \mathrm{E}[Y]$$

Now one can introduce some weights $\alpha$ and $\beta$ to the random variables.
As the covariance is derived from the expected value, one gets the linearity $$\mathrm{Cov}(\alpha X,\beta Y)=\alpha\beta \mathrm{Cov}(X,Y)$$

With this, one gets for the correlation: $$\mathrm{corr}(\alpha X,\beta Y)=\frac{\alpha\beta \mathrm{Cov}(X,Y)}{\sqrt{\alpha^2\mathrm{Var}(X)}\sqrt{\beta^2\mathrm{Var}(Y)}}$$

Finally, you insert your random variables $S_1$, $S_2$ and $S_3$ with their weights $\alpha$, $\beta$ and $\gamma$ into this last formula and come up with three equations.


While reading some details on correlation matrices, I just discovered a way solving your problem, without using a minimiser:
Transformation of random variables (see https://secure.wikimedia.org/wikipedia/en/wiki/Pearson_product-moment_correlation_coefficient#Removing_correlation)

Applying your example to the description given by Wikipedia, $n$ is 3 ($S_1$ to $S_3$) and $m$ is 5. $X$ is the matrix you gave here at the very top.


On your problem with the matrix square root.
I've done all calculations in R as I'm not familiar with doing it in Excel. Maybe somebody else can help you out with that.

> X
      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0   -5    0
[3,]    0  -10  -10
[4,]   -5    0  -15
[5,]    0   -5   -5
> Z
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    1
[2,]    1    1    1    1    1
[3,]    1    1    1    1    1
[4,]    1    1    1    1    1
[5,]    1    1    1    1    1
> D = X - (1/5)*Z %*% X
> D
     [,1] [,2] [,3]
[1,]    1    4    6
[2,]    1   -1    6
[3,]    1   -6   -4
[4,]   -4    4   -9
[5,]    1   -1    1
> DTD = solve(t(D) %*% D)
> DTD.eig = eigen(DTD)
> DTD.sqrt = DTD.eig$vectors %*% diag(sqrt(DTD.eig$values)) %*% solve(DTD.eig$vectors)
> DTD.sqrt
           [,1]        [,2]        [,3]
[1,]  0.7479411  0.19820775 -0.18609441
[2,]  0.1982077  0.17628059 -0.05451766
[3,] -0.1860944 -0.05451766  0.12541941
> T = D %*% DTD.sqrt
> T
           [,1]        [,2]         [,3]
[1,]  0.4242056  0.57622412  0.348351376
[2,] -0.5668331 -0.30517882  0.620939695
[3,]  0.3030723 -0.64140513 -0.360666057
[4,] -0.5240837  0.40295033 -0.602467673
[5,]  0.3636389 -0.03259050 -0.006157341

Check the result: The covariance matrix of $T$ should be the identity matrix.

> cov(T)
              [,1]          [,2]          [,3]
[1,]  2.500000e-01 -7.769177e-17 -1.301994e-16
[2,] -7.769177e-17  2.500000e-01 -6.960356e-16
[3,] -1.301994e-16 -6.960356e-16  2.500000e-01

The off-diagonal elements are all almost zero (rounding error of floating-point arithmetic). The diagonal elements are $0.25$, so there must be still some error in my calculation. I'm sorry for that. Maybe somebody else finds that error?


Just another edit after having a chat with a colleague about this topic:

First a little remark I was not aware of yet:
It is sufficient to look at the covariance-variance matrix instead of the correlation matrix, as the correlation of two variables can only be $0$ if and only if the covariance of those two variables is $0$ as well. (as the formula for the correlation is derived from the formula for covariance, see above)

Now I'm pretty sure, that you definitely do not need an optimiser and that you will not find one single set $(\alpha,\beta,\gamma)$ to minimise the correlation of the three (or more) series.

What you want is applying a Principal Component Analysis (PCA) on your data. You will get (at most) three valid sets $(\alpha,\beta,\gamma)$ but should only take the one, which describes the highest proportion of variance of your data.

The coefficients of the first principal component are your set $(\alpha,\beta,\gamma)$.

If you do not have a built-in function in your program for calculating a PCA, you do the following:

  1. write your data as a matrix $S$ with each variable (series) as one column

  2. calculate the covariance-variance matrix $\Sigma$ of your data by $$\Sigma=S^TS$$

  3. calculate the eigenvalues and eigenvectors of $C$ (various ways of doing this)

  4. the eigenvector corresponding to the highest eigenvalue is the set of $(\alpha,\beta,\gamma)$, which describes most of the variance of the original data

Now you have (three) linear combinations of your original variables (series), where the covariance (and consequently the correlation) between the different combinations is zero (by definition and methodology).

As I do not know what exact application your initial problem has, I want to refer to the last paragraph of the Details-section of the linked Wikipedia article.

  • 0
    Thank you very much for your reply. I believe I will need more direct instructions though as I am not a expert in maths myself. Isn't the correlation formula good for getting a correlation value between 2 series only? How to calculate it, or 'its equivalent', for 3 or more? Could you also explain more thoroughly please how I can make use of the 3 formulas you kindly provided in order to derive my objective function? Thanks again for your time :)2011-04-27
  • 0
    @ibiza: I expanded my post. Have a look on the last (3rd) section. It will probably solve your problem without utilising an optimiser. I'm just not quite sure, whether the diagonal elements of the matrix $T$ will be your weights. Though the weights should be somewhere in $T$ (just my intuition).2011-04-27
  • 0
    @T.K. Hi and thanks for your thoughtful post. I tried to use the linear transformation you suggested but am encountering one problem, could you help me compute the last part that I am struggling with?2011-04-27
  • 0
    @T.K. Also, in the second section of your answer, about minimiser, you end it with "and come up with three equations". I apologize for my lack of understanding, but I would need to know what to do with these 3 equations? Because in the end, I want my objective function to be a single equation to minimize, how would that be possible? Thanks again for your time, it is deeply appreciated.2011-04-27
  • 0
    @ibiza: See the R output. That's your solution. (as it would be done in R) About the three equations: They can be turned into one single equation but in matrix-vector notation2011-04-27
  • 0
    @T.K. Thanks! R is definitely better than Excel, a tool I shall learn someday. Did I see that you divided by 3 ($n$) instead of 5 ($m$) in your calculations? Also, I would be really grateful if you could elaborate on your last point on how to achieve a single equation using matrix-vector notation...As I will probably try to take an optimization approach also. Thanks!2011-04-27
  • 0
    @ibiza: Ai! You’re right. I divided by $n$ instead of $m$. So, all the following numbers are wrong. I'll correct it. About the matrix-vector notation: I'm sorry, but I've to leave that point for somebody else, who is more familiar with this. Open a new question?2011-04-27
  • 0
    ok thanks for all nonetheless :) Also, I might be missing where you invert the matrix $D^TD$ before the square root operation (as the negative sign in ^-1/2 at the wikipedia article represents the inversion)?2011-04-27
  • 0
    Corrected. The R-function `solve` does the inversion of it's argument (precisely: it solves the equation $aX=b$ for $X$, while $a$ is the first and $b$ the second -- optional -- parameter).2011-04-27
  • 0
    @T.K. I still see 1/3 in the code as if it was not corrected? Also, I calculated the covariance matrix of T and it is not resulting in the identity matrix, hinting that T might be incorrect? Thanks :)2011-04-27
  • 0
    @T.K. I have difficulties interpreting the result? T has indeed minimal covariance between all its series, but the weightings set to each 'column' are not constant for each of its values? i.e. for each series, there is not a single factor that is applied to each of its corresponding observations so that the overall correlation is minimized? The values in the initial matrix are simply all completely changed in order to get a correlation of 0 between each and every series? I wonder how I can apply this new knowledge to my problem...2011-04-27
  • 0
    @ibiza: I corrected the `1/3`, but unfortunately I've got another error. The covariance of each vector with itself is $0.25$ and not $1$. I'm missing something...2011-04-27
  • 0
    @T.K. you are right, the diagonal values of the covariance matrix of $T$ are not equal to 1, I get 0.2 for each (not 0.25 as you?)2011-04-27
  • 0
    I believe R has an SVD routine available; you might want to use that directly on `D` instead of applying an eigenroutine on `DTD`.2011-04-27
  • 0
    @ibiza: One last edit and HowTo suggestion.2011-04-28
  • 0
    @T.K Thank you very much for your help, all of this is very interesting and I will come back to this post at times for reference. Although it was not what I was looking for initially (optimizer objective function), you've helped me enough that I will accept your answer :) Peace2011-04-28
1

This should go as a comment but seems to be too long for that field

I've got the matrix-squareroot $ M=\sqrt{(D^t D)^{-1}}$ numerically to be approximately $$ \begin{bmatrix} 0.747941101687 & 0.198207748957 & -0.186094411506 \\ 0.198207748957 & 0.176280588608 & -0.0545176638058 \\ -0.186094411506 & -0.0545176638058 & 0.125419407082 \end{bmatrix} $$ using Pari/GP and diagonalization

  • 0
    Thanks for that, @Gottfried. I do not see any big differences between our results, do you?2011-04-27
  • 0
    @T.K.:arrggh... For whatever reason - I did not see that matrix in your comment before, sorry, must have been blind...2011-04-27
  • 0
    @T.K.: Second view: just found in the revision-story of your msg that your correction and my msgs crossed at the same time ...2011-04-27
  • 0
    @Gottfried: No worries :)2011-04-27
  • 0
    @Gottfried Thanks for your contribution :) It is still puzzling however why the covariance matrix of $T$ is not equal to the identity matrix, as stated that it should be in the wikipedia article and method found by T.K...2011-04-27
  • 0
    @ibiza: I've just tried to help with the matrix-squareroot although I did not yet understand your problem completely. What shall be weighted: each column in S by a certain weight? Or each row? And what is the "overall covariance/correlation" which should be minimized? (I assumed, T.K.'s answer were sufficient for your problem, though, so I didn't ask my questions)2011-04-27
  • 0
    @Gottfried, thanks for your comment! I will try to explain it better : I would like each series (column) to have a single weighting applied to its results (rows) so that the total number and severity of simultaneous drawdowns between every series on every row will be minimized. e.g. S1 could have a weight of 0.4, S2 a weight of 0.1 and S3 a weight of 0.5 and these factors will be applied to each values in the corresponding series. Is that clearer? That is an optimization (minimization) problem to me. Please tell me if there are still any ambiguities :)2011-04-27
  • 0
    @ibiza:Well, I understand now, that with some sought $a,b,c$ and the new series $S4$ we want $ S4 = a*S1 + b*S2 + c*S3 $ . But then to minimize the *sum of the entries in S4* ? Then $a,b,c$ need only be set to minus infinity, so this cannot be meant and I'm still stuck with the minimization-criterion.2011-04-27
  • 0
    @Gottfried: And there the constraint $a+b+c=1$ comes in, so the three weights are limited.2011-04-28
  • 0
    @T.K.: yes, but what about $a=10000$,$b=10000$ and $c=-19999$. Moreover, since you coined the term "correlation" there is likeliness, that minimizing the ***sum*** of $S4$ is not really that what you want... And practically, in your example, you not even confine yourself to the sum of the scalings $a*S_1+b*S_2+(1-a-b)*S_3$ by *a,b,c* but also translate $S_1,S_2,S_3$ by removing their mean - which contradicts to your minimizing-criterion (the sum of scaled $S_1,S_2,S_3$ only) Usually, for instance, one minimizes the sum-of-squares of centered values...2011-04-29