テクニカル分析 MACD(Moving Average Convergence and Divergence)

Equation
n日指数平滑移動平均線
Y_{t}
=\alpha X_{t}+(1-\alpha)Y_{t-1}
=\alpha X_{t}+(1-\alpha)(\alpha X_{t-1}+(1-\alpha)Y_{t-2})
=\alpha X_{t}+(1-\alpha)(\alpha X_{t-1}+(1-\alpha)(\alpha X_{t-2}+(1-\alpha)Y_{t-3}))
\vdots
=\sum^{\infty}_{i=0} X_{t-i}(1-\alpha)^{i}\alpha,\;\alpha=2/(n+1)

m日指数平滑移動平均線
Z_{t}
=\beta X_{t}+(1-\beta)Z_{t-1}
=\beta X_{t}+(1-\beta)(\beta X_{t-1}+(1-\beta)Z_{t-2})
=\beta X_{t}+(1-\beta)(\beta X_{t-1}+(1-\beta)(\beta X_{t-2}+(1-\beta)Z_{t-3}))
\vdots
=\sum^{\infty}_{i=0} X_{t-i}(1-\beta)^{i}\beta,\;\beta=2/(m+1),\;m>n

\textup{MACD}_{t}=Y_{t}-Z_{t}

S_{t}=\sum^{t-8}_{s=t}\textup{MACD}_{s}/9

R
nikkeimacd

> library(TTR)

> nikkei <- dataset$close

> nikkeimacd <- MACD(nikkei,nFast=12,nSlow=26,nSig=9,maType="EMA",percent=FALSE)

> summary(nikkeimacd)
      macd             signal       
 Min.   :-376.46   Min.   :-289.53  
 1st Qu.: -75.80   1st Qu.: -61.27  
 Median :  20.01   Median :  16.87  
 Mean   :  39.73   Mean   :  40.33  
 3rd Qu.: 166.35   3rd Qu.: 169.16  
 Max.   : 616.29   Max.   : 539.65  
 NA's   :25        NA's   :33       

 > attributes(nikkeimacd)
$dim
[1] 793   2

$dimnames
$dimnames[[1]]
NULL

$dimnames[[2]]
[1] "macd"   "signal"


> par(mfrow=c(2,1))

> plot(nikkei,main="Nikkei,Close,2011/1/4-2014/3/26",ylab="JPY",type="l")

> plot(nikkeimacd[,1],type="h",main="MACD,Nikkei,Close,2011/1/4-2014/3/26",ylab="Oscillator")

参考文献
熊谷悦生、舟尾暢男(2008).『Rで学ぶデータマイニング Ⅱシミュレーション編』.オーム社.248pp.

アプリケーション
R Core Team (2013). R: A language and environment for statistical computing.
R Foundation for Statistical Computing, Vienna, Austria.
URL http://www.R-project.org/.