The resource loading... loading...

2.7.1 Windows 32-bit system Python 2.7 environment Install the talib index library

Author: Inventors quantify - small dreams, Created: 2017-02-11 18:01:05, Updated: 2019-08-01 09:20:22

Windows 32-bit system Python 2.7 environment installed talib index library


Inventors quantify the platform by using Python to write policies for calculating indicators such as MA, MACD, EMA, etc. (because they are built-in) without any error returns if they use a rewritten TA library.

For example, check back with a policy (whether using a public server or using your own host, check back is fine).

import types
def main():
    STATE_IDLE = -1
    state = STATE_IDLE
    initAccount = ext.GetAccount()
    while True:
        if state == STATE_IDLE :
            n = ext.Cross(FastPeriod,SlowPeriod) # 指标交叉函数
            if abs(n) >= EnterPeriod :
                opAmount = _N(initAccount.Stocks * PositionRatio,3)
                Dict = ext.Buy(opAmount) if n > 0 else ext.Sell(opAmount)
                if Dict :
                    opAmount = Dict['amount']
                    state = PD_LONG if n > 0 else PD_SHORT
                    Log("开仓详情",Dict,"交叉周期",n)
        else:
            n = ext.Cross(ExitFastPeriod,ExitSlowPeriod) # 指标交叉函数
            if abs(n) >= ExitPeriod and ((state == PD_LONG and n < 0) or (state == PD_SHORT and n > 0)) :
                nowAccount = ext.GetAccount()
                Dict2 = ext.Sell(nowAccount.Stocks - initAccount.Stocks) if state == PD_LONG else ext.Buy(initAccount.Stocks - nowAccount.Stocks)
                state = STATE_IDLE
                nowAccount = ext.GetAccount()
                LogProfit(nowAccount.Balance - initAccount.Balance,'钱:',nowAccount.Balance,'币:',nowAccount.Stocks,'平仓详情:',Dict2,'交叉周期:',n)
        Sleep(Interval * 1000)


The policy is called: equiline policy (python version), using the template: python version spot digital currency trading library

You can download it directly on Strategy Square.

The policy does not use any indicator functions, but uses the ext.Cross export function of the template, which is called in the export function.TA.MAI'm using the TA library (no problem since the TA library is built in!)

If you change the code.

import types
import talib  # 改动  引用 talib 库
def main():
    STATE_IDLE = -1
    state = STATE_IDLE
    initAccount = ext.GetAccount()
    while True:
        records = exchange.GetRecords()
        ma = talib.MA(records.Close)       # 改动 ,调用 talib 库的 MA 函数 即 均线指标计算
        LogStatus("均值" + str(ma))
        if state == STATE_IDLE :
            n = ext.Cross(FastPeriod,SlowPeriod) # 指标交叉函数
            if abs(n) >= EnterPeriod :
                opAmount = _N(initAccount.Stocks * PositionRatio,3)
                Dict = ext.Buy(opAmount) if n > 0 else ext.Sell(opAmount)
                if Dict :
                    opAmount = Dict['amount']
                    state = PD_LONG if n > 0 else PD_SHORT
                    Log("开仓详情",Dict,"交叉周期",n)
        else:
            n = ext.Cross(ExitFastPeriod,ExitSlowPeriod) # 指标交叉函数
            if abs(n) >= ExitPeriod and ((state == PD_LONG and n < 0) or (state == PD_SHORT and n > 0)) :
                nowAccount = ext.GetAccount()
                Dict2 = ext.Sell(nowAccount.Stocks - initAccount.Stocks) if state == PD_LONG else ext.Buy(initAccount.Stocks - nowAccount.Stocks)
                state = STATE_IDLE
                nowAccount = ext.GetAccount()
                LogProfit(nowAccount.Balance - initAccount.Balance,'钱:',nowAccount.Balance,'币:',nowAccount.Stocks,'平仓详情:',Dict2,'交叉周期:',n)
        Sleep(Interval * 1000)


Call in policytalib.MAThe following errors are reported when using your own hosted review or real-time run policy:

img

I'm using a public server to retrieve it, and it's okay! Yes, because the talib library is already installed on the public server.

For the Python environment of your host, you can simply install talib manually. The following demonstration is about installing the talib library in the Python 2.7 environment under windows XP systems (i.e. 32-bit windows). There are many online methods, but here we use a simpler one.

  • 1, ready to download and install Python 2.7 (win32)

    img

    Note that the win32 version of Python 2.7 is shown below.

    When installing, note that the pip component is already installed by default. Select the Autoconfig environment variable option.

    img

  • 2, install the wheel

    img

    Below is a search on the Internet for information:

python wheel怎么安装?
小灰机289 | 浏览 14404 次
推荐于2016-01-19 03:17:24 最佳答案
你装了pip吗,建议先装pip,后面安装各种python库就很方便了。
打开命令行窗口,输入下面的命令:
pip install wheel
这时pip会自动在网络上下载安装wheel。
安装完成后可以敲下面的命令查看是否安装成功:
pip freeze
  • 3, download and install talib

    Downloaded from:http://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib

    To find the talib file that corresponds to the version and the system, see:

    img

    After downloading, install as shown below:

    img

  • 4, I thought it was OK, but when I tried to use import talib, I got an error that says "I can't find numpy", so I'm going to install this library too.

    img

    Download numpy Downloaded from:http://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib

    img

    Installed:

    img

  • 5, try it.

    img

    In inventor quantification, try using the talib's indicator function as a strategy

    The output of LogStatus can be displayed.

    img

  • The installation packages used in the above process have been passed on to the QQ group. Users can also download them themselves from the tutorial address.

    img

    After compression

    img


More

MAIKEOThank you!