Time-Varying Cointegration in R

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Time-Varying Cointegration in R

Johannes Lips-2
Dear list,

I've implemented the time-varying cointegration framework by Bierens and
Martins (2010) in R [1], based on the gauss implementation of Luis
Martins [2]. I do get the same results as in gauss, when using lower
chebyshev dimensions, but when the number of dimensions is increasing, I
run into issues with complex eigenvalues and eigenvectors.
Additionally the eigenvalues and eigenvectors differ quite a bit between
gauss and R and I do not really know how to find out why that is. I also
experimented with different implementations of eigenvalues
determination, based on the C++ routine eigen, but was not able to
replicate the gauss results exactly.
One notable difference is that gauss does not normalize the
eigenvectors, but even after considering this a discrepancy remains.
Perhaps someone with a better knowledge of gauss may shed some light on
possible sources for these differences.



[1] https://github.com/hannes101/TimeVaryingCointegration
[2] http://home.iscte-iul.pt/~lfsm/

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Time-Varying Cointegration in R

Paul Gilbert-2
Johannes

Ordering complex numbers is not obvious, so one likely thing would be
that you have the same result but in a different order. If the
eigenvalues are the same, only the vectors are different, it is a
normalization issue. If it is not that, then verify that you are
calculating eigenvalues with the same matrix in both systems. A matrix
that has several orders of magnitude difference between the largest and
smallest eigenvalues (in abs value) will be ill-conditioned, in which
case the result can differ a lot based on seemingly small differences in
the matrix. You can verify if this is a problem by copy and paste of
exactly the same matrix into both systems. (Round to a reasonable number
of digits and truncate the rest.)

BTW, if ill-conditioning is the problem, and the results depend
critically on this calculation, there is a problem with the technique.

If those are not the problem, then you might consider checking which
result is correct. This problem does have an answer that can be
verified.  From ?eigen

    If ‘r <- eigen(A)’, and ‘V <- r$vectors; lam <- r$values’, then

                               A = V Lmbd V^(-1)

      (up to numerical fuzz), where Lmbd =‘diag(lam)’.

Please let us know if R is getting an incorrect result. It seems highly
unlikely, but it might affect a lot of calculations.

HTH,
Paul

On 03/22/2016 05:14 AM, Johannes Lips wrote:

> Dear list,
>
> I've implemented the time-varying cointegration framework by Bierens and
> Martins (2010) in R [1], based on the gauss implementation of Luis
> Martins [2]. I do get the same results as in gauss, when using lower
> chebyshev dimensions, but when the number of dimensions is increasing, I
> run into issues with complex eigenvalues and eigenvectors.
> Additionally the eigenvalues and eigenvectors differ quite a bit between
> gauss and R and I do not really know how to find out why that is. I also
> experimented with different implementations of eigenvalues
> determination, based on the C++ routine eigen, but was not able to
> replicate the gauss results exactly.
> One notable difference is that gauss does not normalize the
> eigenvectors, but even after considering this a discrepancy remains.
> Perhaps someone with a better knowledge of gauss may shed some light on
> possible sources for these differences.
>
>
>
> [1] https://github.com/hannes101/TimeVaryingCointegration
> [2] http://home.iscte-iul.pt/~lfsm/
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Time-Varying Cointegration in R

Johannes Lips-2
Paul,

thanks a lot for your reply. I think I can confirm that for basic 3x3
matrices both yield the same results, only gauss does not normalize them
to unit length, but if you do that, the eigenvectors are the same. This
can be seen, when comparing the results of R with the results in the
gauss manual [1] (p. 464-465).
I can also confirm, that the matrix A, for which the eigenvectors need
to be computed are exactly the same between R and gauss. The matrix is
calculated based on the example data set, which is also part of the
gauss code and available in R as well.
I confirmed, that for all non-complex eigenvalues the eigenvectors are
the same, when normalizing the vectors in gauss, at least for the two
and three dimensional chebyshev polynomials. So that leaves me with the
problem, that the results of eigen() are stored in a matrix which
converts everything into complex numbers.

Perhaps someone could help me out to make sure the calculations are done
correctly.

Thanks a lot in advance,
johannes

[1] http://www.aptech.com/wp-content/uploads/2014/01/GAUSS14_LR.pdf
[2] https://gist.github.com/hannes101/eeda2411b480cbeaee16

On 22.03.2016 19:55, Paul Gilbert wrote:

> Johannes
>
> Ordering complex numbers is not obvious, so one likely thing would be
> that you have the same result but in a different order. If the
> eigenvalues are the same, only the vectors are different, it is a
> normalization issue. If it is not that, then verify that you are
> calculating eigenvalues with the same matrix in both systems. A matrix
> that has several orders of magnitude difference between the largest
> and smallest eigenvalues (in abs value) will be ill-conditioned, in
> which case the result can differ a lot based on seemingly small
> differences in the matrix. You can verify if this is a problem by copy
> and paste of exactly the same matrix into both systems. (Round to a
> reasonable number of digits and truncate the rest.)
>
> BTW, if ill-conditioning is the problem, and the results depend
> critically on this calculation, there is a problem with the technique.
>
> If those are not the problem, then you might consider checking which
> result is correct. This problem does have an answer that can be
> verified.  From ?eigen
>
>    If ‘r <- eigen(A)’, and ‘V <- r$vectors; lam <- r$values’, then
>
>                               A = V Lmbd V^(-1)
>
>      (up to numerical fuzz), where Lmbd =‘diag(lam)’.
>
> Please let us know if R is getting an incorrect result. It seems
> highly unlikely, but it might affect a lot of calculations.
>
> HTH,
> Paul
>
> On 03/22/2016 05:14 AM, Johannes Lips wrote:
>> Dear list,
>>
>> I've implemented the time-varying cointegration framework by Bierens and
>> Martins (2010) in R [1], based on the gauss implementation of Luis
>> Martins [2]. I do get the same results as in gauss, when using lower
>> chebyshev dimensions, but when the number of dimensions is increasing, I
>> run into issues with complex eigenvalues and eigenvectors.
>> Additionally the eigenvalues and eigenvectors differ quite a bit between
>> gauss and R and I do not really know how to find out why that is. I also
>> experimented with different implementations of eigenvalues
>> determination, based on the C++ routine eigen, but was not able to
>> replicate the gauss results exactly.
>> One notable difference is that gauss does not normalize the
>> eigenvectors, but even after considering this a discrepancy remains.
>> Perhaps someone with a better knowledge of gauss may shed some light on
>> possible sources for these differences.
>>
>>
>>
>> [1] https://github.com/hannes101/TimeVaryingCointegration
>> [2] http://home.iscte-iul.pt/~lfsm/
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R
>> questions should go.
>>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.