deltavar.m

来自「统计工具软件」· M 代码 · 共 89 行

M
89
字号
function [dvar,dvarp] = deltavar(delta,dev,cor,legame,valuta,cambi,vm,t,p)%DELTAVAR	delta-normal VaR.%%	[dvar,dvarp] = deltavar(delta,dev,cor,legame,valuta,cambi,vm,t,p)%   VaR of a portfolio and the VaR for every risk factors with%   delta-normal methods, given the vector vm of portfolio value, the%   holding period t, and the probability p. Delta is the sensibility%   vector, dev is the vector of standard deviations fo the risk facyors,%   and cor is the variance-covarianze matrix.%   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. 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.%%	All data must be in columns.%%	See MONTEVAR, SIMULVAR%%	Copyright (c) 2004 by Flavio Bazzana%   Department of Computer and Management Sciences%   University of Trento%   38100 - Trento ITALY%   flavio.bazzana@economia.unitn.it% VaR calculations for every risk factors, whitout excahnge rates ...c = length(cambi);n = length(legame);m = length(dev);f = m-c;for i=1:m	varp(i)=0;endfor i=1:n	valutac(i)=0;endfor i=1:f	cambif(i)=0;endfor i=1:c	cambic(i)=0;endfor i=1:n 	if valuta(i) == 0		valutac(i)=1;		cambif(legame(i))=1;		else valutac(i)=cambi(valuta(i));			cambif(legame(i))=cambi(valuta(i));			cambic(valuta(i))=cambic(valuta(i))+vm(i);	endendcambic=cambic'.*cambi;% ... first in local currency ...for i=1:n	h=legame(i);	varp(h)=varp(h)+vm(i)*delta(i);end	% ... than in the defined currency ...for i=1:f	varp(i)=varp(i)*cambif(i);end	% ... add exchange rate risk ...for i=f+1:m	varp(i)=cambic(i-f);end% ... calculation of VaR fvor every risk factors ...a=alfauna(p);dvarp = varp'.*dev*a*sqrt(t);% ... calculation of portfolio VaRdvar = sqrt(dvarp'*cor*dvarp);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?