Is there a way to save the rolling scores (preferably in one vector) when doing a rolling pca...
Currently my code is:
latam_5.pcomp(cor, eigval=eval, eigvec=evec) pc1 pc2 pc3
' store eigenvalue proportions which are rolling
!cumpc1 = eval(1)/@sum(eval)
evalpc1(!i) = !cumpc1
!cumpc2 = eval(2)/@sum(eval)
evalpc2(!i) = !cumpc2
' store eigenvals which are rolling
ev1roll(!I) = eval(1)
ev2roll(!I) = eval(2)
' store eigenvec (loadings) which are rolling
evec1(!i) = evec(1,1)
evec2(!i) = evec(2,1)
evec3(!i) = evec(3,1)
evec4(!i) = evec(4,1)
evec5(!i) = evec(5,1)
next
rolling pca scores
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: rolling pca scores
You'll have to roll the sample, and store them at each observation. There are lots of examples of performing rolling operations on this forum.
Re: rolling pca scores
Thanks for your msg. I've done this and only the latest pc1 saves (i.e. for last 2y window that I use). When I try to create a roll for pc1, it comes up with an error message. Have attached my code.
- Attachments
-
- rolling_pca_code_latam.prg
- (1.67 KiB) Downloaded 227 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: rolling pca scores
Could you provide the workfile too?
Re: rolling pca scores
Workfile attached as requested.
Any help would be great...Many thanks.
Note: To clarify I've taken out the error bit in the previously attached code. The line that I had (to attempt to save rolling pc scores across the entire sample) was:
pc1vector(!i) = pc1
The problem is that pc1 is not a single value, but a 2y series. So what I am trying to get is pc1 scores at time t (2y window from start of sample), pc1 scores at time t+1 (window shifted one day), pc1 scores at time t+2 etc. etc.
What this does is updates all the pc's and adds an extra score taking into account the latest data from the +1 window shift. I can't quite figure out how to store this all into a single column vector/series (or even multiple series for that matter).
Any help would be great...Many thanks.
Note: To clarify I've taken out the error bit in the previously attached code. The line that I had (to attempt to save rolling pc scores across the entire sample) was:
pc1vector(!i) = pc1
The problem is that pc1 is not a single value, but a 2y series. So what I am trying to get is pc1 scores at time t (2y window from start of sample), pc1 scores at time t+1 (window shifted one day), pc1 scores at time t+2 etc. etc.
What this does is updates all the pc's and adds an extra score taking into account the latest data from the +1 window shift. I can't quite figure out how to store this all into a single column vector/series (or even multiple series for that matter).
- Attachments
-
- latam_rollingpca.wf1
- (522.19 KiB) Downloaded 181 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: rolling pca scores
Well, as you say, you're trying to store a lot of data into a small container. It can't be done. If I interpret correctly, for each individual roll/sample, you need to save 730 values. Obviously that can't be done in a series, where you only have one value per date. Nor can it be done in a vector. Perhaps you should create 730 vectors? Or a matrix with 730 columns?
Who is online
Users browsing this forum: No registered users and 2 guests
