コード例 #1
0
    def setcommission(self,
                      commission=0.0,
                      margin=None,
                      mult=1.0,
                      commtype=None,
                      percabs=True,
                      stocklike=False,
                      interest=0.0,
                      interest_long=False,
                      leverage=1.0,
                      automargin=False,
                      name=None):
        '''This method sets a `` CommissionInfo`` object for assets managed in
        the broker with the parameters. Consult the reference for
        ``CommInfoBase``

        If name is ``None``, this will be the default for assets for which no
        other ``CommissionInfo`` scheme can be found
        '''

        comm = CommInfoBase(commission=commission,
                            margin=margin,
                            mult=mult,
                            commtype=commtype,
                            stocklike=stocklike,
                            percabs=percabs,
                            interest=interest,
                            interest_long=interest_long,
                            leverage=leverage,
                            automargin=automargin)
        self.comminfo[name] = comm
コード例 #2
0
    def setcommission(self,
                      commission=0.0,
                      margin=None,
                      mult=1.0,
                      commtype=None,
                      percabs=True,
                      stocklike=False,
                      interest=0.0,
                      interest_long=False,
                      name=None):

        comm = CommInfoBase(commission=commission,
                            margin=margin,
                            mult=mult,
                            commtype=commtype,
                            stocklike=stocklike,
                            percabs=percabs,
                            interest=interest,
                            interest_long=interest_long)
        self.comminfo[name] = comm
コード例 #3
0
ファイル: broker.py プロジェクト: zanDaYa/backtrader
class BrokerBase(with_metaclass(MetaBroker, object)):
    params = (
        ('commission', CommInfoBase(percabs=True)),
    )

    def __init__(self):
        self.comminfo = dict()
        self.init()

    def init(self):
        # called from init and from start
        if None not in self.comminfo:
            self.comminfo = dict({None: self.p.commission})

    def start(self):
        self.init()

    def stop(self):
        pass

    def add_order_history(self, orders, notify=False):
        '''Add order history. See cerebro for details'''
        raise NotImplementedError

    def set_fund_history(self, fund):
        '''Add fund history. See cerebro for details'''
        raise NotImplementedError

    def getcommissioninfo(self, data):
        '''Retrieves the ``CommissionInfo`` scheme associated with the given
        ``data``'''
        if data._name in self.comminfo:
            return self.comminfo[data._name]

        return self.comminfo[None]

    def setcommission(self,
                      commission=0.0, margin=None, mult=1.0,
                      commtype=None, percabs=True, stocklike=False,
                      interest=0.0, interest_long=False, leverage=1.0,
                      automargin=False,
                      name=None):

        '''This method sets a `` CommissionInfo`` object for assets managed in
        the broker with the parameters. Consult the reference for
        ``CommInfoBase``

        If name is ``None``, this will be the default for assets for which no
        other ``CommissionInfo`` scheme can be found
        '''

        comm = CommInfoBase(commission=commission, margin=margin, mult=mult,
                            commtype=commtype, stocklike=stocklike,
                            percabs=percabs,
                            interest=interest, interest_long=interest_long,
                            leverage=leverage, automargin=automargin)
        self.comminfo[name] = comm

    def addcommissioninfo(self, comminfo, name=None):
        '''Adds a ``CommissionInfo`` object that will be the default for all assets if
        ``name`` is ``None``'''
        self.comminfo[name] = comminfo

    def getcash(self):
        raise NotImplementedError

    def getvalue(self, datas=None):
        raise NotImplementedError

    def get_fundshares(self):
        '''Returns the current number of shares in the fund-like mode'''
        return 1.0  # the abstract mode has only 1 share

    fundshares = property(get_fundshares)

    def get_fundvalue(self):
        return self.getvalue()

    fundvalue = property(get_fundvalue)

    def getposition(self, data):
        raise NotImplementedError

    def submit(self, order):
        raise NotImplementedError

    def cancel(self, order):
        raise NotImplementedError

    def buy(self, owner, data, size, price=None, plimit=None,
            exectype=None, valid=None, tradeid=0, oco=None,
            trailamount=None, trailpercent=None,
            **kwargs):

        raise NotImplementedError

    def sell(self, owner, data, size, price=None, plimit=None,
             exectype=None, valid=None, tradeid=0, oco=None,
             trailamount=None, trailpercent=None,
             **kwargs):

        raise NotImplementedError

    def next(self):
        pass
コード例 #4
0
class BrokerBase(with_metaclass(MetaParams, object)):
    params = (('commission', CommInfoBase(percabs=True)), )

    def __init__(self):
        self.comminfo = dict()
        self.init()

    def init(self):
        # called from init and from start
        if None not in self.comminfo:
            self.comminfo = dict({None: self.p.commission})

    def start(self):
        self.init()

    def stop(self):
        pass

    def getcommissioninfo(self, data):
        if data._name in self.comminfo:
            return self.comminfo[data._name]

        return self.comminfo[None]

    def setcommission(self,
                      commission=0.0,
                      margin=None,
                      mult=1.0,
                      commtype=None,
                      percabs=True,
                      stocklike=False,
                      interest=0.0,
                      interest_long=False,
                      name=None):

        comm = CommInfoBase(commission=commission,
                            margin=margin,
                            mult=mult,
                            commtype=commtype,
                            stocklike=stocklike,
                            percabs=percabs,
                            interest=interest,
                            interest_long=interest_long)
        self.comminfo[name] = comm

    def addcommissioninfo(self, comminfo, name=None):
        self.comminfo[name] = comminfo

    def getcash(self):
        raise NotImplementedError

    def getvalue(self, datas=None):
        raise NotImplementedError

    def getposition(self, data):
        raise NotImplementedError

    def submit(self, order):
        raise NotImplementedError

    def cancel(self, order):
        raise NotImplementedError

    def buy(self,
            owner,
            data,
            size,
            price=None,
            plimit=None,
            exectype=None,
            valid=None,
            tradeid=0,
            **kwargs):

        raise NotImplementedError

    def sell(self,
             owner,
             data,
             size,
             price=None,
             plimit=None,
             exectype=None,
             valid=None,
             tradeid=0,
             **kwargs):

        raise NotImplementedError

    def next(self):
        pass