Transplant Python quantitative trading TA-Lib library to function calculation

Lib-TA , the full name of "Technical Analysis Library", that is, technical analysis library, Python is a senior financial quantify library, covering more than 150 stocks, futures trading software commonly used in technical analysis indicators, such as MACD, RSI, KDJ, momentum indicators Bollinger bands and so on.

TA-Lib 10 can be divided into sub-sections:

  • Overlap Studies (overlap index)
  • Momentum Indicators (momentum indicators)
  • Volume Indicators (volume index)
  • Cycle Indicators (cycle indicator)
  • Price Transform (conversion price)
  • Volatility Indicators (volatility index)
  • Pattern Recognition (pattern recognition)
  • Statistic Functions (statistical functions)
  • Math Transform (mathematical transformation)
  • Math Operators (math)


This article describes the template Funcraft of the quantitative trading Python library TA-lib ported to function calculation .

Dependent tools

This project is developed under MacOS, tool involved is platform-independent, Linux and Windows for desktop systems should also apply. Before starting this example, make sure the following tools have been correctly installed, update to the latest version and configured correctly.

For MacOS user can use homebrew installation:

brew cask install docker
brew tap vangie/formula
brew install fun

Windows and Linux users to install, please refer to:

https://github.com/aliyun/fun/blob/master/docs/usage/installation.md

After installation, remember to perform fun configinitialization at the configuration.

initialization

Use fun init command can quickly and easily initialize this template project locally.

fun init vangie/ta-lib-example

Installation depends

$ fun install
using template: template.yml
start installing function dependencies without docker

building ta-lib-example/ta-lib-example
Funfile exist, Fun will use container to build forcely
Step 1/5 : FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:build-1.7.7
 ---> 373f5819463b
Step 2/5 : COPY ta-lib-0.4.0-src.tar.gz /tmp
 ---> Using cache
 ---> 64f9f85112b4
Step 3/5 : RUN cd /tmp; tar -xzf ta-lib-0.4.0-src.tar.gz
 ---> Using cache
 ---> 9f2d3f836de9
Step 4/5 : RUN cd /tmp/ta-lib/ ;     ./configure --prefix=/code/.fun/root/usr ;     make ; make install
 ---> Using cache
 ---> 7725836973d4
Step 5/5 : RUN TA_LIBRARY_PATH=/code/.fun/root/usr/lib     TA_INCLUDE_PATH=/code/.fun/root/usr/include     fun-install pip install TA-Lib
 ---> Using cache
 ---> a338e71895b7
sha256:a338e71895b74a0be98278f35da38c48545f04a54e19ec9e689bab976265350b
Successfully built a338e71895b7
Successfully tagged fun-cache-d4ac1d89-5b75-4429-933a-2260e2f7fbec:latest
copying function artifact to /Users/vangie/Workspace/ta-lib-example/{{ projectName }}

Install Success


Tips for next step
======================
* Invoke Event Function: fun local invoke
* Invoke Http Function: fun local start
* Build Http Function: fun build
* Deploy Resources: fun deploy

Local calls

$ fun local invoke
using template: template.yml

Missing invokeName argument, Fun will use the first function ta-lib-example/ta-lib-example as invokeName

skip pulling image aliyunfc/runtime-python3.6:1.7.7...
FunctionCompute python3 runtime inited.
FC Invoke Start RequestId: dc1495b2-13ec-4ecf-a2dc-a0026d82651a
FC Invoke End RequestId: dc1495b2-13ec-4ecf-a2dc-a0026d82651a
[
    "HT_DCPERIOD",
    "HT_DCPHASE",
    "HT_PHASOR",
    "HT_SINE",
    "HT_TRENDMODE"
]

RequestId: dc1495b2-13ec-4ecf-a2dc-a0026d82651a          Billed Duration: 350 ms         Memory Size: 1998 MB    Max Memory Used: 34 MB

deploy

$ fun deploy
using template: template.yml
using region: cn-shanghai
using accountId: ***********4733
using accessKeyId: ***********EUz3
using timeout: 600

Waiting for service ta-lib-example to be deployed...
        Waiting for function ta-lib-example to be deployed...
                Waiting for packaging function ta-lib-example code...
                The function ta-lib-example has been packaged. A total of 39 files files were compressed and the final size was 3.23 MB
        function ta-lib-example deploy success
service ta-lib-example deploy success

carried out

$ fun invoke
using template: template.yml

Missing invokeName argument, Fun will use the first function ta-lib-example/ta-lib-example as invokeName

========= FC invoke Logs begin =========
FC Invoke Start RequestId: 83e23eba-02b4-4380-bbca-daec6856bf4a
FC Invoke End RequestId: 83e23eba-02b4-4380-bbca-daec6856bf4a

Duration: 213.86 ms, Billed Duration: 300 ms, Memory Size: 128 MB, Max Memory Used: 43.50 MB
========= FC invoke Logs end =========

FC Invoke Result:
[
    "HT_DCPERIOD",
    "HT_DCPHASE",
    "HT_PHASOR",
    "HT_SINE",
    "HT_TRENDMODE"
]

Reference Reading

  1. Function calculates
  2. [Taught you] stock market technical analysis tool of TA-Lib (a)

Guess you like

Origin yq.aliyun.com/articles/740311