rolling pca scores

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

vp212
Posts: 3
Joined: Wed Mar 04, 2015 6:49 am

rolling pca scores

Postby vp212 » Wed Mar 04, 2015 6:58 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: rolling pca scores

Postby EViews Gareth » Wed Mar 04, 2015 10:03 am

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.

vp212
Posts: 3
Joined: Wed Mar 04, 2015 6:49 am

Re: rolling pca scores

Postby vp212 » Wed Mar 04, 2015 10:58 am

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

Postby EViews Gareth » Wed Mar 04, 2015 11:02 am

Could you provide the workfile too?

vp212
Posts: 3
Joined: Wed Mar 04, 2015 6:49 am

Re: rolling pca scores

Postby vp212 » Thu Mar 05, 2015 12:22 am

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).
Attachments
latam_rollingpca.wf1
(522.19 KiB) Downloaded 182 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: rolling pca scores

Postby EViews Gareth » Thu Mar 05, 2015 10:22 am

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?


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests