Skip to content

Chapter 5: Strategy Development in Practice

This chapter is currently maintained in Chinese first.

TA-Lib Backend Usage

  • backend="auto" defaults to rust.
  • For baseline alignment with legacy strategies, explicitly use backend="python".
  • To override auto globally, set AKQUANT_TALIB_AUTO_BACKEND=python|rust.
from akquant import talib as ta

close = df["close"].to_numpy()
high = df["high"].to_numpy()
low = df["low"].to_numpy()
volume = df["volume"].to_numpy()

rsi_py = ta.RSI(close, timeperiod=14, backend="python")
rsi_rs = ta.RSI(close, timeperiod=14, backend="rust")
mfi_rs = ta.MFI(high, low, close, volume, timeperiod=14, backend="rust")
tema_rs = ta.TEMA(close, timeperiod=20, backend="rust")

Indicator Selection Template

  • Trend-following: EMA + ADX + NATR
  • Mean-reversion: BBANDS + RSI
  • Volume confirmation: OBV + MFI + ROC
  • Trailing risk control: SAR + ATR
import numpy as np
from akquant import talib as ta

ema_fast = ta.EMA(close, timeperiod=20, backend="rust")
ema_slow = ta.EMA(close, timeperiod=60, backend="rust")
adx = ta.ADX(high, low, close, timeperiod=14, backend="rust")

if np.isnan(ema_fast[-1]) or np.isnan(adx[-1]):
    return
if ema_fast[-1] > ema_slow[-1] and adx[-1] >= 20:
    self.buy(symbol, 100)

For complete Chinese content including warmup handling and migration tips: - 第 5 章:策略开发实战 (Strategy Implementation) - 指标组合实战手册