Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Principal Component Analysis - Rolling Function

    Hi,

    I'm finishing my thesis we're I'm forming currency-hedge investment portfolios out of the PCA on the currencies.

    I need to do a PCA using a "moving-window" of the previous 60 months of data, throughout my entire data-set.

    If you want the "pseudo-code" is:
    -Run PCA using previous 60m of data.
    -Store the principal components
    -Standardize principal components
    -Average the standardized principal components according to each component's proportion.
    -Export Array with the averaged standardized principal components, for each month.

    Basically, an "OOS" PCA with 60 month rolling window.

    Any thoughts?

    I tried using the formula:

    rolling e(L), window(60): pca AUD CAD EUR JPY NZD SGD SEK CHF GBP USD

    But I end up having the mismatch r(109) error, and I can't understand why.

    For those not acquainted with the rolling formula (http://www.stata.com/manuals13/tsrolling.pdf), e(L) is supposed specification of the stored components, 60 the number of periods to use, and pca the command we are using.

    Thanks for ANY help you can provide me with this.

    PS: If anyone knows how to do this in other statistical software (R, for instance), some tips would also be welcomed!

  • #2
    e(L) is an entire matrix; how do you expect that rolling (incidentally, a command not a function) will store it?

    Independently of that, you have

    -Standardize principal components
    -Average the standardized principal components according to each component's proportion.
    What does that mean? You are trying to calculate PCs from the correlation matrix; any further standardization will just discard important information.
    Last edited by Nick Cox; 02 Jun 2014, 07:40.

    Comment


    • #3
      Also cross-posted on http://www.talkstats.com/showthread....onent-Analysis

      Please see the Advice in the FAQ for our policy on cross-posting.

      Comment


      • #4
        Hi -- I think what you could try is to set the number of components constant to at least two or three. For each currency, for each factor, you creat a variable of blank values. So you have AUDFactor1 AUDFactor2 AUDFactor3. For each month, you have a e(L) matrix of loadings. so let's say for AUD factor 1's loading is in the e(L)[1,1] location. You can save that particular value to a scalar and then replace AUDFactor1 equal to your scalar if month equals the last month of your rolling window. So you are saving bits of information from your matrix every month to these variables with a replace function using the month as a means of controling where to save it. A second idea I had would be to save e(L) as another matrix name and then use a prime symbol to reshape the dimenson and save it in another locatoin and just append another layer every month with a new e(L), but I'm not sure whick one is more laborious. Best, Jeff

        Comment

        Working...
        X