Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated module for Julia v1.5 #122

Merged
merged 27 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a5e63d
Updated for changes in TimeSeries (latest)
shivchawla May 6, 2019
5366bc2
Updated for latest TS
shivchawla May 6, 2019
fd97328
Added in wrong folder
shivchawla May 6, 2019
11f49d7
Added in wrong folder
shivchawla May 6, 2019
e9a4857
Added in wrong folder
shivchawla May 6, 2019
3452926
Added in wrong folder
shivchawla May 6, 2019
8c6a1fe
Added in wrong folder
shivchawla May 6, 2019
ea351ef
Added in wrong folder
shivchawla May 6, 2019
4f6ca46
Added in wrong folder
shivchawla May 6, 2019
1778135
Updated Require (Julia 1.0 and TS-v0.14)
shivchawla May 6, 2019
f4baab1
Delete MarketTechnicals.jl
shivchawla May 6, 2019
c389048
Updated code to TimeSeries v0.14 and bug fixes
shivchawla Aug 1, 2019
e11a898
Merge branch 'master' into master
shivchawla Aug 1, 2019
0762418
Added Manifest.toml, Added Project.toml, Deleted REQUIRE
astadmistry Sep 3, 2020
e1b6b8f
Added Statistics as a dependency
astadmistry Sep 3, 2020
4a5d08a
Updated travis to use julia 1.5 instead of julia 0.6
astadmistry Sep 3, 2020
b1f253d
Pkg.clone depreciated. Replaced with Pkg.add
astadmistry Sep 3, 2020
5517b79
Updated travis, Fixed type error in utilities, Added MarketData to de…
astadmistry Sep 3, 2020
0471c24
Updated travis
astadmistry Sep 3, 2020
0d34ba1
Apply suggestions from code review
iblislin Sep 3, 2020
ef58e31
Deleted Manifest.toml
astadmistry Sep 3, 2020
1f5ff3d
Merge branch 'master' of github.com:astadmistry/MarketTechnicals.jl
astadmistry Sep 3, 2020
09b4141
Update .travis.yml
astadmistry Sep 3, 2020
80e9311
Merge branch 'master' of github.com:astadmistry/MarketTechnicals.jl
astadmistry Sep 3, 2020
65c3d1c
Updated minimum supported version from julia 1.0 to julia 1.1
astadmistry Sep 3, 2020
d5378c0
Added Documenter as a dependency
astadmistry Sep 3, 2020
b2a3880
Update Project.toml
iblislin Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "MarketTechnicals"
uuid = "4f8c86c6-9e40-5506-9807-98571cb48bc8"

[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
iblislin marked this conversation as resolved.
Show resolved Hide resolved
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*}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I will file the doc rendering issue as another issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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