Skip to content

Commit

Permalink
Updated module for Julia v1.5 (#122)
Browse files Browse the repository at this point in the history
Co-authored-by: shivchawla <shivchawla2001@gmail.com>
Co-authored-by: Iblis Lin <iblis@hs.ntnu.edu.tw>
  • Loading branch information
3 people authored Sep 3, 2020
1 parent c32d66d commit 61a76ac
Show file tree
Hide file tree
Showing 21 changed files with 1,002 additions and 481 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.swp
docs/build
src/.rc.jl
*.cov
Manifest.toml
27 changes: 19 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: julia

os:
- osx
- linux

julia:
- 0.6
- 1.1
- 1.4
- 1.5

notifications:
email: false
Expand All @@ -19,12 +22,20 @@ branches:

script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("MarketTechnicals"); Pkg.test("MarketTechnicals", coverage=true)'
- julia --project -e 'using Pkg; Pkg.build(); Pkg.test(; coverage=true)';

after_success:
- julia -e 'Pkg.add("Documenter")'
- julia -e 'Pkg.add("MarketData")'
- julia -e 'cd(Pkg.dir("MarketTechnicals", "docs")); include("make.jl")'

- julia -e 'Pkg.add("Coverage")'
- julia -e 'cd(Pkg.dir("MarketTechnicals")); using Coverage; Codecov.submit(process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())';

jobs:
allow_failures:
- julia: nightly
include:
- stage: "Documentation"
julia: 1.5
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.instantiate();
Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=docs/ docs/make.jl
after_success: skip
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "MarketTechnicals"
uuid = "4f8c86c6-9e40-5506-9807-98571cb48bc8"

[deps]
MarketData = "945b72a4-3b13-509d-9b46-1525bb5c06de"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

41 changes: 39 additions & 2 deletions src/MarketTechnicals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,54 @@ module MarketTechnicals

using Reexport
using StatsBase
using Statistics

@reexport using TimeSeries

export sma, ema, kama, env,
bollingerbands, truerange, atr, keltnerbands, chaikinvolatility, donchianchannels,
obv, vwap, adl,
obv, vwap, adl, chaikinmoneyflow, forceindex, easeofmovement, volumepricetrend,
doji,
rsi, macd, cci, roc, adx, stochasticoscillator, chaikinoscillator, aroon,
rsi, macd, cci, roc, adx, stochasticoscillator, chaikinoscillator, aroon, vortex,
trix, massindex, dpo, kst, ichimoku, moneyflowindex, tsi, ultimateoscillator, williamsr,
awesomeoscillator,
floorpivots, woodiespivots,
typical

_nanmean(x) = mean(filter(!isnan, x))
nanmean(x; dims = 1) = ndims(x) > 1 ? mapslices(_nanmean, x, dims = dims) : _nanmean(x)

_nansum(x) = sum(filter(!isnan,x))
nansum(x; dims = 1) = ndims(x) > 1 ? mapslices(_nansum, x, dims = dims) : _nansum(x)

_nanstd(x) = std(filter(!isnan,x))
nanstd(x; dims = 1) = ndims(x) > 1 ? mapslices(_nanstd, x, dims = dims) : _nanstd(x)

function nancumsum(x)
x[isnan.(x)] .= 0
cumsum(x)
end

function nanargmax(x)
x[isnan.(x)] .= -Inf
argmax(x)
end

function nanargmin(x)
x[isnan.(x)] .= Inf
argmin(x)
end

function nanmax(x)
x[isnan.(x)] .= -Inf
maximum(x)
end

function nanmin(x)
x[isnan.(x)] .= Inf
minimum(x)
end

include("candlesticks.jl")
include("levels.jl")
include("movingaverages.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/candlesticks.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function doji(ohlc::TimeArray{T,N}; width=.01, op="Open", hi="High", lo="Low", cl="Close") where {T,N}
function doji(ohlc::TimeArray{T,N}; width=.01, op=:Open, hi=:High, lo=:Low, cl=:Close) where {T,N}
res = @. abs((ohlc[op] - ohlc[cl])) / (ohlc[hi] - ohlc[lo]) < width
TimeArray(res.timestamp, res.values, ["doji"], ohlc.meta)
TimeArray(timestamp(res), values(res), [:doji], meta(ohlc))
end

function hammer(x)
Expand Down
41 changes: 20 additions & 21 deletions src/levels.jl
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
# an idea: create one method named pivots with kwargs

doc"""
"""
floorpivots(ohlc)
Floor Trader Pivots
```math
\begin{align*}
'begin{align*}
R3 & = Pivot_t + (R2 - S1) \\
R2 & = Pivot_t + (R1 - S1) \\
R1 & = 2 Pivot_t - P^{low}_{t-1} \\
Pivot_t & = Price^{typical}_{t-1} =
\frac{P^{high}_{t-1} + P^{low}_{t-1} + P^{close}_{t-1}}{3} \\
frac{P^{high}_{t-1} + P^{low}_{t-1} + P^{close}_{t-1}}{3} \\
S1 & = 2 Pivot_t - P^{high}_{t-1} \\
S2 & = Pivot_t - (R1 - S1) \\
S3 & = Pivot_t - (R2 - S1)
\end{align*}
end{align*}'
```
"""
function floorpivots(ohlc::TimeArray{T,N}) where {T,N}

p = lag(typical(ohlc))
s1 = 2.*p .- lag(ohlc["High"])
r1 = 2.*p .- lag(ohlc["Low"])
s1 = 2 .*p .- lag(ohlc[:High])
r1 = 2 .*p .- lag(ohlc[:Low])
s2 = p .- (r1 .- s1)
r2 = (p .- s1) .+ r1
s3 = p .- (r2 .- s1)
r3 = (p .- s1) .+ r2

TimeArray(
s1.timestamp,
[s3.values s2.values s1.values p.values r1.values r2.values r3.values],
["s3", "s2", "s1", "pivot", "r1", "r2", "r3"], ohlc.meta)
timestamp(s1),
[values(s3) values(s2) values(s1) values(p) values(r1) values(r2) values(r3)],
[:s3, :s2, :s1, :pivot, :r1, :r2, :r3], meta(ohlc))

end

doc"""
"""
woodiespivots(ohlc)
Woodie's Pivot
```math
\begin{align*}
'begin{align*}
Range & = Price^{high}_{t-1} - Price^{low}_{t-1} \\
Expand All @@ -52,22 +51,22 @@ Woodie's Pivot
R2 & = Pivot_t + Range \\
R1 & = 2 Pivot_t - Price^{low}_{t-1} \\
Pivot_t & =
\frac{Price^{high}_{t-1} + Price^{low}_{t-1} + 2 Price^{open}_t}{4} \\
frac{Price^{high}_{t-1} + Price^{low}_{t-1} + 2 Price^{open}_t}{4} \\
S1 & = 2 Pivot_t - Price^{high}_{t-1} \\
S2 & = Pivot_t - Range \\
S3 & = S1 - Range \\
S4 & = S3 - Range \tag{not implemented}
\end{align*}
end{align*}'
```
"""
function woodiespivots(ohlc::TimeArray{T,N}) where {T,N}

rng = lag(ohlc["High"]) .- lag(ohlc["Low"])
rng = lag(ohlc[:High]) .- lag(ohlc[:Low])

p = (lag(ohlc["High"]) .+ lag(ohlc["Low"]) .+ 2.*ohlc["Open"]) ./ 4
s1 = 2.*p .- lag(ohlc["High"])
r1 = 2.*p .- lag(ohlc["Low"])
p = (lag(ohlc[:High]) .+ lag(ohlc[:Low]) .+ 2 .*ohlc[:Open]) ./ 4
s1 = 2 .*p .- lag(ohlc[:High])
r1 = 2 .*p .- lag(ohlc[:Low])
s2 = p .- rng
r2 = p .+ rng
s3 = s1 .- rng
Expand All @@ -76,9 +75,9 @@ function woodiespivots(ohlc::TimeArray{T,N}) where {T,N}
# r4 = r3 + range

TimeArray(
s1.timestamp,
[s3.values s2.values s1.values p.values r1.values r2.values r3.values],
["s3", "s2", "s1", "pivot", "r1", "r2", "r3"], ohlc.meta)
timestamp(s1),
[values(s3) values(s2) values(s1) values(p) values(r1) values(r2) values(r3)],
[:s3, :s2, :s1, :pivot, :r1, :r2, :r3], meta(ohlc))
end
#
# function camarillapivots{T,V}(hi::Array{SeriesPair{T,V},1},
Expand Down
Loading

0 comments on commit 61a76ac

Please sign in to comment.