Skip to content

Commit

Permalink
Release 1.2.3.88
Browse files Browse the repository at this point in the history
  • Loading branch information
mementum committed Mar 14, 2016
2 parents fd070df + 2be6bd8 commit eac5be9
Show file tree
Hide file tree
Showing 9 changed files with 748 additions and 9 deletions.
31 changes: 27 additions & 4 deletions backtrader/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,31 @@


class BrokerBack(with_metaclass(MetaParams, object)):
'''Broker Simulator
Parameters:
Note: use the setXXXX to set the value after instance creation
- ``cash`` (default: 10000): starting cash
- ``commission`` (default: CommInfoBase(percabs=True))
base commission scheme which applies to all assets
- ``checksubmit`` (default: True)
check margin/cash before accepting an order into the system
- ``eosbar`` (default: False):
With intraday bars consider a bar with the same ``time`` as the end
of session to be the end of the session. This is not usually the
case, because some bars (final auction) are produced by many
exchanges for many products for a couple of minutes after the end of
the session
'''
params = (
('cash', 10000.0),
('commission', CommInfoBase(percabs=True)),
('checksubmit', True),
('eosbar', False),
)

def __init__(self):
Expand All @@ -57,6 +77,9 @@ def init(self):

self.submitted = collections.deque()

def seteosbar(self, eosbar):
self.p.eosbar = eosbar

def getcash(self):
return self.cash

Expand Down Expand Up @@ -121,6 +144,7 @@ def orderstatus(self, order):
return o.status

def submit(self, order):
order.plen = len(order.data)
if self.p.checksubmit:
order.submit()
self.submitted.append(order)
Expand Down Expand Up @@ -154,7 +178,6 @@ def check_submitted(self):

def submit_accept(self, order):
order.pannotated = None
order.plen = len(order.data)
order.accept()
self.pending.append(order)
self.notify(order)
Expand Down Expand Up @@ -298,11 +321,11 @@ def notify(self, order):

def _try_exec_close(self, order, pclose):
if len(order.data) > order.plen:

dt0 = order.data.datetime[0]

if dt0 > order.dteos:
if order.pannotated:
if dt0 > order.dteos or (self.p.eosbar and dt0 == order.dteos):
# past the end of session or right at it and eosbar is True
if order.pannotated and dt0 != order.dteos:
execdt = order.data.datetime[-1]
execprice = order.pannotated
else:
Expand Down
10 changes: 9 additions & 1 deletion backtrader/cerebro.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .writer import WriterFile
from .import num2date
from .utils import OrderedDict
from .strategy import Strategy


class Cerebro(with_metaclass(MetaParams, object)):
Expand Down Expand Up @@ -189,6 +190,9 @@ def resampledata(self, dataname, name=None, **kwargs):
Any other kwargs like ``timeframe``, ``compression``, ``todate`` which
are supported by ``Resampler`` will be passed transparently
'''
if dataname in self.datas:
dataname = dataname.clone()

dataname.resample(**kwargs)
self.adddata(dataname, name=name)

Expand Down Expand Up @@ -315,7 +319,7 @@ def run(self, **kwargs):
Strategy classes added with ``addstrategy``
'''
if not self.datas:
return
return [] # nothing can be run

pkeys = self.params._getkeys()
for key, val in kwargs.items():
Expand Down Expand Up @@ -352,6 +356,10 @@ def run(self, **kwargs):
self.writers_csv = any(map(lambda x: x.p.csv, self.runwriters))

self.runstrats = list()

if not self.strats: # Datas are present, add a strategy
self.addstrategy(Strategy)

iterstrats = itertools.product(*self.strats)
if not self._dooptimize or self.p.maxcpus == 1:
# If no optimmization is wished ... or 1 core is to be used
Expand Down
8 changes: 5 additions & 3 deletions backtrader/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,13 @@ def close(self,
size = abs(size or possize)

if possize > 0:
return self.sell(data, size, price, exectype, valid,
return self.sell(data=data, size=size, price=price,
exectype=exectype, valid=valid,
tradeid=tradeid, **kwargs)
elif possize < 0:
return self.buy(data, size, price, exectype, valid,
tradeid=tradeid, **kwargs)
return self.sell(data=data, size=size, price=price,
exectype=exectype, valid=valid,
tradeid=tradeid, **kwargs)

return None

Expand Down
2 changes: 1 addition & 1 deletion backtrader/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
unicode_literals)


__version__ = '1.2.2.88'
__version__ = '1.2.3.88'
17 changes: 17 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
1.2.3.88:
- Add samples following 'Close' order corrections/improvements for
testing. Addresses #62
- Improve 'Close' execution support and correct conflicting behavior
with method checksubmit. Addresses #62
- Correct method close of strategy by using kwargs which was not
taking into account the existence of a plimit parameter in methods
buy/sell and would pass the execution type as plimit
- PandasData extension sample and data supporting discussion in
ticket #65
- If datas have been passed to cerebro, ensure cerebro has a
strategy to run against (which can get indicators, analyzers,
observers and other through the appropriate interface)
- Addresses #64 by auto-cloning datas in resampledata if the data
was already in the system
- Return a list in case cerebro.run is not run due to missing datas

1.2.2.88:
- Update of bidask sample
- SessionFiller correction to avoid moving the evaluated bar too early into
Expand Down
Loading

0 comments on commit eac5be9

Please sign in to comment.