请选择 进入手机版 | 继续访问电脑版
楼主: niuniuyiwan
5383 2

[R] [R]几何布朗运动及Vasicek模型利率路径在R中的模拟 [推广有奖]

  • 7关注
  • 91粉丝

VIP

学科带头人

88%

还不是VIP/贵宾

-

威望
0
论坛币
12597 个
通用积分
1650.3361
学术水平
1116 点
热心指数
1164 点
信用等级
1058 点
经验
8057 点
帖子
1624
精华
1
在线时间
2436 小时
注册时间
2010-10-10
最后登录
2024-3-28

niuniuyiwan 在职认证  发表于 2015-8-6 15:36:08 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

  Simulation of the short rate in the Vasicek model in R

                        转自http://delta9hedge.blogspot.com/2013/05/simulation-of-vasicek-interest-rates-in.html
  1. #==================
  2. # model parameters
  3. # 初始参数设定
  4. #==================
  5. r0 <- 0.02
  6. thetaQ <- 0.05
  7. kappa <- 0.1
  8. sigma <- 0.015
  9. T0 <- 1

  10. #=======================
  11. # simulation parameters
  12. #  Euler离散化(40次模拟)
  13. #=======================

  14. hedge.points <-252
  15. simulations.total <- 40
  16. maturity <- T0


  17. dt <- maturity/(hedge.points+1)
  18. timeline <- seq(0,maturity, dt)

  19. f <- matrix(r0,(hedge.points+2),simulations.total)

  20. vasicek_rate <- function(r,kappa,theta,sigma,dt){
  21. expkappadt <- exp(-kappa*dt)
  22. vasi_vola <- (sigma^2)*(1-expkappadt^2)/(2*kappa)
  23. result <- r*expkappadt+theta*(1-expkappadt)+sqrt(vasi_vola)*rnorm(1)
  24. return(result)
  25. }

  26. for(i in 2:(hedge.points+2)){
  27. for(j in 1:simulations.total){
  28.   f[i,j]<- vasicek_rate(f[i-1,j],kappa,thetaQ,sigma,dt)
  29. }
  30. }


  31. #==================================
  32. # plot of interest rate simulations
  33. # 绘制利率路径
  34. #==================================

  35. plot(timeline,f[,1], ylim=range(f,thetaQ), type="l", col="mediumorchid2")
  36. for(j in 2:simulations.total){
  37. lines(timeline,f[,j], col=colors()[floor(runif(1,1,657))] )
  38. }
  39. abline( h = thetaQ, col = "red")
  40. text(0, thetaQ+0.005,paste("long term interest level: theta =",thetaQ),adj=0)

  41. title(main="Simulation of Vasicek interest rate", col.main="red", font.main=4)
复制代码

1.png

Simulation of a Geometric Brownian Motion in R

  1. maturity <- 15
  2. simulation.length <- 10001
  3. dt <-  maturity/(simulation.length-1)

  4. timeline <- seq(0,maturity, dt)

  5. S0<-1
  6. r<-0.05
  7. mu<-0.1
  8. mu0<-0.2
  9. sigma<-0.2
  10. sigma0<-0.375

  11. f <- g <- g0 <- h <- h0 <- rep(0, times=simulation.length)
  12. g0[1] <- h0[1] <- g[1] <-  h[1] <- S0

  13. for(i in 2:simulation.length){
  14. f[i] <- f[i-1]+sqrt(dt)*rnorm(1)
  15. g[i] <- g[1]*exp((mu-(sigma^2)/2)*(i-1)*dt+sigma*f[i])
  16. g0[i] <- g0[1]*exp(mu*(i-1)*dt)
  17. h[i] <- h[1]*exp((mu0-sigma0^2/2)*(i-1)*dt+sigma0*f[i])
  18. h0[i] <- h0[1]*exp(mu0*(i-1)*dt)
  19. }

  20. o_range <- range(f,g,g0,h,h0)

  21. plot(timeline,f, ylim=o_range, type="l", col="coral1")
  22. lines(timeline,g0, col="chartreuse3")
  23. lines(timeline,g, col="chartreuse2")
  24. lines(timeline,h, col="deepskyblue1")
  25. lines(timeline,h0, col="deepskyblue3")

  26. title(main="Geometric Brownian Motion trajectories", col.main="red", font.main=4)



  27. legend(1, o_range[2], c("mu = 0.2,  sigma = 0.375","mu = 0.1,  sigma = 0.2","Brownian motion"), cex=0.8,
  28.    col=c("deepskyblue1","chartreuse2","coral1"), pch=1, lty=1);
复制代码

geometric_brownian_trajectories (1).jpg



二维码

扫码加我 拉你入群

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

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

关键词:Vasicek 布朗运动 ASIC SIC ASI 模型

已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
我的素质低 + 100 + 100 精彩帖子
xddlovejiao1314 + 100 + 100 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 200  论坛币 + 200  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

xddlovejiao1314 学生认证  发表于 2015-8-7 10:41:38 |显示全部楼层 |坛友微信交流群
好贴,谢谢分享。
已有 1 人评分论坛币 收起 理由
niuniuyiwan + 12 精彩帖子

总评分: 论坛币 + 12   查看全部评分

使用道具

wzm1997 发表于 2019-5-17 14:56:01 |显示全部楼层 |坛友微信交流群
好好学习

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

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

GMT+8, 2024-3-29 16:11