@agserran said in notify_order() Race Condition:
notify_order() Race Condition
The notifications are received in the main thread via a synchronized queue (standard python machinery). Your code never leaves the main thread.
When you send orders they are managed in the main thread (ibpy puts them in a socket and there they go)
It cannot as such be a race condition, because only 1 thread is involved.
Some examples with what you do would be needed.
@sagittarius19 said in How to filter large stock universe then run trading system on small group:
@backtrader thanks for the help regarding this. I know its prolly a very simple fix. Here is what I updated to, and im still getting an error.
lines = ('symbol')
params = (('symbol', -1),)
btfeeds.PandasData.datafields = btfeeds.PandasData.datafields + [u'symbol']
File "c:\Python27_path\Python27 Scritps\Extended pandas import attempt4.py", line 13, in <module>
File "c:\Python36\lib\site-packages\backtrader\lineseries.py", line 364, in __new__
File "c:\Python36\lib\site-packages\backtrader\lineseries.py", line 130, in _derive
clslines = baselines + lines
TypeError: can only concatenate tuple (not "str") to tuple
When i put another dummy value next to it, I got this error.
lines = ('symbol','blank')
params = (('symbol', -1),('blank', -1),)
btfeeds.PandasData.datafields = btfeeds.PandasData.datafields + [u'symbol', u'blank']
File "c:\Python27_path\Python27 Scritps\Extended pandas import attempt4.py", line 49, in <module>
File "c:\Python36\lib\site-packages\backtrader\cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "c:\Python36\lib\site-packages\backtrader\cerebro.py", line 1209, in runstrategies
File "c:\Python36\lib\site-packages\backtrader\feed.py", line 435, in preload
File "c:\Python36\lib\site-packages\backtrader\feed.py", line 476, in load
_loadret = self._load()
File "c:\Python36\lib\site-packages\backtrader\feeds\pandafeed.py", line 255, in _load
line = self.p.dataname.iloc[self._idx, colindex]
File "c:\Python36\lib\site-packages\backtrader\linebuffer.py", line 222, in __setitem__
self.array[self.idx + ago] = value
TypeError: must be real number, not str
Does datas not allow for non numerical values to be in the columns?
All values are floats. This is not a database.
This was already answered in another post and your assumption is nowhere to be found that things are separated by strategy.
The broker is a single account broker. Anything you do, you do it on a single account. Positions will be closed on that account and tradeid is just a marker for the separation of an artificial thing which is a Trade (a collection of operations)
@blonc said in tradeid - multiple strategies on same symbol:
do I need to also include the data?
If you don't, the 1st data in the system will be used. This is in the documentation.
@blonc said in passing data to strategy via an *args:
the bellow issue:
And what's exactly the issue?
That's a well defined and documented behavior of the platform. It has also been discussed before by people who wanted to access data before all warm-up periods were fulfilled and worked using prenext and adding multiple checks.
@predri said in Including data from a database:
AttributeError: 'DataFrame' object has no attribute 'setenvironment'
Yes. You cannot pass a DataFrame to cerebro and expect things to work.
As pointed out by @Laurent-Michelizza, showing us what you do could be helpful.
@laurent-michelizza said in more data more problems:
That could happen if your data doesn't have the same start/end dates or is not properly aligned
Only the 1st. The system won't enter the next phase of the strategy until all data feeds (and also the associated indicators) have covered the warm-up period (aka as minperiod)
The reason is clear: in next all elements are guaranteed to have a value available at index . Hence the need to await the minimum period of all elements to be consumed.
If you need to access data before, use prenext, but each element will have to be checked for actual data.
Docs - Operating the Platform
Docs - Strategy
It works for everyone else and it is a defined value in the matplotlib sources.
Either your matplotlib installation is corrupted, you have a version which pre-dates anything which was ever used with backtrader or something else.
@blonc said in analyzer with multiple strategies - results[n] no matter n gives identical results.:
it seems to be giving me results for the entire system not independent strategies.
Yes. The broker is a single account broker. Nowhere it is stated that strategies operate on individual accounts. Actually, the examples that show multiple strategies operating, show that they operate on the same account.
If you want strategies that operate on different accounts, run them with different cerebros.
The main point here is: there is a single strategy which is used against different pairs.
The optimization is to optimize the parameters of a strategy. What you want is to optimize for pairs and that's something which is not the target of the optimization. For each pair you can optimize the other parameters.
But if you insist (from your other post) in that data feeds are passed as params you will probably hit a wall with the optimization approach.
@blonc said in drawdown per trade in def notify_trade()::
I know you can get drawdown in the analyzer as wellbut that seems to just be the max drawdown
Wrong knowledge then. Docs - Analyzers
Quoting from the DrawDown docs:
Returns a dictionary (with . notation support and subdctionaries) with
drawdown stats as values, the following keys/attributes are available:
- ``drawdown`` - drawdown value in 0.xx %
- ``moneydown`` - drawdown value in monetary units
- ``len`` - drawdown length
- ``max.drawdown`` - max drawdown value in 0.xx %
- ``max.moneydown`` - max drawdown value in monetary units
- ``max.len`` - max drawdown length