Path: news.mathworks.com!not-for-mail
From: "Gang-Gyoo " <ggjin@hhu.ac.kr>
Newsgroups: comp.soft-sys.matlab
Subject: Simple lag function
Date: Mon, 29 Apr 2013 19:54:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <klmj51$i7v$1@newscl01ah.mathworks.com>
Reply-To: "Gang-Gyoo " <ggjin@hhu.ac.kr>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1367265249 18687 172.30.248.35 (29 Apr 2013 19:54:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 29 Apr 2013 19:54:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2332296
Xref: news.mathworks.com comp.soft-sys.matlab:794570

function test

%Test data(not your data)
data= rand(12,2);

%Log monthly risk free rate
lrf_m = log(1+(lag(data(:,2))/(100*12)));
lrf_m(1,1)=NaN;

%Log monthly exc return German Long term bond
ly_10_m = (log(1+(data(:,1))/(100*12)));
dur = 12*((1-(1+(data(:,1)/(100))).^(-10)))./(1-(1+(data(:,1)/(100))).^(-1));
lret_b_10_m =(lag(dur).*lag(ly_10_m)-(lag(dur)-1).*ly_10_m);
exlret_b_10 = lret_b_10_m-lrf_m
end

function y= lag(x)
y= [NaN x(1:end-1)']';
end