backtrader
@backtrader
Posts made by backtrader
-
Release 1.9.75.123
1.9.75.123:
- Adding extra day before dtcmp calc, as otherwise the extradays
have no effect (#388) - Fixing the issue with TWS API Bust events (err code 10225) (#396)
- Add support for ASK quotes for CASH assets (#395) plus fixes
- Remove duplicated note (#386)
- Fixing time.clock for python>=3.8 (#394)
- Changed file initiation for WriterFile to make it work under
multi-process optimization (#397) plus fixes - Fixed backend loading if a backend is loaded (Google Collab) and
backend to use on MacOSX - Fix: crumb in feeds.YahooFinanceData (#400)
- Fix color assignments, ticks line widths and some pep-8 improvements
- Fix timeframe/compression detection when plotting
- Fix default value for ticks display format on X-axis
- Sample with ta-lib SAR test
- Generic support of multiple "text/*" content types for Yahoo
- Adding extra day before dtcmp calc, as otherwise the extradays
-
RE: Backtrader's Future
Dear @vladisld,
I have just read this tread and you statement
@vladisld said in Backtrader's Future:
Since no one I guess has a full understanding of the platform yet, we probably should limit ourselves to bug fixing only, at least initially - and see how it goes.
This is probably spot on and something I have failed to realize. Since your fork doesn't yet contain any changes, I am adding a few bug fixes to the main repository and release a new version with them.
-
RE: cerebro.resample() introduces data in the future
@xyshell said in cerebro.resample() introduces data in the future:
Note: 6219.15 is the close price of the 1h data at 2020-03-20 01:00:00, while 6219.15 is also the open price of the 1min data
No. There is no such thing as the closing price of the
1-hour
data, because that data doesn't exist. Naming things properly does help.Additionally the information you provide is wrong, which is confirmed by looking at your data.
Note for the other readers: for whatever the reason, this data defies all established standards and has the following format:
CHLOVTimestamp
Your data indicates that
6219.15
is the closing price of the1-min
bar at00:59:00
, hence the last bar to go into the resampling for1-hour
between00:00:00
and00:59:00
(60 bars -if all are present-) which is first delivered to you as a resampled bar at01:00:00
6219.15
is the opening price of the1-min
bar at01:00:00
At
01:00:00
you have two bits of information available:- The current
1-min
bar for01:00:00
- The
1-hour
resampled data for the period00:00:00
to00:59:00
As expected.
-
RE: Timers
@benjomeyer said in Timers:
timername='selltimer',
Given how you pass it ... you could probably try this better
def notify_timer(self, timer, when, timername): if timername=='buytimer': self.buy_stocks() elif timername=='selltimer': self.sell_stocks()
given that you have no additional
*args
or**kwargs
. But a more general approach I would suggest thisdef notify_timer(self, timer, when, **kwargs): timername = kwargs.get('timername', None) if timername=='buytimer': self.buy_stocks() elif timername=='selltimer': self.sell_stocks()
where you can also decide if a default logic for
None
is needed.Note: notice the usage of
elif
-
RE: Building Sentiment Indicator class: TypeError: must be real number, not LineBuffer
@Kevin-Fu said in Building Sentiment Indicator class: TypeError: must be real number, not LineBuffer:
def next(self): self.date = self.data.datetime date = bt.num2date(self.date[0]).date() prev_sentiment = self.sentiment if date in date_sentiment: self.sentiment = date_sentiment[date] self.lines.sentiment[0] = self.sentiment
In any case that's probably where the error happens. There is no definition of
self.sentiment
and the indicator understands you are looking for the line namedsentiment
. The problems- Lack of variable initialization
- Conflicting naming
-
RE: Building Sentiment Indicator class: TypeError: must be real number, not LineBuffer
@Kevin-Fu said in Building Sentiment Indicator class: TypeError: must be real number, not LineBuffer:
Any input would be greatly appreciated
But you provide no input with regards to the error. Only
TypeError: must be real number, not LineBuffer
Python exceptions provided a stacktrace which points to the different line numbers in the stack ... allowing to trace the error to the origin point (and showing any potential intermediate conflict)
The error is only telling us that you are passing an object (a
LineBuffer
) there where afloat
should have been passed by you. But not where you are doing it ... which is in the stacktrace ... -
RE: DataCls does autoregister
@Kevin-Galkov said in DataCls does autoregister:
If I run the mementum/backtrader/samples/oandatest/oandatest.py , it complains:
In any, it does complay because you don't have the proper package installed, you have something for
v20
. -
RE: DataCls does autoregister
You have to use this:
The built-in module is only compatible with the old
Oanda
API.And
oandatest.py
works with the old built-in module. -
RE: Timers
Timers
go tonotify_timer
which receives thetimer
,when
it is happening and any extra*args
and**kwargs
you may created the timer with. You can use any of the latter to differentiate timers.Or you can simply use the
timer id
to associate different logic to each timer.