⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simulvar.m

📁 统计工具软件
💻 M
字号:
function [svar] = simulvar(DR,RC,X,delta,valuta,legame,vm,t,p,tipo,rendimento)%SIMULVAR	hystorical simulation VaR.%%	[svar] = simulvar(DR,RC,X,delta,valuta,legame,vm,t,p,tipo,rendimento) %   calculates historical simulation VaR given the vector vm of portfolio%   value, holding period t, probability p, the X matrix of asset prices,%   the RC matrix of exchange rates, the DR matrix of risk factors values,%   the vectors legame and valuta.%   If tipo = 0 uses the historical data of risk factors only and the delta%   coefficients, if tipo = 1 uses the asset prices directly. Put%   rendimento = 0 if the yields are calculated with aritmetic methods, 1%   if calculates with logaritmic methods. Market value are based on the%   last asset prices.%%	All data must be in columns.%%	See DELTAVAR, MONTEVAR%%	Copyright (c) 2004 by Flavio Bazzana%   Department of Computer and Management Sciences%   University of Trento%   38100 - Trento ITALY%   flavio.bazzana@economia.unitn.itm = length(legame);n = size(X,1);if tipo == 0	Z(1,:)=X(1,:);	prezzi=X(n,:)';% calculation of asset prices on the basis of historical returns% of risk factors and mapping factors	for j=2:n		for k=1:m			h=legame(k);			if rendimento==0				Z(j,k)=Z(j-1,k)*(1+delta(k)*DR(j-1,h));				else				Z(j,k)=Z(j-1,k)*exp(delta(k)*DR(j-1,h));			end		end	end% historical matrix of currencies	cp = vm./prezzi;	for j=1:m		if valuta(j)==0			X1(:,j)=ones(n,1);			else X1(:,j)=RC(:,valuta(j));		end	end% calculation of portfolio VaR	X2 = Z.*X1;% calculation of portfolio VaR directly from the assets	else	cp = vm./X(n,:)';	for j=1:m		if valuta(j)==0			X1(:,j)=ones(n,1);			else X1(:,j)=RC(:,valuta(j));		end	end	X2 = X.*X1;endvp = X2*cp;% ordering the daily lossesdvp = diff(vp);sdvp = sort(dvp);% calculation of portfolio VaRn = length(sdvp);svar = -sdvp(fix(n-n*p))*sqrt(t); % graph[freq,classi]=hist(dvp*sqrt(t),n/25);bar(classi,freq,'b')line([-svar -svar],[0 max(freq)],'color','red')title('Historical VaR simulation')xlabel('classes of losses')ylabel('frequencies')text(-svar+(svar/10),max(freq)/2,num2str(p))

⌨️ 快捷键说明

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