R语言构造股票市场指数
㈠ 请问如何用R语言做大量次数的几何布朗运动的模拟(参数μ,σ已知)
这上网搜应该搜的到吧,比如这篇文章"
股票价格行为关于几何布朗运动的模拟--基于中国上证综指的实证研究
",照着几何布朗运动的公式直接写代码应该就行了吧,代码逻辑都很清晰。
下面是照着这片文章模拟一次的代码,模拟多次的话,外面再套个循环应该就行了。然后再根据均方误差(一般用这个做准则的多)来挑最好的。
话说你的数据最好别是分钟或者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语言按下面编程形式将正态分布改为指数分布,画出指数分布概率密度和分布函数
如果只是画图,用curve()函数就好了
画正态密度:curve(dnorm,xlim=c(-3,3),col=2)
xlim是控制x轴显示从哪儿到哪儿,col是控制曲线颜色
画指数密度:curve(dexp(x,rate=1),xlim=c(0,5))
画指数分布:curve(pexp(x,rate=1),xlim=c(0,5))
你的方法是生成很多点x=seq(-6,6,0.1)
逐一算出函数值
t1[[i]]=dnorm(x,u[i],sigma)
t2[[i]]=pnorm(x,u[i],sigma)
最后在plot出来,用type="l"和lty=2的虚线弄出来。
curve这些功能都可以做到。
curve(dexp(x,rate=1),xlim=c(0,5),lty=2,add=T)就有虚线,
add=T可以一图多线
㈢ 怎么利用r语言做em算法估计混合双参数指数分布的数值模拟
建议你先看一下这本书:
Modeling Survival Data Using Frailty Models
chap 2. Some Parametric Methods
2.1 Introction . . . . . . . . . . . . . . . . . . . . . . . . . 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 Introction . . . . . . . . . . . . . . . . . . . . . . . . . 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"),...)
㈣ 用R语言做时间序列分析时,模型为指数时R语言怎么写
动平均法的基本原理,是通过移动平均消除时间序列中的不规则变动和其他变动,从而揭示出时间序列的长期趋势。 说指数平滑法是在移动平均法基础上发展起来的一种时间序列分析预测法,它是通过计算指数平滑值,配合一定的时间序列预测模型对现象
㈤ R语言怎么把股票日收盘价转换成对数收益率
知道一系列收盘价向量X,length=1000,求对数收益率的R语言代码
acf(int[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly
acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly
log return')
Box.test(int[,2], lag = 5, type = "Ljung-Box")
Box.test(int[,2], lag = 10, type = "Ljung-Box")
Box.test(int.l[,2], lag = 5, type = "Ljung-Box")
Box.test(int.l[,2], lag = 10, type = "Ljung-Box")
运行结错误办
> int <- read.table("d-intc7208.txt", head=T)
错误于file(file, "rt") : 打链结
外: 警告信息:
In file(file, "rt") :
打文件'd-intc7208.txt': No such file or directory
+ acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly
错误: 意外符号 in:
"
acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int"
> log return')
错误: 意外符号 in "log return"
㈥ 如何在r语言中抓取股票数据并分析论文
用quantomd包
然后getsymbols函数
分析论文 要看你研究方向
如果是看影响因素 一般回归就行
如果看股票波动和预测 可能需要时间序列
㈦ 炒股中的R指标是什么意思在哪里看啊
1、布林线上轨的高抛技巧
逢高减磅是一句比较抽象而且笼统的口头禅,而客观地、量化地“逢高”卖出才是技术分析实战技巧要解决的问题关键。而在大盘平衡市的个股轮动中,在热门股中逃顶,在波峰果断高抛,从而卖得有技术、卖得有艺术,这才是实战操盘的精华。正确利用布林线上轨高抛这一颇为直观且胜算高的指标技巧,是实战逃顶的关键。
针对三类不同走势的个股布林上轨高抛有如下博弈对策
㈧ 正在学习用R语言编写股票自动交易软件,但是对股票以及R语言都知之甚少。求高手指点。
我和你一样,也在学,大智慧新一代,通达信,和飞狐这几个你任选一个先学,以后慢慢的都会了。飞狐相对要复杂一些,要想编出功能更强大的公式,飞狐里还会用到VBS和JS脚本,还会用到C语言,别的公式不会用到这些。
㈨ 如何用R语言提取股票行情数据
你好,关于股票价格有关的开盘价格,当日最高价格,当日最低价格,收盘价格,股票交易量;和调整后的价格;
DIA.Open 当日开盘价格
DIA.High 当日最高价格
DIA.Low 当日最低价格
DIA.Close 当日收盘价格
DIA.Volume 当日股票交易量
DIA.Adjusted 当日调整后的价格
㈩ R语言如何实现y=ae^bx指数模型回归
对数转换后直接做回归