Create 3 column matrix of excel data and lag one column

I want to:
1) I have three columns in an excel spreadsheet (date, inflation data, FX data). The dates are the first of every month. Holding the inflation data as is, I want to lag the FX data by 1 month then 2 months and so on up until 12 months.
2) Then I want to test the correlation between the inflation data and the FX data for each lag. (i.e. corr(inflation,FX1M), corr(inflation,FX2M)...)
What I did (which is far too long, I'd like to condense it): 1) Loaded the three columns as separate vectors ("Date","InflationSpread", & "FX") 2) Ran FX1=lagmatrix(FX,1) X 12 for each lag. 3) Ran FX1(isnan(FX1))=[] X 12 to cut out all the NaNs from each 4) Created IS1 through IS12 using IS1=InflationSpread(2:end,:), IS2=InflationSpread(3:end,:),... So that they were the same lengths as FX1 through FX12, cutting out the beginning data where the NaNs were. 5) corr(FX1,IS1), corr(FX2, IS2),...

Answers (0)

Tags

Asked:

on 27 Oct 2015

Edited:

on 27 Oct 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!