楼主: lixutao
2555 1

[问答] 求解蒙特卡罗模拟金融衍生品定价(张树德那本书)代码意义 [推广有奖]

  • 0关注
  • 0粉丝

学前班

60%

还不是VIP/贵宾

-

威望
0
论坛币
8 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
20 点
帖子
1
精华
0
在线时间
2 小时
注册时间
2015-10-29
最后登录
2018-8-27

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
function [p,ci]=AsianMCCV(s0,k,r,t,sigma,nsamples,nrepl,npilot)
trypath=assetpaths1(s0,r,sigma,nsamples,npilot);
stocksum=sum(trypath,2);
pp=mean(trypath(:,2:(nsamples+1),2);
trypayoff=exp(-r*t)*max(0,pp-x);
matcov=cov(stocksum,trypayoff);
dt=t/nsamples;
expsum=s0*(1-exp((nsamples+1)*r*dt))/(1-exp(r*dt));
controlvars=zeros(nrepl,1);
for i=1:nrepl
    stockpath=assetpaths1(s0,r,sigma,t,nsamples,1);
    payoff(i)=exp(-r*t)*max(0,mean(stockpath(2:(nsamples+1)))-x);
    controlvars(i)=payoff(i)+c*(sum(stockpath)-expsum);
end
[p,aux,ci]=normfit(controlvars);
function spaths=assetpahts1(s0,mu,sigma,nsteps,nrepl)
dt=t/nsteps;
nudt=(mu-0.5*sigma^2)*dt;
sidt=sigma*sqrt(dt);
increments=nudt+sidt*randn(nrepl,nsteps);
logpaths=cumsum([log(s0)*ones(nrepl,1),increments],2)
spaths=exp(logpaths);

感觉trypath也不是向量啊,怎么可以对列求和或对行求和(红色标记出来)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:蒙特卡罗模拟 金融衍生品 衍生品定价 蒙特卡罗 金融衍生 蒙特卡罗 function 衍生品

沙发
niuniuyiwan 在职认证  发表于 2015-10-29 10:50:12 |只看作者 |坛友微信交流群
  1. function S = AssetPaths(S0,mu,sig,dt,steps,nsims)
  2. % Function to generate sample paths for assets assuming geometric
  3. % Brownian motion.
  4. %
  5. % S = AssetPaths(S0,mu,sig,dt,steps,nsims)
  6. %
  7. % Inputs: S0 - stock price
  8. %       : mu - expected return
  9. %       : sig - volatility
  10. %       : dt - size of time steps
  11. %       : steps - number of time steps to calculate
  12. %       : nsims - number of simulation paths to generate
  13. %
  14. % Output: S - a matrix where each column represents a simulated
  15. %             asset price path.
  16. %
  17. % Notes: This code focuses on details of the implementation of the
  18. %        Monte-Carlo algorithm.
  19. %        It does not contain any programatic essentials such as error
  20. %        checking.
  21. %        It does not allow for optional/default input arguments.
  22. %        It is not optimized for memory efficiency or speed.

  23. % Author: Phil Goddard (phil@goddardconsulting.ca)
  24. % Date: Q2, 2006

  25. % calculate the drift
  26. nu = mu - sig*sig/2;

  27. % Generate potential paths
  28. S = S0*[ones(1,nsims); ...
  29.             cumprod(exp(nu*dt+sig*sqrt(dt)*randn(steps,nsims)),1)];
复制代码

1.JPG



使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-7 01:18