matlab 怎么与运算,求助如何用MATLAB计算VAR和Expected shortfall

不知道这个能不能满足

function calcvar

%calcvar        terminal interface for VaR calculation.

%

%        You can use the sample data (1, 2, 3) to try the program

%

%        Copyright (c) 2004 by Flavio Bazzana

%   Department of Computer and Management Sciences

%   University of Trento

%   38100 - Trento ITALY

%   flavio.bazzana@economia.unitn.it

clear

home

%        Load data ----------------------------------------------------------------------------------------

file=input('Which data? (1, 2, 3) ');

if file==1 load('dati1');

elseif file==2 load('dati2');

else load('dati3');

end

dati=size(X,1)

%        Type of return ------------------------------------------------------------------------

rendimento=input('Which return? (0 normal, 1 log) ');

[DX,DR,cambi,fattori,prezzi] = rendimenti(X,RF,RC,rendimento);

%        Decay factor ----------------------------------------------------------------------------

lambda=input('Decay factor? (x<=1) ');

if lambda==1

[delta,dev,cor,C] = semplicecorr(DX,DR,legame);

else [delta,dev,cor,C] = ewmacorr(DX,DR,legame,lambda);

end

%        Parameters ---------------------------------------------------------------------------------

t=input('Holding period? ');

p=input('Probability? ');

%        VaR method ------------------------------------------------------------------------------------

a=0;

while a < 4;

a=input('VaR methods? (1 delta-normal, 2 historical simulation, 3 Monte Carlo, 4 average) ');

if a==1

[dvar,dvarp] = deltavar(delta,dev,cor,legame,valuta,cambi,vm,t,p);

dvar

elseif a==2

tipo=input('Mapping? (0 from risk factors, 1 from prices) ');

[svar] = simulvar(DR,RC,X,delta,valuta,legame,vm,t,p,tipo,rendimento)

elseif a==3

modello=input('Simulation model? (0 linear, 1 log) ');

l=input('Number of simulations? ');

[mvar] = montevar(delta,C,legame,valuta,cambi,fattori,prezzi,vm,t,p,modello,l,rendimento)

end

end

%        Average VaR --------------------------------------------------------------------------

dati=input('How many data for VaR calculation? ');

giorni=input('How many days of VaR calculation? ');

datidelta=input('Mapping calculation? (0 over all X, 1 over the data only) ');

a=0;

while a < 4;

a=input('VaR methods? (1 delta-normal, 2 historical simulation, 3 Monte Carlo, 4 backtest) ');

if a==1

[dvar,media] = deltamedia(X,RF,RC,legame,valuta,vm,t,p,rendimento,dati,giorni,lambda,datidelta);

media

elseif a==2

tipo=input('Mapping? (0 from risk factors, 1 from prices) ');

[svar,media] = simulmedia(X,RF,RC,legame,valuta,vm,t,p,rendimento,dati,giorni,tipo,lambda,datidelta);

media

elseif a==3

modello=input('Simulation model? (0 linear, 1 log) ');

l=input('Number of simulations? ');

[mvar,media] = montemedia(X,RF,RC,legame,valuta,vm,t,p,rendimento,dati,giorni,modello,l,lambda,datidelta);

media

end

end

%        Daily backtest --------------------------------------------------------------------

campione=input('Number of test? (Basilea = 250) ');

dati=input('How many data for VaR calculation? ');

datidelta=input('Mapping calculation? (0 over all X, 1 over the data only) ');

a=0;

while a < 4;

a=input('Backtest for? (1 delta-normal, 2 historical simulation, 3 Monte Carlo, 4 end) ');

if a==1

[dn,dvar,vp] = deltaback(X,RF,RC,legame,valuta,vm,p,rendimento,campione,dati,lambda,datidelta);

elseif a==2

tipo=input('Type of estimation? (0 from risk factors, 1 from prices) ');

[sn,svar,vp] = simulback(X,RF,RC,legame,valuta,vm,p,rendimento,tipo,campione,dati,lambda,datidelta);

elseif a==3

modello=input('Simulation model? (0 linear, 1 log) ');

l=input('Number of simulations? ');

[mn,mvar,vp] = monteback(X,RF,RC,legame,valuta,vm,p,rendimento,campione,dati,modello,l,lambda,datidelta);

end

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值