當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。