728x90
library(TTR)
my.EnvelopeIndicator<-function(data, m=10, p=0.03){
return(matrix(SMA(data, n=m) %>% {c( rep(.[m], m-1), .[which(is.na(.)==F)])})%*%c(1-p,1,1+p))
}
df_env<-as.data.frame(my.EnvelopeIndicator(res$openingPrice, m=5, p=0.03))
names(df_env)<-c("env_lower","env","env_upper")
res<-cbind(res, df_env)
head(res)
my.BBands<-function(data, m=20, std=1, hlc_c=c("highPrice","lowPrice","tradePrice")){
return(BBands(data[, c(hlc_c[1],hlc_c[2],hlc_c[3])], n=m, sd=std)[,c(1,2,3)] %>% {rbind(matrix(rep(.[m,], m-1), ncol=3, byrow=T),.[m:nrow(.),])})
}
df_bbands<-as.data.frame(my.BBands(data=res, m=40, std=3))
res<-cbind(res,df_bbands)
# res<-res[,c(1:16)]
# str(res)
'정리 > 코드' 카테고리의 다른 글
Reload on code changes in python (0) | 2022.10.08 |
---|---|
ggplot2 그래프 화면 분할 코드 (0) | 2018.10.30 |