Git Product home page Git Product logo

indicators.jl's Introduction

Build Status Coverage Status codecov.io

Indicators

Indicators is a Julia package offering efficient implementations of many technical analysis indicators and algorithms. This work is inspired by the TTR package in R and the Python implementation of TA-Lib, and the ultimate goal is to implement all of the functionality of these offerings (and more) in Julia. This package has been written to be able to interface with both native Julia Array types, as well as the TS time series type from the Temporal package. Contributions are of course always welcome for wrapping any of these functions in methods for other types and/or packages out there, as are suggestions for other indicators to add to the lists below.

Implemented

Moving Averages

  • SMA (simple moving average)
  • WMA (weighted moving average)
  • EMA (exponential moving average)
  • TRIMA (triangular moving average)
  • KAMA (Kaufman adaptive moving average)
  • MAMA (MESA adaptive moving average, developed by John Ehlers)
  • HMA (Hull moving average)
  • ALMA (Arnaud-Legoux moving average)
  • SWMA (sine-weighted moving average)
  • DEMA (double exponential moving average)
  • TEMA (triple exponential moving average)
  • ZLEMA (zero-lag exponential moving average)
  • MMA (modified moving average)
  • VWMA (volume-weighted moving average)
  • MLR (moving linear regression)
    • Prediction
    • Slope
    • Intercept
    • Standard error
    • Upper & lower bound
    • R-squared

Momentum Indicators

  • Momentum (n-day price change)
  • ROC (rate of change)
  • MACD (moving average convergence-divergence)
  • RSI (relative strength index)
  • ADX (average directional index)
  • Heikin-Ashi (Heiken Ashi)
  • Parabolic SAR (stop and reverse)
  • Fast & slow stochastics
  • SMI (stochastic momentum indicator)
  • KST (Know Sure Thing)
  • Williams %R
  • CCI (commodity channel index)
  • Donchian channel
  • Ichimoku Kinko Hyo
  • Aroon indicator + oscillator

Volatility Indicators

  • Bollinger Bands
  • Average True Range
  • Keltner Bands

Other

  • Rolling/running mean
  • Rolling/running standard deviation
  • Rolling/running variance
  • Rolling/running covariance
  • Rolling/running correlation
  • Rolling/running maximum
  • Rolling/running minimum
  • Rolling/running MAD (mean absolute deviation)
  • Rolling/running quantiles

Wish List

To-Do

  • Hamming moving average
  • VWAP (volume-weighted average price)
  • EVWMA (elastic, volume-weighted moving average)
  • VMA (variable-length moving average)
  • Chaikin Money Flow
  • Ultimate Oscillator
  • OBV (on-balance volume)
  • Too many more to name...always happy to hear suggestions though!

Done

  • Moving Linear Regression
  • KAMA (Kaufman adaptive moving average)
  • DEMA (double exponential moving average)
  • TEMA (tripe exponential moving average)
  • ALMA (Arnaud Legoux moving average)
  • Parabolic SAR
  • Williams %R
  • KST (know sure thing)
  • CCI (commodity channel index)
  • ROC (rate of change)
  • Momentum
  • Donchian Channel
  • Aroon Indicator / Aroon Oscillator
  • Stochastics
    • Slow Stochastics
    • Fast Stochastics
    • Stochastic Momentum Index
  • MMA (modified moving average)
  • ZLEMA (zero lag exponential moving average)
  • VWMA (volume-weighted moving average)

Examples

Randomly generated data:

alt text

Apple (AAPL) daily data from 2015:

alt text

Corn futures daily data

alt text

Gold Futures Moving Regression

alt text

indicators.jl's People

Contributors

balupton avatar bapi-reddy avatar dysonance avatar femtotrader avatar ghtaarn avatar jamosaa avatar juliatagbot avatar sairus7 avatar staticfloat avatar tkelman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

indicators.jl's Issues

TimeSeries not supported directly

I wrote some wrappers for the indicators in this package taking in TimeArray arguments for my work, which uses the TimeSeries.jl package. I think it would be helpful for some people if these wrappers were available as part of the package: if desired, I can submit a PR.

Functions that depend on `wma` don't work with `Float32` arrays

Indicators.hma(Float64.(.1:.1:10.0)) works, but Indicators.hma(Float32.(.1:.1:10.0)) throws a dispatch error when it calls wma.

I think this is because the wma is defined, both the input and weight array are of type T<:Real. By default wma's weight array will be a Float64 array, forcing the input array to also be Float64. With financial data we might sometimes want to work with Float32 or other real number types.

I think it is as simple as changing this:
function wma(x::AbstractArray{T}; n::Int64=10, wts::AbstractArray{T}=collect(1:n)/sum(1:n)) where {T<:Real}

to this:
function wma(x::AbstractArray{T}; n::Int64=10, wts::AbstractArray{W}=collect(1:n)/sum(1:n)) where {T<:Real, W<:Real}

which would allow x to be a type different from wts.

Is Heikin Ashi calculation correct?

Please refer to: https://www.mssqltips.com/sqlservertip/7230/build-heikin-ashi-charts-in-excel-based-on-financial-time-series-data/

HA_close = (open_current + high_current + low_current + close_current)/4
HA_open = (HA_open_prior + HA_close_prior)/2
HA_high = maximum of (high_current, HA_open_current, or HA_close_current)
HA_low = minimum of (low_current, HA_open_current, or HA_close_current)

The hao is calculated as average of previous Heikin Ashi Open and Close, not the original OHLC data.

hac = mean(matr; dims=2)
hao = Vector{Float64}(undef, length(hac))
hao[1] = open[1]
for i=2:length(hac)
hao[i] = (hao[i-1]+hac[i-1])/2
end
hah = max.(hao, hac, matr[:,2])
hal = min.(hao, hac, matr[:,3])

Deprecated syntax `@doc call with ->`

Hello @dysonance ,

Running tests displays

┌ Warning: Deprecated syntax `@doc call with ->` at /Users/femto/.julia/packages/Indicators/rjUJD/src/run.jl:19.
│ Use `a line break` instead.
└ @ ~/.julia/packages/Indicators/rjUJD/src/run.jl:19

Best regards

`ERROR: MethodError: no method matching !(::BitVector)

Hi

I see the below error:

ERROR: MethodError: no method matching !(::BitVector) Closest candidates are: !(::Function) at /Applications/[Julia-1.7.app/Contents/Resources/julia/share/julia/base/operators.jl:1117](http://julia-1.7.app/Contents/Resources/julia/share/julia/base/operators.jl:1117) !(::VectorizationBase.AbstractSIMD{<:Any, <:Union{Bool, SIMDTypes.Bit}}) at ~/.julia/packages/VectorizationBase/0i42N/src/base_defs.jl:359 !(::Temporal.TS) at ~/.julia/packages/Temporal/DkX3V/src/calc/operations.jl:119

Fixed it by:

trendy.jl

crit[idx[.!minima(x[crit], threshold=threshold)]] .= false

hope it helps!

thanks

Incompatible with other packages

hey mate, it appears that installing Indicators downgrades HTTP. Can you please help with this

⌅ [cd3eb016] ↓ HTTP v1.5.5 ⇒ v0.9.17

ta!

Feature Request: Exponentially Weighted Running/Rolling Statistics

Indicators already has rolling and running (expanding) stats, but having exponentially weighted versions of these would be useful to calculate things like exponentially weighted standard deviation and all the other rolling statistics.

Having access to this functionality (as in pandas ewm) would be useful because exponentially weighted stats have less lag than simple moving or expanding windows.

Discussion for integration with `TSFrame`

TSFrames.jl is DataFrames.jl optimised for time-series functionalities. I feel it is pre-eminent time series data structure in Julia, as being a thin wrapper around DataFrames.jl is a huge benefit given the large community support for that package.

I am planning to use both Indicators and TSFrames for my work, and I've started building the wrappers to use the algorithms in Indicators on TSFrame structures. Currently planning to send PR as a package extension to TSFrames.jl. issue, PR.

This is an appropriate use case of the Julia 1.9+ package extension functionalities. But im not sure which package should be weak dependency of the other? Since I'm extending methods of this package dispatched on struct from another, Indicators could add TSFrames as weak dependency.

I'm wondering if its a good idea and there is consensus for adding it as a feature/extension in Indicators.jl, similar to the integration with Temporal.jl here. Although I'm not convinced these should be full dependencies. What are the community thoughts?

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Adding support for TimeSeries

Do you think it's good idea to add support for TimeSeries (in addition to TS)? I am using TimeSeries and I want to use this library directly with TimeSeries.

BigFloat support

Provide generic functions to be able to used by other numeric types like BigFloat.

Simple Moving Average with the end points

Is it possible to include a keyword argument to calculate the sma with the end points?

So for an array $y_t$, let $\beta_t$ be the moving average defined as

$$\begin{align} \beta_{t = 1} &= \frac{1}{2}(y_1 + y_2) \\\ \beta_{1 < t < T} &= \frac{1}{3}(y_{t - 1} + y_t + y_{t + 1}) \\ \beta_{t = T} &= \frac{1}{2}(y_{T- 1} + y_{T}) \end{align}$$

No support for HTTP >1 due to Temporal.jl

Indicators.jl is great, but unfortunately is it inconvenient to use, as the dependency Temporal.jl is not supporting HTTP > 1.

Is Indicators.jl and Temporal.jl still maintained?
In case you need help, I am willing to contribute. There is already a PR (dysonance/Temporal.jl#52) but not sure if just bumping up the HTTP version in the .toml file is enough.

No matching signature

Hi there, I'm attempting something simple with Julia 0.7 and a Temporal import (I'm very new to all of this):

filename = "../homedepot.csv"
candles = tsread(filename)
sma(candles[:High], 10)

This gives me an error:

ERROR: LoadError: MethodError: no method matching sma(::Temporal.TS{Float64,Dates.Date}, ::Int64)
Closest candidates are:
sma(::Temporal.TS{V,T}; args...) where {V, T} at ....

What might I be doing wrong? Thanks!

Running Regression Support x,y input

Right now it regresses x as some index and y the dependent y::Array{Float64} input.

If I wanted to a run a regression between two variables, well I guess could change the xi part of the function to accept an Array input for x.

Lets say VIX and ES mini are sorted per date and want to find a rolling regression between ES / VIX (x,y)

Or in co-integration pairs trading, One may wish to run a rolling linear regression between Stock A / B. One as x,y independent/dependent variables.

An ADF test would be fantastic also :)

Great work. I just found Julia a few days ago and liking this package as I was familiar with TTR.

Support views

hi, Any idea why this package does not support views? it would help a lot reduce memory usage

Thanks!

hurst and runmad slow

hi

thanks for putting together this package. I run a series of technical analysis on stocks. If I run without hurst and runmap, it comes out to 4 seconds for 50 stocks, however, if I add these both, the time increases to 35 seconds!

I am using Julia 1.5 and the latest version of indicators

I am afraid I cant seem to print the profile trace. the issue seems to be:

function estimate_hurst(x::Array{T}; intercept::Bool=false)::T where {T<:Real} RS = genrsdata(x)
rsdata = [rsdata; genrsdata(a)] rsdata = [rsdata; genrsdata(b)]

Also, I noticed that if I replace the Close with the below, it now takes close to 9 seconds!

Close = 100.0 .+ cumsum(randn(n))
Any thoughts please?

thanks
Roh

John Ehlers Indicators - Cycle Analytics for Traders

Hey!

Sorry been neck deep in projects. Working on John Ehlers indicators from his latest book. Here are a few to get started:

# Supersmoother
# Equation 3-3
function supersmoother(x::Array{Float64}; n::Int64=10)::Array{Float64}
a = exp(-1.414*3.14159 / n)
b = 2 * a * cosd(1.414 * 180 / n)
c2 = b
c3 = -a * a
c1 = 1 - c2 - c3
@assert n<size(x,1) && n>0 "Argument n out of bounds."
Super = zeros(x)
 @inbounds for i = 3:length(x)
Super[i] = c1 * (x[i] + x[i-1]) / 2 + c2 * Super[i-1] + c3 * Super[i-2]
end
return Super
end
# Decycler 4-1
function decycler(x::Array{Float64}; n::Int64=60)::Array{Float64}
    @assert n<size(x,1) && n>0 "Argument n out of bounds."
#Highpass filter cyclic components whose periods are shorter than “cutoff” bars
alpha1 = ((cosd(360 / n) + sind(360 / n) - 1)) / (cosd(360 / n))
Decycle = zeros(x)
 @inbounds for i in 2:length(x)
     Decycle[i] = (alpha1 / 2)*(x[i] + x[i-1]) + (1- alpha1)*Decycle[i-1]
end
return Decycle
end
# Decyler Oscillator 4-2
function Decycle_OSC(x::Array{Float64}; n1::Int64=30, n2::Int64=60)::Array{Float64}
        @assert n2<size(x,1) && n2>0 "Argument n out of bounds."
alpha1 = (cosd(.707*360 / n1) + sind(.707*360 / n1) - 1) / cosd(.707*360 / n1)
alpha2 = (cosd(.707*360 / n2) + sind(.707*360 / n2) - 1) / cosd(.707*360 / n2)
HP1 = zeros(x)
HP2 = zeros(x)
Decycle_OSC = zeros(x)
@inbounds for i in 3:length(x)
HP1[i] = (1 - alpha1 / 2)*(1 - alpha1 / 2)*(x[i] - 2*x[i-1] + x[i-2]) + 2*(1 - alpha1)*HP1[i-1] - (1 - alpha1)* (1 - alpha1)*HP1[i-2]
HP2[i] = (1 - alpha2 / 2)*(1 - alpha2 / 2)*(x[i] - 2*x[i-1] + x[i-2]) + 2*(1 - alpha2)*HP2[i-1] - (1 - alpha2)*(1 - alpha2)*HP2[i-2]
end
Decycle_OSC .= HP2 .- HP1
return Decycle_OSC
end

When I get a chance I will take a look at the other implementations you made for the RS hurst. Ehlers has a hurst function which is also interesting and maybe of more value than the RS method.

More to come!

Not working with Julia 1.2.0

Try to run the examples not working:

  • first complain Dates is Undefined after adjusted using Base.Dates to using Dates passed
  • then complain srand() Undefined, removed it passed
  • then got following error otuput

MethodError: no method matching +(::Float64, ::Array{Float64,1})
Closest candidates are:
+(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529
+(::Float64, !Matched::Float64) at float.jl:395
+(!Matched::PyCall.PyObject, ::Any) at /home/steve/.julia/packages/PyCall/ttONZ/src/pyoperators.jl:13
...

Stacktrace:
[1] top-level scope at In[5]:8

rolling regressions

could you show some example codes of computing rolling regressions in your document?

Rolling autocorrelation

This is the shell of an idea. Not wrapped in a clean function. It has demean. Function would include demean=true,false

Rolling Autocorrelation

Sliding window (k width)

mean_out = zeros(size(d_es_close,1))
var_out = zeros(size(d_es_close,1))
cov_out = zeros(size(d_es_close,1))
autocor_out = zeros(size(d_es_close,1))
devmean_out = zeros(size(d_es_close,1))
n=1000
k = 1 # set lag
n_lag = 100 # return series lag

Calculate bar return series

rets = zeros(size(d_es_close,1))
for i in n_lag+1:length(d_es_close)
rets[i] = ((d_es_close[i] / d_es_close[i-n_lag])-1) # rets[i] = ((d_es_close[i] / d_es_close[i-n_lag+1])-1)
end

lag the series by k

lagged_series = [fill(0,k); rets[1:end-k]]

Calculate the mean of the rolling sample

for i = n:size(rets,1)
mean_out[i] = mean(rets[i-n+1:i])
end

Calculate deviations from the mean

for i = n:size(rets,1)
devmean_out[i] = rets[i] - mean_out[i]
end

Calculate rolling variance

for i = n:size(rets,1)
var_out[i] = var(rets[i-n+1:i])
end

Calculate rolling covariance

for i = n:size(rets,1)
if i+k >= size(rets,1)
break
end
cov_out[i] = cov(rets[i-n+1:i],lagged_series[i-n+1:i])
end

Rolling Autocorrelation

for i =n:size(rets,1)
autocor_out[i] = cov_out[i] / var_out[i]
end

It's simply the covariance of the series and some lag of itself / variance.

Il see if I can wrap it in a clean function when I get a chance!

Running Statistics Are Slow

Hello,

I just wish to report that Running Statistics of this library are super slow.

On an array of 4000 elements:
Running Correlation of Indicators.jl takes: 0.085305 seconds
Running Correlation of TA-lib takes: 0.000577 seconds

In my application, I loop hundreds of times over running statistics, thus the difference in speed has an impact on the overall performance.

I thought Indicators.jl is faster since it is written in Julia and does not use wrappers like TA-lib do.

Thank you!

Indicators RSI is not like Talib RSI

RSI from Indicators.jl is not the same as TALib RSI.
There is 95% correlation between them, thus 5% deviation.

IND_RSI = Indicators.rsi(close, n=14)
TLB_RSI = tlb.RSI(close, timeperiod=14)

replace!(IND_RSI, NaN => 0.0)
replace!(TLB_RSI, NaN => 0.0)

julia> cor(IND_RSI, TLB_RSI)
0.9482340199922739

I compared RSI values against Equis MetaStock, and found that TALib RSI is the one giving the correct values. TALib RSI matches exactly MetaStock RSI.

I didnt compare every indicator to TALib, but it seems fine with Momentum. The correlation between Indicators.jl Momentum and TALib Momentum is 1.0.

IND_MOM = Indicators.momentum(close, n=14)
TLB_MOM = tlb.MOM(close, timeperiod=14)

replace!(IND_MOM, NaN => 0.0)
replace!(TLB_MOM, NaN => 0.0)

julia> cor(IND_MOM, TLB_MOM)
1.0

Thank you!

Can not install "Indicators.jl" with latest "Plots(v1.6.4)" and "RecipesBase" !

Can not install "Indicators.jl" with latest "Plots(v1.6.4)" and "RecipesBase" !

Pkg.add("Indicators")

My versioninfo():
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: AMD Ryzen 5 3600X 6-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, znver2)
Environment:
JULIA.EXECUTABLEPATH = C:\Users\USER\AppData\Local\Julia-1.3.1\bin\ & set JULIA_NUM_THREADS=12 & julia.exe
JULIA_NUM_THREADS = 12

The return error message:

Resolving package versions...
Unsatisfiable requirements detected for package RecipesBase [3cdcf5f2]:
RecipesBase [3cdcf5f2] log:
├─possible versions are: [0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 1.0.0-1.0.2, 1.1.0] or uninstalled
├─restricted by compatibility requirements with Plots [91a5bcdd] to versions: [0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 1.0.0-1.0.2, 1.1.0]
│ └─Plots [91a5bcdd] log:
│ ├─possible versions are: [0.12.1-0.12.4, 0.13.0-0.13.1, 0.14.0-0.14.2, 0.15.0-0.15.1, 0.16.0, 0.17.0-0.17.4, 0.18.0, 0.19.0-0.19.3,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.