请问如何用R语言做大量次数的几何布朗运动的模拟(参数μ,σ已知)

Python019

请问如何用R语言做大量次数的几何布朗运动的模拟(参数μ,σ已知),第1张

这上网搜应该搜的到吧,比如这篇文章"

股票价格行为关于几何布朗运动的模拟--基于中国上证综指的实证研究

",照着几何布朗运动的公式直接写代码应该就行了吧,代码逻辑都很清晰。

下面是照着这片文章模拟一次的代码,模拟多次的话,外面再套个循环应该就行了。然后再根据均方误差(一般用这个做准则的多)来挑最好的。

话说你的数据最好别是分钟或者3s切片数据,不然R这速度和内存够呛。

N <- 2000 #模拟的样本数

S0 <- 2000 #初始值

mu <- 0.051686/100

sigma <- 1.2077/100

St <- rep(0,N)

epsion <- rnorm(N,0,1) #正态分布随机数

for(i in 1:N) {

if(i == 1) {

delta_St <- mu * S0 + sigma * S0 * epsion[i]

St[i] <- S0 + delta_St

}else {

delta_St <- mu * St[i-1] + sigma * St[i-1] * epsion[i]

St[i] <- St[i-1] + delta_St

}

}

Final_St <- c(S0,St) #最终结果

plot(Final_St,type = "l")

r语言数据分析是查看数据的结构、类型,数据处理。根据查询相关资料信息显示:R语言是一个开源、跨平台的科学计算和统计分析软件包,具有丰富多样、强大的的统计功能和数据分析功能,数据可视化可以绘制直方图、箱型图、小提琴图等展示分数的分布情况可以通过散点图和线性拟合来展示分数和年龄之间的关系。

建议你先看一下这本书:

Modeling Survival Data Using Frailty Models

chap 2. Some Parametric Methods

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.2 Exponential Distribution . . . . . . . . . . . . . . . . . . . 20

2.3 Weibull Distribution . . . . . . . . . . . . . . . . . . . . . 21

2.4 Extreme Value Distributions . . . . . . . . . . . . . . . . 23

2.5 Lognormal . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.6 Gamma . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2.7 Loglogistic . . . . . . . . . . . . . . . . . . . . . . . . . 29

2.8 Maximum Likelihood Estimation . . . . . . . . . . . . . 30

2.9 Parametric Regression Models

chap 6. Estimation Methods for Shared Frailty Models

6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . .105

6.2 Inference for the Shared Frailty Model . . . . . . . . . . 106

6.3 The EM Algorithm . . . . . . . . . . . . . . . . . . . . . . .108

6.4 The Gamma Frailty Model . . . . . . . . . . . . . . . . . . . 110

6.5 The Positive Stable Frailty Model . . . . . . . . . . . . . . 111

6.6 The Lognormal Frailty Model . . . . . . . . . . . . . . . . . 113

6.6.1 Application to Seizure Data . . . . . . . . . . . . . . . 113

6.7 Modified EM (MEM) Algorithm for Gamma Frailty Models 114

6.8 Application

然后用最基本的package "survival"

并参考你的模型可能用到的一些functions:

survreg(formula, data, weights, subset,na.action, dist="weibull",....)

survreg.distributions include "weibull", "exponential", "gaussian",

"logistic","lognormal" and "loglogistic"

frailty(x, distribution="gamma", ...)

distribution: either the gamma, gaussian or t distribution may be specified.

frailty.gamma(x, sparse = (nclass >5), theta, df, eps = 1e-05,

method = c("em","aic", "df", "fixed"),...)