当前位置: 首页>>代码示例>>Python>>正文


Python backtrader.num2date方法代码示例

本文整理汇总了Python中backtrader.num2date方法的典型用法代码示例。如果您正苦于以下问题:Python backtrader.num2date方法的具体用法?Python backtrader.num2date怎么用?Python backtrader.num2date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backtrader的用法示例。


在下文中一共展示了backtrader.num2date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_to_pandas

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def convert_to_pandas(strat_clk, obj: bt.LineSeries, start: datetime = None, end: datetime = None, name_prefix: str = "", num_back=None) -> pd.DataFrame:
    lines_clk = obj.lines.datetime.plotrange(start, end)

    df = pd.DataFrame()
    # iterate all lines
    for lineidx in range(obj.size()):
        line = obj.lines[lineidx]
        linealias = obj.lines._getlinealias(lineidx)
        if linealias == 'datetime':
            continue

        # get data limited to time range
        data = line.plotrange(start, end)

        ndata = convert_by_line_clock(data, lines_clk, strat_clk)

        df[name_prefix + linealias] = ndata

    df[name_prefix + 'datetime'] = [bt.num2date(x) for x in strat_clk]

    return df 
开发者ID:verybadsoldier,项目名称:backtrader_plotting,代码行数:23,代码来源:utils.py

示例2: _get_datas

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def _get_datas(strategy: bt.Strategy) -> str:
    md = '\n# Data Feeds\n'

    for data in strategy.datas:
        md += f'## {data.__class__.__name__}\n'

        tabdata = {
            'DataName:': str(data._dataname).replace("|", "\\|"),
            'Timezone:': data._tz,
            'Number of bars:': len(data),
            'Bar Length:': f"{data._compression} {bt.TimeFrame.getname(data._timeframe, data._compression)}",
        }

        # live trading does not have valid data parameters (other datas might also not have)
        if not math.isinf(data.fromdate):
            tabdata['Time From:'] = bt.num2date(data.fromdate)

        if not math.isinf(data.todate):
            tabdata['Time To:'] = bt.num2date(data.todate)

        md += _get_table(['Property', 'Value'], tabdata)

    return md 
开发者ID:verybadsoldier,项目名称:backtrader_plotting,代码行数:25,代码来源:metadata.py

示例3: _st_start

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def _st_start(self):
        if self.p.historical:
            self.put_notification(self.DELAYED)
            dtend = None
            if self.todate < float('inf'):
                dtend = num2date(self.todate)

            dtbegin = None
            if self.fromdate > float('-inf'):
                dtbegin = num2date(self.fromdate)

            self.qhist = self.ib.reqHistoricalDataEx(
                contract=self.contract, enddate=dtend, begindate=dtbegin,
                timeframe=self._timeframe, compression=self._compression,
                what=self.p.what, useRTH=self.p.useRTH, tz=self._tz,
                sessionend=self.p.sessionend)

            self._state = self._ST_HISTORBACK
            return True  # continue before

        # Live is requested
        if not self.ib.reconnect(resub=True):
            self.put_notification(self.DISCONNECTED)
            self._state = self._ST_OVER
            return False  # failed - was so

        self._statelivereconn = self.p.backfill_start
        if self.p.backfill_start:
            self.put_notification(self.DELAYED)

        self._state = self._ST_LIVE
        return True  # no return before - implicit continue 
开发者ID:mementum,项目名称:backtrader,代码行数:34,代码来源:ibdata.py

示例4: _st_start

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def _st_start(self, instart=True, tmout=None):
        if self.p.historical:
            self.put_notification(self.DELAYED)
            dtend = None
            if self.todate < float('inf'):
                dtend = num2date(self.todate)

            dtbegin = None
            if self.fromdate > float('-inf'):
                dtbegin = num2date(self.fromdate)

            self.qhist = self.o.candles(
                self.p.dataname, dtbegin, dtend,
                self._timeframe, self._compression,
                candleFormat=self._candleFormat,
                includeFirst=self.p.includeFirst)

            self._state = self._ST_HISTORBACK
            return True

        self.qlive = self.o.streaming_prices(self.p.dataname, tmout=tmout)
        if instart:
            self._statelivereconn = self.p.backfill_start
        else:
            self._statelivereconn = self.p.backfill

        if self._statelivereconn:
            self.put_notification(self.DELAYED)

        self._state = self._ST_LIVE
        if instart:
            self._reconns = self.p.reconnections

        return True  # no return before - implicit continue 
开发者ID:mementum,项目名称:backtrader,代码行数:36,代码来源:oanda.py

示例5: log

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log(self, txt, dt=None):
        dt = dt or self.data.datetime[0]
        dt = bt.num2date(dt)
        print('%s, %s' % (dt.isoformat(), txt)) 
开发者ID:mementum,项目名称:backtrader,代码行数:6,代码来源:test_strategy_optimized.py

示例6: log

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log(self, txt, dt=None, nodate=False):
        if not nodate:
            dt = dt or self.data.datetime[0]
            dt = bt.num2date(dt)
            print('%s, %s' % (dt.isoformat(), txt))
        else:
            print('---------- %s' % (txt)) 
开发者ID:mementum,项目名称:backtrader,代码行数:9,代码来源:test_analyzer-sqn.py

示例7: log

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log(self, txt, dt=None):
        if self.p.printout:
            dt = dt or self.data.datetime[0]
            dt = bt.num2date(dt)
            print('%s, %s' % (dt.isoformat(), txt)) 
开发者ID:mementum,项目名称:backtrader,代码行数:7,代码来源:multidata-strategy-unaligned.py

示例8: notify_order

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def notify_order(self, order):
        if not order.alive():
            print('{} {} {}@{}'.format(
                bt.num2date(order.executed.dt),
                'buy' if order.isbuy() else 'sell',
                order.executed.size,
                order.executed.price)
            ) 
开发者ID:mementum,项目名称:backtrader,代码行数:10,代码来源:sigsmacross.py

示例9: log

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log(self, txt, dt=None):
        ''' Logging function fot this strategy'''
        dt = dt or self.data.datetime[0]
        if isinstance(dt, float):
            dt = bt.num2date(dt)
        print('%s, %s' % (dt.isoformat(), txt)) 
开发者ID:mementum,项目名称:backtrader,代码行数:8,代码来源:observers-orderobserver.py

示例10: notify_order

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def notify_order(self, order):
        if order.status != order.Completed:
            return

        self.order = None
        print('{} {} Executed at price {}'.format(
            bt.num2date(order.executed.dt).date(),
            'Buy' * order.isbuy() or 'Sell', order.executed.price)
        ) 
开发者ID:mementum,项目名称:backtrader,代码行数:11,代码来源:cheat-on-open.py

示例11: notify_order

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def notify_order(self, order):
        curdtstr = self.data.datetime.datetime().strftime('%a %Y-%m-%d %H:%M:%S')
        if order.status in [order.Completed]:
            dtstr = bt.num2date(order.executed.dt).strftime('%a %Y-%m-%d %H:%M:%S')
            if order.isbuy():
                print('%s: BUY  EXECUTED, on:' % curdtstr, dtstr)
                self.order = None
            else:  # Sell
                print('%s: SELL EXECUTED, on:' % curdtstr, dtstr) 
开发者ID:mementum,项目名称:backtrader,代码行数:11,代码来源:close-minute.py

示例12: _st_start

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def _st_start(self):
        self.put_notification(self.DELAYED)

        date_begin = num2date(
            self.fromdate) if self.fromdate > float('-inf') else None
        date_end = num2date(
            self.todate) if self.todate < float('inf') else None

        self.qhist = self.o.price_data(self.p.dataname, date_begin, date_end, self.p.timeframe,
                                       self.p.compression, self.p.include_last)

        self._state = self._ST_HISTORBACK

        return True 
开发者ID:khramkov,项目名称:Backtrader-MQL5-API,代码行数:16,代码来源:mt5data.py

示例13: log_status

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log_status(self):
        status_dict = {}

        # general status
        status_dict["date"] = bt.num2date(self.data0.datetime[0])
        status_dict["data0"] = self.data0[0]
        status_dict["data1"] = self.data1[0]
        status_dict["lookback"] = self.lookback
        status_dict["max_lookback"] = self.max_lookback
        status_dict["enter_threshold_size"] = self.enter_threshold_size
        status_dict["exit_threshold_size"] = self.exit_threshold_size
        status_dict["loss_limit"] = self.loss_limit
        status_dict["status"] = self.status
        status_dict["qty0"] = self.qty0
        status_dict["qty1 "] = self.qty1 
        status_dict["initial_price_data0"] = self.initial_price_data0 
        status_dict["initial_price_data1"] = self.initial_price_data1 
        status_dict["initial_cash"] = self.initial_cash 
        status_dict["initial_long_pv"] = self.initial_long_pv
        status_dict["initial_short_pv"] = self.initial_short_pv
        status_dict["upper_limit"] = self.upper_limit 
        status_dict["lower_limit"] = self.lower_limit 
        status_dict["up_medium"] = self.up_medium 
        status_dict["low_medium"] = self.low_medium 
        status_dict["portfolio_value"] = self.broker.getvalue()
        status_dict["latest_trade_action"] =self.latest_trade_action
        status_dict["sell_stk"] = self.sell_stk
        status_dict["buy_stk"] = self.buy_stk
        status_dict["sell_amt"] = self.sell_amt 
        status_dict["buy_amt"] = self.buy_amt

        # strategy-specific status
        status_dict["spread"] = self.get_spread()
        status_dict["allow_trade"] = self.allow_trade 
        status_dict["resid_mean"] = self.resid_mean 
        status_dict["resid_std"] = self.resid_std

        # log the dictionary
        PTStrategy.log("[strategy-status]: {}".format(status_dict), None, self.data0) 
开发者ID:wywongbd,项目名称:pairstrade-fyp-2019,代码行数:41,代码来源:ptstrategy_distance.py

示例14: log

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log(txt, dt=None, data=None):
        dt = dt or data.datetime[0]
        dt = bt.num2date(dt)
        _logger.info('%s, %s' % (dt.isoformat(), txt)) 
开发者ID:wywongbd,项目名称:pairstrade-fyp-2019,代码行数:6,代码来源:ptstrategy.py

示例15: log_status

# 需要导入模块: import backtrader [as 别名]
# 或者: from backtrader import num2date [as 别名]
def log_status(self):
        status_dict = {}

        # general status
        status_dict["date"] = bt.num2date(self.data0.datetime[0])
        status_dict["data0"] = self.data0[0]
        status_dict["data1"] = self.data1[0]
        status_dict["lookback"] = self.lookback
        status_dict["max_lookback"] = self.max_lookback
        status_dict["enter_threshold_size"] = self.enter_threshold_size
        status_dict["exit_threshold_size"] = self.exit_threshold_size
        status_dict["loss_limit"] = self.loss_limit
        status_dict["status"] = self.status
        status_dict["qty0"] = self.qty0
        status_dict["qty1"] = self.qty1 
        status_dict["initial_price_data0"] = self.initial_price_data0 
        status_dict["initial_price_data1"] = self.initial_price_data1 
        status_dict["initial_cash"] = self.initial_cash 
        status_dict["initial_long_pv"] = self.initial_long_pv
        status_dict["initial_short_pv"] = self.initial_short_pv
        status_dict["upper_limit"] = self.upper_limit 
        status_dict["lower_limit"] = self.lower_limit 
        status_dict["up_medium"] = self.up_medium 
        status_dict["low_medium"] = self.low_medium 
        status_dict["portfolio_value"] = self.broker.getvalue()
        status_dict["latest_trade_action"] =self.latest_trade_action
        status_dict["sell_stk"] = self.sell_stk
        status_dict["buy_stk"] = self.buy_stk
        status_dict["sell_amt"] = self.sell_amt 
        status_dict["buy_amt"] = self.buy_amt

        # strategy-specific status
        status_dict["spread"] = self.get_spread()
        status_dict["allow_trade"] = self.allow_trade 
        status_dict["alpha"] = self.alpha 
        status_dict["intercept"] = self.intercept
        status_dict["resid_mean"] = self.resid_mean
        status_dict["resid_std"] = self.resid_std

        # log the dictionary
        PTStrategy.log("[strategy-status]: {}".format(status_dict), None, self.data0) 
开发者ID:wywongbd,项目名称:pairstrade-fyp-2019,代码行数:43,代码来源:ptstrategy_cointegration.py


注:本文中的backtrader.num2date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。