美文网首页
5.5 TA-Lib

5.5 TA-Lib

作者: wanggs66 | 来源:发表于2020-04-25 11:40 被阅读0次
  • Using ta-lib

In backtrader:

import backtrader as bt

class MyStrategy(bt.Strategy):
    params = (('period', 20),)

    def __init__(self):
        self.sma = bt.indicators.SMA(self.data, period=self.p.period)
        ...

...

In ta-lib :

import backtrader as bt

class MyStrategy(bt.Strategy):
    params = (('period', 20),)

    def __init__(self):
        self.sma = bt.talib.SMA(self.data, timeperiod=self.p.period)
        ...

...

[notes] Params for the ta-lib indicators are defined by the library itself.

And for indicators that require more than one input, open, high, close need to be passed by individually.

import backtrader as bt

class MyStrategy(bt.Strategy):
    params = (('period', 20),)

    def __init__(self):
        self.stoc = bt.talib.STOCH(self.data.high, self.data.low, self.data.close,
                               fastk_period=14, slowk_period=3, slowd_period=3)

        ...

...

相关文章

网友评论

      本文标题:5.5 TA-Lib

      本文链接:https://www.haomeiwen.com/subject/fzbhwhtx.html