[英]convert log returns to actual price of a time series forecast using R
I have this simulated data and i fitted the ARMA-GARCH model using rugarch package. 我得到了这些模拟数据,并使用rugarch软件包拟合了ARMA-GARCH模型。 My code so far as follows,
到目前为止,我的代码如下:
ar.sim<-arima.sim(model=list(ar=c(.9,-.2),ma=c(-.7,.1)),n=100)
logr=diff(log(na.omit(ar.sim)))
require(rugarch)
gar<-ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 1)),
distribution.model = "norm");
fitg=ugarchfit(spec = gar,data = ar.sim,solver = "hybrid");
ugarchforecast(fitg,n.ahead =10)
In this model , i used log returns . 在此模型中,我使用了日志返回。 So my forecast also based on log returns.
因此,我的预测也基于对数回报。 But i need the actual price.
但是我需要实际价格。 I googled to find any R function that convert this log return to actual price.
我用谷歌搜索找到了任何R函数,可以将此日志返回值转换为实际价格。 But i couldn't find any.
但是我找不到任何东西。
Is there any function in R to extract the actual price from this log return of do i need to do that manually ? R中有任何函数可以从此日志返回值中提取实际价格吗,我需要手动执行此操作吗?
The price should be [initial price] * exp(cumulative log returns). 价格应为[初始价格] * exp(累计对数收益)。 For example:
例如:
df <- data.frame(price = c(90, 108, 81, 105, 180))
df$log = log(df$price)
df$logr = c(NA, diff(df$log))
df$logr_na0 = ifelse(is.na(df$logr), 0, df$logr)
df$cuml_log= cumsum(df$logr_na0)
df$reconstructed_price_norm = exp(df$cuml_log)
initial_price <- 90
df$reconstructed_price = initial_price * df$reconstructed_price_norm
output 产量
> df
price log logr logr_na0 cuml_log reconstructed_price_norm reconstructed_price
1 90 4.499810 NA 0.0000000 0.0000000 1.000000 90
2 108 4.682131 0.1823216 0.1823216 0.1823216 1.200000 108
3 81 4.394449 -0.2876821 -0.2876821 -0.1053605 0.900000 81
4 105 4.653960 0.2595112 0.2595112 0.1541507 1.166667 105
5 180 5.192957 0.5389965 0.5389965 0.6931472 2.000000 180
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.