Volatility
ATR
MarketTechnicals.atr
— Functionatr(ohlc::TimeArray, n = 14; h= :High, l= :Low, c = :Close)
Average True Range
It's the exponential moving average of truerange
Formula
\[\text{ATR} = \text{EMA}(\text{TR}, n)\]
julia> atr(ohlc)
486×1 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-24 to 2001-12-31
│ │ atr │
├────────────┼────────┤
│ 2000-01-24 │ 8.3436 │
│ 2000-01-25 │ 8.5147 │
│ 2000-01-26 │ 8.2237 │
│ 2000-01-27 │ 8.0649 │
│ 2000-01-28 │ 8.2217 │
│ 2000-01-31 │ 8.3044 │
│ 2000-02-01 │ 8.0684 │
│ 2000-02-02 │ 7.8578 │
│ 2000-02-03 │ 7.6851 │
⋮
│ 2001-12-19 │ 1.02 │
│ 2001-12-20 │ 1.0185 │
│ 2001-12-21 │ 1.0079 │
│ 2001-12-24 │ 0.9752 │
│ 2001-12-26 │ 0.9884 │
│ 2001-12-27 │ 0.9721 │
│ 2001-12-28 │ 0.977 │
│ 2001-12-31 │ 0.9665 │
Bollinger Bands
MarketTechnicals.bollingerbands
— Functionbollingerbands(ta::TimeArray, ma=20, width=2.0)
Bollinger Bands
Formula
\[\begin{align*} \text{Up} & = \text{SMA} + \text{width} \times \sigma(P) \\ \text{Mean} & = \text{SMA} \\ \text{Down} & = \text{SMA} - \text{width} \times \sigma(P) \end{align*}\]
julia> bollingerbands(cl)
481×3 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-31 to 2001-12-31
│ │ up │ down │ mean │
├────────────┼──────────┼─────────┼──────────┤
│ 2000-01-31 │ 117.3251 │ 89.3939 │ 103.3595 │
│ 2000-02-01 │ 116.2242 │ 89.3258 │ 102.775 │
│ 2000-02-02 │ 116.1505 │ 89.0305 │ 102.5905 │
│ 2000-02-03 │ 116.105 │ 89.007 │ 102.556 │
│ 2000-02-04 │ 116.4873 │ 89.9247 │ 103.206 │
│ 2000-02-07 │ 117.9014 │ 89.9666 │ 103.934 │
│ 2000-02-08 │ 119.2289 │ 90.3521 │ 104.7905 │
│ 2000-02-09 │ 119.4875 │ 92.0805 │ 105.784 │
│ 2000-02-10 │ 118.2181 │ 95.9809 │ 107.0995 │
⋮
│ 2001-12-19 │ 23.3847 │ 19.3273 │ 21.356 │
│ 2001-12-20 │ 23.3129 │ 19.4981 │ 21.4055 │
│ 2001-12-21 │ 23.2433 │ 19.6837 │ 21.4635 │
│ 2001-12-24 │ 23.2429 │ 19.6831 │ 21.463 │
│ 2001-12-26 │ 23.2546 │ 19.7204 │ 21.4875 │
│ 2001-12-27 │ 23.2918 │ 19.8372 │ 21.5645 │
│ 2001-12-28 │ 23.3476 │ 19.9824 │ 21.665 │
│ 2001-12-31 │ 23.3718 │ 20.0182 │ 21.695 │
Chaikin Volatility
MarketTechnicals.chaikinvolatility
— Functionchaikinvolatility(ta, n = 10, p = 10; h = High, l = :Low)
Chaikin Volatility
Arguments
n
is the smooth periodp
is the previous period
Formula
\[\text{Chaikin Vola} = \frac{\text{EMA}(P^\text{High}_t - P^\text{Low}_t, n) - \text{EMA}(P^\text{High}_{t-p} - P^\text{Low}_{t-p}, n)} {\text{EMA}(P^\text{High}_{t-p} - P^\text{Low}_{t-p}, n)} \times 100\]
References
julia> chaikinvolatility(ohlc)
481×1 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-31 to 2001-12-31
│ │ chaikinvolatility │
├────────────┼───────────────────┤
│ 2000-01-31 │ -2.2401 │
│ 2000-02-01 │ -3.2901 │
│ 2000-02-02 │ -3.4767 │
│ 2000-02-03 │ -12.7455 │
│ 2000-02-04 │ -5.0588 │
│ 2000-02-07 │ -2.2411 │
│ 2000-02-08 │ -15.7427 │
│ 2000-02-09 │ -13.3072 │
│ 2000-02-10 │ -16.8273 │
⋮
│ 2001-12-19 │ -14.5449 │
│ 2001-12-20 │ -19.2088 │
│ 2001-12-21 │ -16.5194 │
│ 2001-12-24 │ -17.97 │
│ 2001-12-26 │ -15.0247 │
│ 2001-12-27 │ -13.2106 │
│ 2001-12-28 │ -10.9081 │
│ 2001-12-31 │ -7.6953 │
Donchian Channels
MarketTechnicals.donchianchannels
— Functiondonchianchannels(ohlc::TimeArray, n = 20; h = :High, l = :Low)
Donchian Channels
Formula
\[\begin{align*} \text{Up} & = \max(P_1^\text{High}, \dots, P_t^\text{High}) \\ \text{Mid} & = \frac{\text{Up} + \text{Down}}{2} \\ \text{Down} & = \min(P_1^\text{Low}, \dots, P_t^\text{Low}) \end{align*}\]
References
julia> donchianchannels(ohlc)
481×3 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-31 to 2001-12-31
│ │ up │ mid │ down │
├────────────┼───────┼────────┼───────┤
│ 2000-01-31 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-01 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-02 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-03 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-04 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-07 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-08 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-09 │ 121.5 │ 104.0 │ 86.5 │
│ 2000-02-10 │ 121.5 │ 107.0 │ 92.5 │
⋮
│ 2001-12-19 │ 24.03 │ 21.645 │ 19.26 │
│ 2001-12-20 │ 24.03 │ 21.8 │ 19.57 │
│ 2001-12-21 │ 24.03 │ 21.955 │ 19.88 │
│ 2001-12-24 │ 24.03 │ 22.06 │ 20.09 │
│ 2001-12-26 │ 24.03 │ 22.06 │ 20.09 │
│ 2001-12-27 │ 24.03 │ 22.06 │ 20.09 │
│ 2001-12-28 │ 24.03 │ 22.06 │ 20.09 │
│ 2001-12-31 │ 24.03 │ 22.06 │ 20.09 │
Keltner Bands
MarketTechnicals.keltnerbands
— Functionkeltnerbands(ohlc, n = 20, w = 2; h = :High, l = :Low, c = :Close)
Keltner Channels
Linda Bradford Raschke introduced the newer version of Keltner Channels in the 1980s. We implement the newer version.
Formula
\[\begin{align*} \text{Up} & = \text{Mid} + w \times \text{ATR}(n) \\ \text{Mid} & = \text{EMA}(P^{typical}, n) \\ \text{Down} & = \text{Mid} - w \times \text{ATR}(n) \end{align*}\]
References
julia> keltnerbands(ohlc)
480×3 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-02-01 to 2001-12-31
│ │ kup │ kma │ kdn │
├────────────┼──────────┼──────────┼─────────┤
│ 2000-02-01 │ 119.9312 │ 103.6682 │ 87.4052 │
│ 2000-02-02 │ 119.215 │ 103.2532 │ 87.2913 │
│ 2000-02-03 │ 118.899 │ 103.1913 │ 87.4835 │
│ 2000-02-04 │ 119.1651 │ 103.5737 │ 87.9823 │
│ 2000-02-07 │ 119.9635 │ 104.3207 │ 88.6779 │
│ 2000-02-08 │ 120.5981 │ 105.2504 │ 89.9028 │
│ 2000-02-09 │ 121.1377 │ 106.0894 │ 91.0412 │
│ 2000-02-10 │ 121.38 │ 106.6962 │ 92.0123 │
│ 2000-02-11 │ 121.583 │ 107.0464 │ 92.5097 │
⋮
│ 2001-12-19 │ 23.0157 │ 20.9971 │ 18.9785 │
│ 2001-12-20 │ 23.0074 │ 20.9898 │ 18.9721 │
│ 2001-12-21 │ 23.0053 │ 21.0015 │ 18.9978 │
│ 2001-12-24 │ 22.9825 │ 21.0239 │ 19.0653 │
│ 2001-12-26 │ 23.0596 │ 21.0829 │ 19.1063 │
│ 2001-12-27 │ 23.1209 │ 21.1671 │ 19.2133 │
│ 2001-12-28 │ 23.2507 │ 21.2905 │ 19.3304 │
│ 2001-12-31 │ 23.3156 │ 21.3705 │ 19.4254 │
TR
MarketTechnicals.truerange
— Functiontruerange(ohlc::TimeArray; h = :High, l = :Low, c = :Close)
True Range
Formula
\[\text{TR} = \max (P_t^\text{High}, P_{t-1}^\text{Close}) - \min (P_t^\text{Low}, P_{t-1}^\text{Close})\]
julia> truerange(ohlc)
499×1 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-04 to 2001-12-31
│ │ tr │
├────────────┼───────┤
│ 2000-01-04 │ 10.75 │
│ 2000-01-05 │ 8.06 │
│ 2000-01-06 │ 12.0 │
│ 2000-01-07 │ 6.0 │
│ 2000-01-10 │ 7.5 │
│ 2000-01-11 │ 8.88 │
│ 2000-01-12 │ 9.0 │
│ 2000-01-13 │ 11.56 │
│ 2000-01-14 │ 5.5 │
⋮
│ 2001-12-19 │ 1.21 │
│ 2001-12-20 │ 1.0 │
│ 2001-12-21 │ 0.87 │
│ 2001-12-24 │ 0.55 │
│ 2001-12-26 │ 1.16 │
│ 2001-12-27 │ 0.76 │
│ 2001-12-28 │ 1.04 │
│ 2001-12-31 │ 0.83 │