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

roadmap for a Julia TA-Lib wrapper #1

Open
17 of 25 tasks
femtotrader opened this issue May 7, 2016 · 12 comments
Open
17 of 25 tasks

roadmap for a Julia TA-Lib wrapper #1

femtotrader opened this issue May 7, 2016 · 12 comments

Comments

@femtotrader
Copy link
Owner

femtotrader commented May 7, 2016

@femtotrader
Copy link
Owner Author

Some help to define a (better) roadmap will be nice

Pinging @milktrader @mrjbq7

Feel free to ping some other people who might be interested

@mrjbq7
Copy link

mrjbq7 commented May 8, 2016

There are a lot of functions to define, I ended getting one to work manually then made a code generator that used that as a template to create the code for all of the functions:

https://github.com/mrjbq7/ta-lib/blob/master/tools/generate.py

@femtotrader
Copy link
Owner Author

Ideally I think we should have a kind of tabular or JSON format to define functions and group them according similar behavior (return one array (like SMA) or 3 like BBANDS ...)
Such intermediate format will help to make wrappers in several languages.
Your opinion @mrjbq7 ?

@femtotrader
Copy link
Owner Author

femtotrader commented May 8, 2016

This idea is (partially) implemented here: https://github.com/femtotrader/TALib.jl/tree/master/scripts (see parse_headers_manually.py

@femtotrader
Copy link
Owner Author

femtotrader commented May 8, 2016

An other interesting approach could be to use a Python C parser library to create intermediate file from parsed headers. pyclibrary http://pyclibrary.readthedocs.io/ seems interesting. You can find in same directory parse_headers_pyclibrary.py and JSON / YAML files.

Clang might also be considered https://github.com/ihnorton/Clang.jl
(an example https://github.com/mmacedoeu/amqp.jl/blob/master/gen.jl )

@femtotrader
Copy link
Owner Author

MA and BBANDS seems to be working fine (see README).

@mrjbq7
Copy link

mrjbq7 commented May 10, 2016

Nice!

@milktrader
Copy link

milktrader commented May 12, 2016

  • accept TimeArray as input

@femtotrader
Copy link
Owner Author

femtotrader commented May 13, 2016

That's add to roadmap.
There is 3 level of functions

  • level 0: function with raw C function calls (same parameters than C functions)
  • level 1: functions with array as input
  • level 2: highest function level (DataFrame or TImeArray as input)

But ideally I would like to avoid to add DataFrames.jl (or TimeArray.jl) as required dependencies (just optional dependencies)

I did code for level 0.

see generate_ta_func_raw in scripts/ta_func_api.jl but these function display a string which is output to STDOUT.
I generate code using

julia scripts/ta_func_api.jl > out.jl

but I think I can do something more elegant with macros.

Any help on this will be great.

In the meantime, I will try to implement this weekend level 1 functions.

@femtotrader
Copy link
Owner Author

femtotrader commented May 13, 2016

@milktrader maybe you can provide some examples of TimeArray usage for MA and BBANDS like I did in TALib.jl for DataFrames. It will be easier for me to implement code generation if I know what code I should generate.

see

function MA(dfOHLCV::DataFrames.DataFrame; timeperiod::Integer=30, matype::TA_MAType=TA_MAType_SMA, price=PRICE)

and

function BBANDS(dfOHLCV::DataFrames.DataFrame; timeperiod::Integer=30, nbdevup::AbstractFloat=2.0, nbdevdn::AbstractFloat=2.0, matype::TA_MAType=TA_MAType_SMA, price=PRICE)

@femtotrader
Copy link
Owner Author

level 2 support with DataFrames as inputs / outputs is implemented.

We can do now

using TALib
using DataFrames
using PyPlot

filename = "test/ford_2012.csv"
df = readtable(filename)
df[:Date] = Date(df[:Date])

indic = MA(df)
plot(df[:Date], df[:Close], indic[:Date], indic[:Real])

indic = MA(df, price=:Open)
plot(df[:Date], df[:Close], indic[:Date], indic[:Real])

indic = BBANDS(df)
plot(df[:Date], df[:Close],
    indic[:Date], indic[:UpperBand],
    indic[:Date], indic[:MiddleBand],
    indic[:Date], indic[:LowerBand]
)

Next step will be to have level 2 - TimeArray functions

Code is quite ugly but everyone is free to help.

@femtotrader
Copy link
Owner Author

femtotrader commented May 21, 2016

level 2 support with TimeArrays as inputs / outputs is also implemented.

We can do now

julia> using TALib
julia> using TimeSeries
julia> using PyPlot

julia> filename = "test/ford_2012.csv"
julia> ohlcv = readtimearray(filename)
250x5 TimeSeries.TimeArray{Float64,2,Date,Array{Float64,2}} 2012-01-03 to 2012-12-31

             Open     High     Low      Close    Volume
2012-01-03 | 11.0     11.25    10.99    11.13    45709900
2012-01-04 | 11.15    11.53    11.07    11.3     79725200
2012-01-05 | 11.33    11.63    11.24    11.59    67877500
2012-01-06 | 11.74    11.8     11.52    11.71    59840700

2012-12-26 | 12.31    12.79    12.31    12.79    140331900
2012-12-27 | 12.79    12.81    12.36    12.76    108315100
2012-12-28 | 12.55    12.88    12.52    12.87    95668600
2012-12-31 | 12.88    13.08    12.76    12.95    106908900

julia> indic = MA(ohlcv)
250x1 TimeSeries.TimeArray{Float64,1,Date,Array{Float64,1}} 2012-01-03 to 2012-12-31

             Real
2012-01-03 | NaN
2012-01-04 | NaN
2012-01-05 | NaN
2012-01-06 | NaN

2012-12-26 | 11.3347
2012-12-27 | 11.3933
2012-12-28 | 11.4667
2012-12-31 | 11.546

julia> plot(ohlcv.timestamp, ohlcv["Close"].values, indic.timestamp, indic["Real"].values)

julia> indic = BBANDS(ohlcv)
250x3 TimeSeries.TimeArray{Float64,2,Date,Array{Float64,2}} 2012-01-03 to 2012-12-31

             UpperBand  MiddleBand  LowerBand
2012-01-03 | NaN        NaN         NaN
2012-01-04 | NaN        NaN         NaN
2012-01-05 | NaN        NaN         NaN
2012-01-06 | NaN        NaN         NaN

2012-12-26 | 12.9438    12.11       11.2762
2012-12-27 | 13.1808    12.316      11.4512
2012-12-28 | 13.2853    12.536      11.7867
2012-12-31 | 13.1319    12.754      12.3761

julia> plot(ohlcv.timestamp, ohlcv["Close"].values,
    indic.timestamp, indic["UpperBand"].values,
    indic.timestamp, indic["MiddleBand"].values,
    indic.timestamp, indic["LowerBand"].values
)

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants