#SPX 月次収益率統計モデル matplot predict

データの準備

TERM <- "1972::2024-02"

merge(g20=diff(cli_g20)[TERM],usa=diff(cli_usa)[TERM],g7=diff(cli_g7)[TERM])-> w
merge(w,nfci=as.vector(diff(to.monthly(NFCI)[,4])[TERM]),spx=as.vector(monthlyReturn(GSPC)[TERM])) -> w
w<-last(w,120)
# r <- (lm(w$spx ~ poly(w$nfci,3,raw=T)  + w$g20))
r <- (lm(spx ~ poly(nfci,3,raw=T)  + g20,data.frame(w)))

p1 <- as.vector(last(diff(NFCI,4)))
p2<-  as.vector(last(diff(cli_g20)))+as.vector(last(diff(diff(cli_g20))))
predict(r,newdata=data.frame(nfci=p1,g20=p2),interval='prediction',level=0.95)

cbind(w,predict=as.vector(predict(r))) -> w
r
summary(r)

# matplot(index(w),w[,5:6],type="h",lwd=2)
matplot(index(w),w[,5:6],type="h",lwd=c(3,2),lty=c(1,3))
abline(v=seq(as.Date("2013-12-15"),Sys.Date(),by='years'),lty=2)



2023/12時点での回帰分析

>   summary(r)

Call:
lm(formula = w$spx ~ poly(w$nfci, 3, raw = T) + w$g20)
Residuals:
Min 1Q Median 3Q Max
-0.084130 -0.016276 0.000481 0.018320 0.096191
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.010318 0.003118 3.309 0.001251 **
poly(w$nfci, 3, raw = T)1 -0.470390 0.056340 -8.349 1.75e-13 ***
poly(w$nfci, 3, raw = T)2 -0.201747 0.094984 -2.124 0.035811 *
poly(w$nfci, 3, raw = T)3 0.863863 0.218327 3.957 0.000132 ***
w$g20 -0.011728 0.004860 -2.413 0.017402 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03332 on 115 degrees of freedom
Multiple R-squared: 0.4405, Adjusted R-squared: 0.421
F-statistic: 22.63 on 4 and 115 DF, p-value: 8.307e-14

当該月データの推計

# composite leading indicator の推計
p2 <- last(w$g20) + last(diff(w$g20))
last(w$g20) + last(diff(w$g20))
# NFCI の推計
p1 <- last(diff(NFCI,4))
last(diff(NFCI,4))
r$coefficients[1] + r$coefficients[2]*p1 +r$coefficients[3]*p1**2 + r$coefficients[4] * p1**3 + r$coefficients[5]* p2



この記事が気に入ったらサポートをしてみませんか?