- Remove unused files
- README update, Docstring corrections, documentation corrections
- Update travis settings
Available via pip
A summary of what's on the table:
Time Scheduled Functions/Callbacks [Done] Functions will be called at specific times (periodical calling like ... "every 60 minutes starting at 08:30" may be considered) Timezone considerations
tzbounded like the data feeds
pytzdoesn't have a notion of
local timezone. This poses a small challenged when it comes to accept times which are referring to the actual local time (it may not seem so in real time, but it is in backtesting, in which the datetime reference is marked by the data feeds being backtested)
The best possible place to add the scheduling seems to be in the strategy's
__init__ method and as such should be a method of
This doesn't preclude having a global scheduling which could be entered in
cerebro to control any strategy.
Collection of numpy/pandas/statsmodel dependent indicators [Done] The discussions here have given birth to some. So far none has been added to the package for a good reason: backtrader was meant to be a pure Python package, in the sense that it wouldn't need any external dependencies beyond a regular Python distribution. (With the exception of
matplotlib if plotting was wished)
But at some point in time and even it not based on
numpy arrays, those indicators should make it into the main distribution
Reverting Resampling/Replaying to the original model [Discarded]
Once the above items are done ... v2 can be kickstarted to try to
The event is over ...
and we even ...
A repository with the snippets:
There you will also find a PDF with the notes that were taking during the event (including the pictures)
And of course ... the best picture ever
Some of the contributions which were in the queue would for sure be nice additions for some users of `backtrader´. In order to allow for a seamless integration of those for as many people as possible, the following approach will be taken
A side project named
backtrader_contrib will be created
This project will accept pull requests
Elements submitted (indicators, analyzers, ...) will be injected into the main backtrader package
The licensing is left open to the user with one exception: no GPLv2. Being the reason that some licenses like Apache License 2.0 is not compatible with GPLv2, but it is with GPLv3
The repository will contain the license text for GPLv3, ASF 2.0, MIT, BSD
The repository will be published as a
pip package on a regular basis
This is a very recent error introduced with this commit: https://github.com/backtrader/backtrader/commit/8f537a1c2c271eb5cfc592b373697732597d26d6
In attempting to fix the
bool problem if you only had 1 trade the proper
not to identify lost trades was lost.
This is now fixed in this push to the
development branch: https://github.com/backtrader/backtrader/commit/cc2751a5f53166f68c5340eb876579f1a5590bf5
It would seem that downloading from Yahoo is not full of quirks and column swaps anymore. The feed has been cleaned up, removing traces of the original API and making it clearer and with more parameters where possible. The README in the repositovy has also been updated to reflect this fact.
github tracker was becoming a type of bulletin board with questions and requests intermixed with any real issues.
And some users were even answering others' questions and even fulfilling some coding requests.
Hence the decision to try to unify everything under a community board which anyone can look into and where those questions, doubts and others can be better followed and managed.
It will hopefully be of help for those who like
backtrader and find it useful
sizer can be used as a portfolio manager in the sense that it can:
sizerhas access to the
strategyin which is running and the associated
brokerand with it to the universe of assets and for example net liquidation value
This means complex logic can be implemented to support the mentioned criteria: Margins, Var.
sizer cannot do:
A fully fledged portfolio manager would require development (not light for sure) and popular support (or other art of) for such a feature would be needed.
The solution above is for sure one that works. There are alternatives.
For example, Sizer` instances have a specific attribute which was thought for such thing.
strategy(See the docs: Sizers - Smart Stakng )
Cerebro instances share the same array of data feeds. With that in mind the code above could look different.
class VaRContracts(bt.Sizer): params = (('percent', 1), ('leverage', 40000), ('scaled', None), ('reverse', False), ('didx', 0), ) def __init__(self): self._data = self.strategy.datas[self.p.didx] def _getsizing(self, comminfo, cash, data, isbuy): self.pchg = self.calc_pchg(self._data.close.get(size=51))
This uses an numeric index to address the array.
Using names could make even more sense. This has the advantage that you don't need to have created the data feed before adding the sizer.
cerebro.addsizer(lsizers.VaRContracts, percent=1, leverage=args.leverage, scaled=args.scaled, dataname='SPY') cerebro.adddata(data0, name='SPY')
class VaRContracts(bt.Sizer): params = (('percent', 1), ('leverage', 40000), ('scaled', None), ('reverse', False), ('dataname', None), ) def __init__(self): self._data = self.strategy.getdatabyname(self.p.dataname) def _getsizing(self, comminfo, cash, data, isbuy): self.pchg = self.calc_pchg(self._data.close.get(size=51))
One of the design goals of backtrader was to be able to quickly prototype things and that's why one can define and redefine what's in the data sources and things derived from the data sources.
If your data already contains the information in the
csv format, you simply need to extend one of the
CSV data feeds to load your extra column and it will be available to you.
This topic is therefore of course covered in the documentation: Extending a Data Feed
You still need to tell
CSVGenericData where your fields are. Have a look for it at Data Feed Reference
There is a blog post documenting the birth of
GenericCSVData: Blog Post
In addition and maybe to full simulate an indicator you can wrap the extra data value in an indicator:
class MyIndicator(bt.Indicator): lines = ('myline',) def __init__(self): self.lines.myline = self.data.myvaluename
myvaluename is the name you will assign to the extra data value present in your feed.
"Simulating this with backtrader appears to result in errors."
backtrader is only doing what you are telling it to do. That isn't an error.
In order notification, if buy order is executed I execute two sell orders: one limit order with stop loss, and one stop order with take profit. This eventually fails and results in strategy executing both of the sell orders. Ideally if one of these sell orders is executed, i would like the other one to be instantly killed.
It doesn't fail. It simply doesn't fulfill your own expectations (it is nowhere stated in the documentation that one order will be cancelled because the other is executed)
You are looking for
OCO (Order Cancels Order) functionality and this is not implemented in backtrader
How should I code takeprofit/stoploss on my positions?
In the absence of
OCO, a dictionary can do the trick, by adding two entries. In one the stop-loss order is the key and the take-profit order is the value. In the second entry the roles are reversed.
Upon being notified of the execution of one order, inspection of the dictionary allows cancelling the pending order
Should I extend the bbroker itself to support stoploss/takeprofit?
The platform is open.