julia环境下——k线【技术指标】-【ta-lib】包的学习记

2020-08-29  本文已影响0人  昵称违法

talib底层用C编写,计算速度非常快,底层有优化。

调用路径:【julia】->《PyCall》->【python】->《Cython/Cpython》->【Ta-lib】

提示:

LLV(C,N) 与 MIN(C,N),HHV(C,N)与MAX(C,N)的区别:
MIN:前面的个数不足N时,返回空值。依据通达信函数库。
LLV:前面的个数不足N时,前面有几个取几个值进行判断 

HHV,MAX同理。

一、ta-lib的官网

https://ta-lib.org/

二、包简介

TaLib是一个Python金融指数处理库。包含了很多技术分析里的常用参数指标,例如MA、SMA、WMA、MACD、ATR等。

三、包的安装

先得有python环境
python版的ta-lib安装(略)

四、julia调用ta-lib包

# 调取ta-lib
using PyCall
ta = pyimport("talib")
println("okk!!!")

五、使用ta-lib函数

5.1获取所有的函数

#获取所有的函数
fns = ta.get_functions()
fns .|> println

结果

HT_DCPERIOD
HT_DCPHASE
HT_PHASOR
HT_SINE
HT_TRENDMODE
ADD
DIV
MAX
MAXINDEX
MIN
MININDEX
MINMAX
MINMAXINDEX
MULT
SUB
SUM
ACOS
ASIN
ATAN
CEIL
COS
COSH
EXP
FLOOR
LN
LOG10
SIN
SINH
SQRT
TAN
TANH
ADX
ADXR
APO
AROON
AROONOSC
BOP
CCI
CMO
DX
MACD
MACDEXT
MACDFIX
MFI
MINUS_DI
MINUS_DM
MOM
PLUS_DI
PLUS_DM
PPO
ROC
ROCP
ROCR
ROCR100
RSI
STOCH
STOCHF
STOCHRSI
TRIX
ULTOSC
WILLR
BBANDS
DEMA
EMA
HT_TRENDLINE
KAMA
MA
MAMA
MAVP
MIDPOINT
MIDPRICE
SAR
SAREXT
SMA
T3
TEMA
TRIMA
WMA
CDL2CROWS
CDL3BLACKCROWS
CDL3INSIDE
CDL3LINESTRIKE
CDL3OUTSIDE
CDL3STARSINSOUTH
CDL3WHITESOLDIERS
CDLABANDONEDBABY
CDLADVANCEBLOCK
CDLBELTHOLD
CDLBREAKAWAY
CDLCLOSINGMARUBOZU
CDLCONCEALBABYSWALL
CDLCOUNTERATTACK
CDLDARKCLOUDCOVER
CDLDOJI
CDLDOJISTAR
CDLDRAGONFLYDOJI
CDLENGULFING
CDLEVENINGDOJISTAR
CDLEVENINGSTAR
CDLGAPSIDESIDEWHITE
CDLGRAVESTONEDOJI
CDLHAMMER
CDLHANGINGMAN
CDLHARAMI
CDLHARAMICROSS
CDLHIGHWAVE
CDLHIKKAKE
CDLHIKKAKEMOD
CDLHOMINGPIGEON
CDLIDENTICAL3CROWS
CDLINNECK
CDLINVERTEDHAMMER
CDLKICKING
CDLKICKINGBYLENGTH
CDLLADDERBOTTOM
CDLLONGLEGGEDDOJI
CDLLONGLINE
CDLMARUBOZU
CDLMATCHINGLOW
CDLMATHOLD
CDLMORNINGDOJISTAR
CDLMORNINGSTAR
CDLONNECK
CDLPIERCING
CDLRICKSHAWMAN
CDLRISEFALL3METHODS
CDLSEPARATINGLINES
CDLSHOOTINGSTAR
CDLSHORTLINE
CDLSPINNINGTOP
CDLSTALLEDPATTERN
CDLSTICKSANDWICH
CDLTAKURI
CDLTASUKIGAP
CDLTHRUSTING
CDLTRISTAR
CDLUNIQUE3RIVER
CDLUPSIDEGAP2CROWS
CDLXSIDEGAP3METHODS
AVGPRICE
MEDPRICE
TYPPRICE
WCLPRICE
BETA
CORREL
LINEARREG
LINEARREG_ANGLE
LINEARREG_INTERCEPT
LINEARREG_SLOPE
STDDEV
TSF
VAR
ATR
NATR
TRANGE
AD
ADOSC
OBV

5.2 获取按功能分类后的函数列表

#按功能种类获取函数
dt = ta.get_function_groups()

for (k,v) in dt
    println("====$(k)====")
    v .|> println
end

结果

====Price Transform====
AVGPRICE
MEDPRICE
TYPPRICE
WCLPRICE
====Momentum Indicators====
ADX
ADXR
APO
AROON
AROONOSC
BOP
CCI
CMO
DX
MACD
MACDEXT
MACDFIX
MFI
MINUS_DI
MINUS_DM
MOM
PLUS_DI
PLUS_DM
PPO
ROC
ROCP
ROCR
ROCR100
RSI
STOCH
STOCHF
STOCHRSI
TRIX
ULTOSC
WILLR
====Statistic Functions====
BETA
CORREL
LINEARREG
LINEARREG_ANGLE
LINEARREG_INTERCEPT
LINEARREG_SLOPE
STDDEV
TSF
VAR
====Overlap Studies====
BBANDS
DEMA
EMA
HT_TRENDLINE
KAMA
MA
MAMA
MAVP
MIDPOINT
MIDPRICE
SAR
SAREXT
SMA
T3
TEMA
TRIMA
WMA
====Volatility Indicators====
ATR
NATR
TRANGE
====Cycle Indicators====
HT_DCPERIOD
HT_DCPHASE
HT_PHASOR
HT_SINE
HT_TRENDMODE
====Math Transform====
ACOS
ASIN
ATAN
CEIL
COS
COSH
EXP
FLOOR
LN
LOG10
SIN
SINH
SQRT
TAN
TANH
====Pattern Recognition====
CDL2CROWS
CDL3BLACKCROWS
CDL3INSIDE
CDL3LINESTRIKE
CDL3OUTSIDE
CDL3STARSINSOUTH
CDL3WHITESOLDIERS
CDLABANDONEDBABY
CDLADVANCEBLOCK
CDLBELTHOLD
CDLBREAKAWAY
CDLCLOSINGMARUBOZU
CDLCONCEALBABYSWALL
CDLCOUNTERATTACK
CDLDARKCLOUDCOVER
CDLDOJI
CDLDOJISTAR
CDLDRAGONFLYDOJI
CDLENGULFING
CDLEVENINGDOJISTAR
CDLEVENINGSTAR
CDLGAPSIDESIDEWHITE
CDLGRAVESTONEDOJI
CDLHAMMER
CDLHANGINGMAN
CDLHARAMI
CDLHARAMICROSS
CDLHIGHWAVE
CDLHIKKAKE
CDLHIKKAKEMOD
CDLHOMINGPIGEON
CDLIDENTICAL3CROWS
CDLINNECK
CDLINVERTEDHAMMER
CDLKICKING
CDLKICKINGBYLENGTH
CDLLADDERBOTTOM
CDLLONGLEGGEDDOJI
CDLLONGLINE
CDLMARUBOZU
CDLMATCHINGLOW
CDLMATHOLD
CDLMORNINGDOJISTAR
CDLMORNINGSTAR
CDLONNECK
CDLPIERCING
CDLRICKSHAWMAN
CDLRISEFALL3METHODS
CDLSEPARATINGLINES
CDLSHOOTINGSTAR
CDLSHORTLINE
CDLSPINNINGTOP
CDLSTALLEDPATTERN
CDLSTICKSANDWICH
CDLTAKURI
CDLTASUKIGAP
CDLTHRUSTING
CDLTRISTAR
CDLUNIQUE3RIVER
CDLUPSIDEGAP2CROWS
CDLXSIDEGAP3METHODS
====Volume Indicators====
AD
ADOSC
OBV
====Math Operators====
ADD
DIV
MAX
MAXINDEX
MIN
MININDEX
MINMAX
MINMAXINDEX
MULT
SUB
SUM

5.3 查看函数的用法

? ta.MA

结果

 MA(real[, timeperiod=?, matype=?])

    Moving average (Overlap Studies)

    Inputs:
        real: (any ndarray)
    Parameters:
        timeperiod: 30
        matype: 0 (Simple Moving Average)
    Outputs:
        real

5.4 计算5日均线

using DataFrames
df = DataFrame()
df.price = [float(x) for x in 1:100]
df.ma5 = ta.MA(df.price,5)
df |> display

结果

100 rows × 2 columns

price   ma5
Float64 Float64
1   1.0     NaN
2   2.0     NaN
3   3.0     NaN
4   4.0     NaN
5   5.0     3.0
6   6.0     4.0
7   7.0     5.0
8   8.0     6.0
9   9.0     7.0
10  10.0    8.0
11  11.0    9.0
12  12.0    10.0
13  13.0    11.0
14  14.0    12.0
15  15.0    13.0
16  16.0    14.0
17  17.0    15.0
18  18.0    16.0
19  19.0    17.0
20  20.0    18.0
21  21.0    19.0
22  22.0    20.0
23  23.0    21.0
24  24.0    22.0
25  25.0    23.0
26  26.0    24.0
27  27.0    25.0
28  28.0    26.0
29  29.0    27.0
30  30.0    28.0
⋮    ⋮       ⋮

上一篇下一篇

猜你喜欢

热点阅读