_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › UPRO-TMFEWMA覲煙

譴...
譴...
譴...
譴...


EWMA Volatility #

  • EWMA: Exponentially Weighted Moving Average
  • 了 = 0.94 --> JP覈蟇伎 朱 る 企蟆 手 . 伎 螻壱 覺り讌 覘.

$$ \sigma_t^2 = (1-\lambda)\cdot\gamma_t-1^2 + \lambda\cdot\sigma_t-1^2 $$ $$ where, $$ $$ \ \ \sigma : 譴ク谿 $$ $$ \ \ \lambda: 螳譴豺 $$ $$ \ \ \gamma : 給 $$ $$ \ \ t : $$











#

#install.packages("RiskPortfolios")
library(tidyquant)
library(MTS)
library(scales)
library(qpcR)
library(TTR)

options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)
# Downloading Apple price using quantmod

ewma.func <- function(rets, lambda) {
	sig.p <- 0
	sig.s <- vapply(rets, function(r) sig.p <<- sig.p*lambda + (r^2)*(1 - lambda), 0)
	return(sqrt(sig.s))
}

cash <- 0.4

from_dt <- as.character(today()-20)
to_dt <- today()

tickers = c("UPRO", "TMF")
getSymbols(tickers, from = from_dt, to = to_dt,warnings = FALSE, auto.assign = TRUE)
#tail(UPRO)
#tail(TMF)

UPRO_sd <- sd(ewma.func(as.numeric(UPRO$UPRO.Close), 0.94))
TMF_sd <- sd(ewma.func(as.numeric(TMF$TMF.Close), 0.94))

p1 <- TMF_sd/(UPRO_sd+TMF_sd)
p2 <- UPRO_sd/(UPRO_sd+TMF_sd)
p1 <- round(p1*(1-cash),2)
p2 <- round(p2*(1-cash),2)

p3 <- 1 - (p1 + p2)
print(paste("UPRO=",percent(p1),"TMF=",percent(p2), "蠍=",percent(p3)))


蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2020-09-02 16:08:47

企 蠍 企. 願 一一 譟危讌 狩 覲旧企. (ろ)