📄 deltaback.m
字号:
function [dn,dvar,vp] = deltaback(X,RF,RC,legame,valuta,vm,p,rendimento,campione,dati,lambda,datidelta)%DELTABACK backtesting for delta-normal VaR.%% [dn,dvar,vp] = deltaback(X,RF,RC,legame,valuta,vm,p,rendimento,campione,dati,lambda,datidelta) % calculates the number of exceptions in portfolio backtesting for VaR with% delta-normal method. Campione represents the number of simulations (for% Basel is 250) and dati is the number of data used for VaR calculation.% Lambda is the weight in EWMA volatility forecast.% If Datidelta = 0 the mapping procedure is calculated over all X,% = 1 only with defined data.%% All data mus be in column.%% See DELTAVAR%% Copyright (c) 2004 by Flavio Bazzana% Department of Computer and Management Sciences% University of Trento% 38100 - Trento ITALY% flavio.bazzana@economia.unitn.itn=size(X,1);m=length(valuta);[DX,DR,cambi,fattori,prezzi] = rendimenti(X,RF,RC,rendimento);[deltax,dev,cor,C] = semplicecorr(DX,DR,legame);cp = vm./prezzi;for i=1:campione+1% VaR interval X1=X(n-dati-i:n-i,:); RF1=RF(n-dati-i:n-i,:); RC1=RC(n-dati-i:n-i,:); % calculation of deltavar over such interval [DX,DR,cambi,fattori,prezzi] = rendimenti(X1,RF1,RC1,rendimento); if lambda==1 [delta,dev,cor,C] = semplicecorr(DX,DR,legame); else [delta,dev,cor,C] = ewmacorr(DX,DR,legame,lambda); end if datidelta==1 [dvar(i),dvarp] = deltavar(delta,dev,cor,legame,valuta,cambi,vm,1,p); else [dvar(i),dvarp] = deltavar(deltax,dev,cor,legame,valuta,cambi,vm,1,p); end% calculation of portfolio value for j=1:m if valuta(j)==0 k1(j)=1; else k1(j)=cambi(valuta(j)); end end k2 = prezzi.*k1'; vp(i) = k2'*cp;end% calculation of the exceptionsdn=0;for i=1:campione if vp(i+1)-vp(i)<-dvar(i) dn=dn+1; end if vp(i+1)-vp(i)>dvar(i) dn=dn+1; endendf=1:campione;plot(f,-dvar(1:campione),'b',f,dvar(1:campione),'b',f,diff(vp),'r')title('Backtesting delta-normal VaR')xlabel('Sample')ylabel('VaR')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -