Time series of rolling eigenvalue proportion (from PCA)
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Time series of rolling eigenvalue proportion (from PCA)
Hi,
I would like to run a rolling PCA of weekly returns of a basket of risky assets. To understand the evolution over time of the co-movement of the different assets in the basket, what I need as output is a time series of the proportion of the eigenvalue of the 1st principal component from each 2-year window sample, rolled over a week forward at the time (from 1/1/1995- 7/6/2014). two questions: 1) I want the computation to use ordinary covariances, so included 'cov' in the options, but I am still getting ordinary correlations in the output. what am I doing wrong? 2) I realize I need to use the following commands, but not sure how to build the loop, and generate and save a time series of the proportion of the first eigenvalue.
group gbasket brent copper alum nickel plat cotton spx dax hk_eq bra_eq Chn_eq Ind_eq spxmatr consdis aud nzd adxy sek cad
gbasket.pcomp (cov, eigval=eval)
Can you please help me with this?
Thanks very much in advance,
Tal
I would like to run a rolling PCA of weekly returns of a basket of risky assets. To understand the evolution over time of the co-movement of the different assets in the basket, what I need as output is a time series of the proportion of the eigenvalue of the 1st principal component from each 2-year window sample, rolled over a week forward at the time (from 1/1/1995- 7/6/2014). two questions: 1) I want the computation to use ordinary covariances, so included 'cov' in the options, but I am still getting ordinary correlations in the output. what am I doing wrong? 2) I realize I need to use the following commands, but not sure how to build the loop, and generate and save a time series of the proportion of the first eigenvalue.
group gbasket brent copper alum nickel plat cotton spx dax hk_eq bra_eq Chn_eq Ind_eq spxmatr consdis aud nzd adxy sek cad
gbasket.pcomp (cov, eigval=eval)
Can you please help me with this?
Thanks very much in advance,
Tal
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
You have a space between the pcomp proc and its options. Remove the space.
Re: Time series of rolling eigenvalue proportion (from PCA)
Ok great, so that answers my first question... Thank you very much. Can you kindly also explain how I should construct the loop to get a weekly rolling eigenvalue proportion of 2-year window?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
Do a search for "rolling" on this forum - there are tons of examples.
Re: Time series of rolling eigenvalue proportion (from PCA)
Thank you Gareth. I looked it up, and also looked at the 'roll' examples you provide in the sample programs. I think it should be something like the below, however I get an error on the final command, when I try to store the output (the proportion of the first PC eigenvalues) in a vector... Can you please tell me what is the problem?
Thanks again very much for your help
group gbasket brent copper alum nickel plat cotton spx dax hk_eq bra_eq Chn_eq Ind_eq spxmatr consdis aud nzd adxy sek cad
' set window size
!window = 104
' set step size
!step = 1
' get size of workfile
!length = @obsrange
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'vector to store eigenvalue proportions
vector(!nrolls) evalpc1
' variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first @first+!i+!window-2
' principle component estimation
gbasket.pcomp(cov, eigval=eval, cproport) pc1
' store eigenvalue proportions
evalpc1(!1) = @cproport(gbasket)
next
Thanks again very much for your help
group gbasket brent copper alum nickel plat cotton spx dax hk_eq bra_eq Chn_eq Ind_eq spxmatr consdis aud nzd adxy sek cad
' set window size
!window = 104
' set step size
!step = 1
' get size of workfile
!length = @obsrange
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'vector to store eigenvalue proportions
vector(!nrolls) evalpc1
' variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first @first+!i+!window-2
' principle component estimation
gbasket.pcomp(cov, eigval=eval, cproport) pc1
' store eigenvalue proportions
evalpc1(!1) = @cproport(gbasket)
next
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
The pcomp group proc doesn't have a "cproport" option. I'm not sure what you're trying to do with the lines:
Edit: Sorry, now I see that it does.
Code: Select all
gbasket.pcomp(cov, eigval=eval, cproport) pc1
evalpc1(!1) = @cproport(gbasket)
Edit: Sorry, now I see that it does.
Re: Time series of rolling eigenvalue proportion (from PCA)
The 'cproport' (as defined in the Eviews 7 help section) is what generates the cumulative proportion of eigenvalues. This is the closest I could find to what I am looking for. The first line you quoted is supposed to run the principal component analysis and generate the eigenvalues and proportion of the first PC (1st eigenvalue/total sum of eigenvalues) in a rolling manner, ie generate one value (=proportion) for each time window, on a weekly rolling basis, until I get a full time series. Then the second line is just trying to store this time series in the vector I created...
Is there no function that will allow me to perform this in one direct way? Do you think perhaps I need to just request for a time series of the rolling 1st principal component eigenvalue, and then divide the series myself by the sum of eigenvalues?
Is there no function that will allow me to perform this in one direct way? Do you think perhaps I need to just request for a time series of the rolling 1st principal component eigenvalue, and then divide the series myself by the sum of eigenvalues?
Re: Time series of rolling eigenvalue proportion (from PCA)
I get the same error message - Gareth, any suggestions?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
Store the eigenvalues using the eigval= option in pcomp. Then if you want the proportion of a single eigenvalue, divide it by the sum of them:
Code: Select all
gbasket.pcomp(cov, eigval=eval) pc1
' store eigenvalue proportions
!cumpc = eval(1)/@sum(eval)
Re: Time series of rolling eigenvalue proportion (from PCA)
Thank you. That seemed to work. However, I'm getting all zeros.
The entire code is below: can you suggest any changes?
' set window size
!window = 104
' set step size
!step = 1
' get size of workfile
!length = @obsrange
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'vector to store eigenvalue proportions
vector(!nrolls) evalpc1
' variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first @first+!i+!window-2
' principle component estimation
gbasket.pcomp(cor, eigval=eval) pc1
' store eigenvalue proportions
!cumpc = eval(1)/@sum(eval)
next
The entire code is below: can you suggest any changes?
' set window size
!window = 104
' set step size
!step = 1
' get size of workfile
!length = @obsrange
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'vector to store eigenvalue proportions
vector(!nrolls) evalpc1
' variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample to estimation period
smpl @first @first+!i+!window-2
' principle component estimation
gbasket.pcomp(cor, eigval=eval) pc1
' store eigenvalue proportions
!cumpc = eval(1)/@sum(eval)
next
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
You have to put the !cumpc somewhete
Re: Time series of rolling eigenvalue proportion (from PCA)
meaning !cumpc needs to be stored in the vector evalpc1? Can't seem to get the data stored in evalpc1
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Time series of rolling eigenvalue proportion (from PCA)
Code: Select all
evalpc1(!i) = !cumpc1Re: Time series of rolling eigenvalue proportion (from PCA)
That worked, thank you.
Who is online
Users browsing this forum: No registered users and 2 guests
