Skip to content

Commit

Permalink
Merge b02f9f6 into 84078b8
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed May 14, 2017
2 parents 84078b8 + b02f9f6 commit a56ab9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ Commodity Channel Index
```math
CCI = \frac{P_{typical} - SMA(P_{typical})}{c \times \sigma(P_{typical})}
```
**Reference**
- https://en.wikipedia.org/wiki/Commodity_channel_index
"""
function cci{T,N}(ohlc::TimeArray{T,N}, ma::Int=20, c::Float64=0.015)
res = moving(typical(ohlc), mean_abs_dev, ma) ./ c
rename(res, "cci")
function cci{T,N}(ohlc::TimeArray{T,N}, ma::Int=20, c::AbstractFloat=0.015)
pt = typical(ohlc)
cci = ((pt .- sma(pt, ma)) ./ moving(pt, mean_abs_dev, ma)) ./ c
rename(cci, "cci")
end

doc"""
Expand Down
8 changes: 5 additions & 3 deletions test/momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ facts("Momentum") do
end

context("cci") do
@fact cci(ohlc).values[1] --> roughly(360.765, atol=01) # TTR::CCI value is -38.931614
@fact cci(ohlc).values[end] --> roughly(44.651, atol=.01) # TTR::CCI value is 46.3511339
@fact cci(ohlc).timestamp[end] --> Date(2001,12,31)
# TTR::CCI value is -38.931614
@fact cci(ohlc).values[1] --> roughly(-38.931614, atol=01)
# TTR::CCI value is 46.3511339
@fact cci(ohlc).values[end] --> roughly(46.3511339, atol=.01)
@fact cci(ohlc).timestamp[end] --> Date(2001, 12, 31)
end
end

0 comments on commit a56ab9b

Please sign in to comment.