zhangtao 发表于 2012-12-7 21:22 
epoh老师,您好!
非常感谢您!我的意思是,如何用附件 中的包用simulvar.m和calcvar.m
调用数据dati ...
calcvar.m是个script
deltavar.m,simulvar.m,montevar.m才是用来计算VaR的function
你必须给出数据X,RF,RC:
% X is the matrix of asset prices,
% RF the matrix of risk factors prices,
% RC the matrix of exchange rates
% The vector legame set the relations between assets and risk factors.
% Given 2 risk factors and 4 assets the vector (1 1 1 2) means that the
% first three assets are related with the first risk factors, the fourth
% asset with the second risk factor.
% legame=[1;1;1;1;2;3]
% vector vm of portfolio value.
% vm=[10;20;5;10;5;10]
% The vector valuta set the relation between tha asset and the exchange rate in the same manner of the
% vector legame, with the convention that 0 is for the referred exchange rate.
% valuta=[0;0;0;0;1;0]
% VaR estimation.
% deltavar - delta-normal VaR.
% simulvar - hystorical simulation VaR.
% montevar - Monte Carlo VaR.
%load data dati1.xls
dati1=xlsread('dati1.xls','A2:J1046');
X=dati1(:,1:6);
RF=dati1(:,7:9);
RC=dati1(:,10);
legame=[1;1;1;1;2;3]
vm=[10;20;5;10;5;10]
valuta=[0;0;0;0;1;0]
%Type of return
rendimento=0 %(0 normal, 1 log)
[DX,DR,cambi,fattori,prezzi] = rendimenti(X,RF,RC,rendimento);
%Decay factor
lambda=0.9
if lambda==1
[delta,dev,cor,C] = semplicecorr(DX,DR,legame);
else [delta,dev,cor,C] = ewmacorr(DX,DR,legame,lambda);
end
% Parameters ---------------------------------------------------------------------------------
t=1
p=0.5
% VaR method
% historical simulation
tipo=0 %(0 from risk factors, 1 from prices)
[svar] = simulvar(DR,RC,X,delta,valuta,legame,vm,t,p,tipo,rendimento) % -0.0293
% Monte Carlo
modello=0 %(0 linear, 1 log)
l=10000 %Number of simulations
[mvar] = montevar(delta,C,legame,valuta,cambi,fattori,prezzi,vm,t,p,modello,l,rendimento) % -0.0150