Code covered by the BSD License  

Highlights from
Exercises in Advanced Risk and Portfolio Management

from Exercises in Advanced Risk and Portfolio Management by Attilio Meucci
text and comments on solutions available at http://symmys.com/node/170

S_BondResidualModel.m
clc; clear; close all;

load db_BondAttribution 
% B = key rate durations
% F = key rate weekly changes
% X = bonds returns net of carry

[T,K,N]=size(B);

U=0*X;
for t=1:T
    U(t,:)=X(t,:)-F(t,:)*squeeze(B(t,:,:));
end

C=corr([U F]);

C_U=C(1:N,1:N)
C_FU=C(1:N,N+1:end)

Contact us at files@mathworks.com