楼主: xingzhaoh
4910 15

[问答] 小代码求教 [推广有奖]

11
epoh 发表于 2012-12-7 15:38:25
zhangtao 发表于 2012-12-7 10:52
epoh老师,您好!
如何用附件 中的包用simulvar.m和calcvar.m
调用数据dati1.mat做VaR分析?
calcvar.m  - terminal interface for VaR calculation
%VaR estimation.
   deltavar         - delta-normal VaR.
   simulvar         - hystorical simulation VaR.
   montevar      - Monte Carlo VaR.
%in matlab command window
>>calcvar

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

file=input('Which data? (1, 2, 3) '); 1
     if file==1 load('dati1');
        elseif file==2 load('dati2');
        else load('dati3');
end
%        Type of return --------------------------------------------------------------------

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

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

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

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

t=input('Holding period? '); 1
p=input('Probability? ');    0.5

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

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

tipo=input('Mapping? (0 from risk factors, 1 from prices) '); 0
[svar] = simulvar(DR,RC,X,delta,valuta,legame,vm,t,p,tipo,rendimento)

svar =
0 from risk factors :  -0.0293
1 from prices       :  -0.0148
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 epoh老师,谢谢您的热心

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

12
zhangtao 发表于 2012-12-7 21:22:38
epoh 发表于 2012-12-7 15:38
calcvar.m  - terminal interface for VaR calculation
%VaR estimation.
   deltavar         - del ...
epoh老师,您好!
非常感谢您!我的意思是,如何用附件 中的包用simulvar.m和calcvar.m
调用数据dati1.mat做VaR分析?就是可以套上自己的数据用simulvar.m和calcvar.m
计算VaR,而不是去执行这个主程序。您看simulvar.m和calcvar.m
如何才能套上自己的数据调用呢?
非常感谢!
基与蒙特卡罗模拟法的风险价值_VaR_及其在中国股票市场中的运用.zip (1.82 MB) 本附件包括:
  • 基与蒙特卡罗模拟法的风险价值_VaR_及其在中国股票市场中的运用.nh

数学好就是要天天学

13
zhangtao 发表于 2012-12-8 10:45:53
epoh老师,您好!
您看看这个dynare程序什么地方有错?非常感谢!
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 33 Column: 4
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 33 Column: 4
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 35 Column: 4
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 37 Column: 9
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 37 Column: 9
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 44 Column: 8
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 44 Column: 8
The expression to the left of the equals sign is not a valid target for an assignment.
??? Error: File: D:\MATLAB7\work\Untitled.m Line: 44 Column: 8
The expression to the left of the equals sign is not a valid target for an assignment.
>>
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
epoh + 5 + 5 + 5 好议题

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

数学好就是要天天学

14
epoh 发表于 2012-12-8 18:11:08
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:
    dati1.xls (151 KB)
% 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



15
epoh 发表于 2012-12-8 20:52:04
zhangtao 发表于 2012-12-8 10:45
epoh老师,您好!
您看看这个dynare程序什么地方有错?非常感谢!
??? Error: File: D:\MATLAB7\work\Unt ...
>>addpath c:\dynare\4.3.1\matlab
>>cd c:\dynare\test
>>dynare dynaret
...
...

There are 3 eigenvalue(s) larger than 1 in modulus
for 0 forward-looking variable(s)

The rank conditions ISN'T verified!

我已很久没碰DSGE model,
这个问题,就请zhangtao 兄,自行检查model的正确性了.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 epoh老师,真的非常感动!非常感谢!

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

16
syler 发表于 2013-1-15 21:09:16
epoh 发表于 2012-11-23 16:37
data=read.csv("sysfit_11.csv")

logistInit
大神,指点下这个问题啊,在论坛里,下面是连接,无人指点很是迷茫啊
https://bbs.pinggu.org/forum.php? ... ;page=1#pid16255949

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 15:35