dysonance / indicators.jl Goto Github PK
View Code? Open in Web Editor NEWFinancial market technical analysis & indicators in Julia
License: Other
Financial market technical analysis & indicators in Julia
License: Other
could you show some example codes of computing rolling regressions in your document?
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!
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!
hi, Any idea why this package does not support views? it would help a lot reduce memory usage
Thanks!
Returning all NaN
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,
This is the shell of an idea. Not wrapped in a clean function. It has demean. Function would include demean=true,false
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
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
lagged_series = [fill(0,k); rets[1:end-k]]
for i = n:size(rets,1)
mean_out[i] = mean(rets[i-n+1:i])
end
for i = n:size(rets,1)
devmean_out[i] = rets[i] - mean_out[i]
end
for i = n:size(rets,1)
var_out[i] = var(rets[i-n+1:i])
end
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
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!
Hi ,
I'm new to Julia Language at the moment but will eventually be able to contribute more. Would like you to considere these for the todo List.
Nadaraya-Watson-Estimator and the Nadaraya-Watson-Envelope
I think would be very valuable here in Julia.
You can find more info on those here:
https://www.tradingview.com/script/Iko0E2kL-Nadaraya-Watson-Envelope-LuxAlgo/
https://www.tradingview.com/script/amRCTgFw-Nadaraya-Watson-Estimator-LuxAlgo/
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?
hey mate, it appears that installing Indicators downgrades HTTP. Can you please help with this
⌅ [cd3eb016] ↓ HTTP v1.5.5 ⇒ v0.9.17
ta!
Is it possible to include a keyword argument to calculate the sma with the end points?
So for an array
https://gist.github.com/flare9x/76fe49368f14e652f6de3a130344ea4e#file-rolling_rs_hurst-jl
This is over lapping blocks of varying lags on a return series. Each data point in the series then has a H value. Needs to be wrapped in a clean function.
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!
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
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.
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.
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
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])
Provide generic functions to be able to used by other numeric types like BigFloat.
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!
Hi,
we should tag a new release and remove Manifest.toml; at the moment, for example, Plots.jl
is pinned at 0.29.0 which is really old.
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.
Hello!
Just found out about your packages. Looks nice! I was wondering if you were planning support for AlphaVantage API? There's a package developed in Julia right now https://github.com/ellisvalentiner/AlphaVantage.jl
Cheers!
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
https://github.com/joshday/OnlineStats.jl
Adding the ability to update an indicator instance, would be very much welcome.
Similar to dysonance/Temporal.jl#14
Try to run the examples not working:
using Base.Dates
to using Dates
passedMethodError: 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
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
.
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.
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!
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.
It's reasonable to get the running avg of new cases per day (an example). I can make a PR if this makes sense
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.