-
Notifications
You must be signed in to change notification settings - Fork 25
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
TALib wrapper #51
Comments
A Node wrapper can be found at https://github.com/oransel/node-talib |
This package is currently pure Julia code, but I see no problem creating a new one that does wrap TALib. If you'd like to start on it we can add it to the JuliaQuant organization as TALib.jl. |
I don't feel very confortable with calling C code from Julia. I'm using Mac OS X and installed TALib through
Do you have some experience about calling C code from Julia and could you help on this ? |
Yeah, it's a lot easier than you think. The language is designed to accept calls to C and Fortran libraries so wrapping isn't a snarly mess like in other languages. One suggestion is to look over some other Julia libraries that wrap C code. |
I've found an example here https://github.com/aviks/PiGPIO.jl/blob/master/src/PiGPIO.jl |
Sweet! Yeah @aviks knows the code, solid reference to start |
Maybe we could first try to do in Julia same than in Python: import talib
import numpy as np
talib.SIN(np.array([0.0, np.pi/2, np.pi, 3*np.pi/2])) which output array([ 0.00000000e+00, 1.00000000e+00, 1.22464680e-16,
-1.00000000e+00]) with Julia sin([0.0, pi/2, pi, 3pi/2]) should be (approximately) same as TA_SIN([0.0, pi/2, pi, 3pi/2]) Unfortunately, in |
I try this: julia> SIN(a) = ccall( (:SIN, "/usr/local/lib/libta_lib.0.0.0.dylib"), Int32, (Cfloat,), a)
SIN (generic function with 1 method)
julia> SIN(0.0)
ERROR: ccall: could not find function SIN in library /usr/local/lib/libta_lib.0.0.0.dylib
in SIN at none:1 so function is not named I did (according http://stackoverflow.com/questions/4506121/how-to-print-a-list-of-symbols-exported-from-a-dynamic-library )
and get
So function seems to be named I did
I also try:
Not sure a segfault is great! Any idea ? |
Here is how TA_RetCode TA_SIN( int startIdx,
int endIdx,
const double inReal[],
int *outBegIdx,
int *outNBElement,
double outReal[] ) See |
Good news... julia> _TA_COS(startIdx, endIdx, inReal, outBegIdx, outNBElement, outReal) = ccall( (:TA_COS, "/usr/local/lib/libta_lib.0.0.0.dylib"), Cint, (Cint, Cint, Ptr{Cdouble}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}), startIdx, endIdx, inReal, outBegIdx, outNBElement, outReal)
_TA_COS (generic function with 1 method)
julia> startIdx = 0
0
julia> inReal = [0.0, pi/2, pi, 3pi/2, 0.0, pi/2, pi, 3pi/2]
8-element Array{Float64,1}:
0.0
1.5708
3.14159
4.71239
0.0
1.5708
3.14159
4.71239
julia> endIdx = length(inReal) - 1
7
julia> outBegIdx = Ref{Cint}(0)
Base.RefValue{Int32}(0)
julia> outNBElement = Ref{Cint}(0)
Base.RefValue{Int32}(0)
julia> outReal = zeros(length(inReal))
8-element Array{Float64,1}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> _TA_COS(startIdx, endIdx, inReal, outBegIdx, outNBElement, outReal)
0
julia> println(outReal)
[1.0,6.123233995736766e-17,-1.0,-1.8369701987210297e-16,1.0,6.123233995736766e-17,-1.0,-1.8369701987210297e-16]
julia> function TA_COS(inReal::Array{Float64,1})
N = length(inReal)
outReal = zeros(N)
retCode = _TA_COS(0, N - 1, inReal, Ref{Cint}(0), Ref{Cint}(0), outReal)
if retCode == 0
outReal
else
error("Bad return code")
end
end
TA_COS (generic function with 1 method)
julia> outReal = TA_COS(inReal)
8-element Array{Float64,1}:
1.0
6.12323e-17
-1.0
-1.83697e-16
1.0
6.12323e-17
-1.0
-1.83697e-16
julia> println(outReal)
[1.0,6.123233995736766e-17,-1.0,-1.8369701987210297e-16,1.0,6.123233995736766e-17,-1.0,-1.8369701987210297e-16]
|
Many functions have suffix like |
See the API docs for discussions on how look back works and how to call the functions efficiently: |
Thanks @mrjbq7 for this. Work In Progress available at https://github.com/femtotrader/TALib.jl |
Closing here |
Looking forward to benchmarking TALib against MarketTechnicals, with both DataFrames and TimeArrays. |
Hello,
it will be nice to have a Julia TALib wrapper like https://github.com/mrjbq7/ta-lib for Python
Pinging @mrjbq7
Here is function supported by TALib http://ta-lib.org/
Kind regards
The text was updated successfully, but these errors were encountered: