@RandomTrader88 Exactly this happened with me. I tried to run a strategy with no buy/sell signal and got this error.
Best posts made by zuj
-
RE: cerebro.plot() error
Latest posts made by zuj
-
Exception while optimizing
I am trying to optimize a strategy. It is working fine when I am using indicators such as AnnualReturn, Drawdown but whenever I use Sharpe or Sharpe_A, it throws the following exception and starts running endlessly.
Starting Portfolio Value: 100000.00 Exception in thread Thread-75: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/usr/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.6/multiprocessing/pool.py", line 463, in _handle_results task = get() File "/usr/lib/python3.6/multiprocessing/connection.py", line 251, in recv return _ForkingPickler.loads(buf.getbuffer()) AttributeError: Can't get attribute 'Lines_LineSeries_LineIterator_DataAccessor_ObserverBase_Observer_DataTrades_a179e3eb9e354bd68d683450f934ee8a' on <module 'backtrader.lineseries' from '/usr/local/lib/python3.6/dist-packages/backtrader/lineseries.py'>
I think that this might be because of some deadlock due to multiprocessing. How can I correct this?
-
RE: Difference in number of trades executed and actual order issued during backtesting
@run-out I can't share my whole strategy but I will show the part in which I issue trades because that's what matters for the notify_trade() to the best of my knowledge.
if self.currentPosition is None: if condition1: self.log("Long Entry") self.sell(self.data) self.buy(self.data1) self.currentPosition="long" elif condition2: self.log("Short Entry") self.buy(self.data) self.sell(self.data1) self.currentPosition="short" else: if self.currentPosition=="long" and condition3: self.log("Long Exit") self.close(self.data) self.close(self.data1) self.trade_count_sym1+=1 self.trade_count_sym2+=1 self.currentPosition=None elif self.currentPosition=="short" and condition4: self.log("Short Exit") self.close(self.data) self.close(self.data1) self.currentPosition=None self.trade_count_sym1+=1 self.trade_count_sym2+=1
trade_count_sym1 and trade_count_sym2 both turn out to be 409 while the trade count from analyzers are mentioned in the original post
-
Difference in number of trades executed and actual order issued during backtesting
I have a simple pairs trading code in which I buy one symbol and sell another symbol when a condition is met and vice versa when another condition is met. I haven't put any restrictions in backtrader. After analyzing the results using notify_order and notify_trade, I am getting total trades ([('total', 369), ('open', 2), ('closed', 367)]) while for sym1 trades are 241 and sym2 trades are 126. I also added a global variable in next() to record how many times self.close() is called for each symbol and it's 409 for both. Why are there discrepancies in the results?
-
RE: How to get return values for every closed trade?
@run-out It throws an error
45 dir = 'short' ---> 46 if trade.history[0].event.size > 0: dir = 'long' 47 48 pricein = trade.history[len(trade.history)-1].status.price IndexError: list index out of range
-
How to get return values for every closed trade?
I am trying to create a Monte Carlo simulation that's why I require return values for every closed trade, I don't see any analyzer that can give me that. returns from the pyfolio analyzer is giving portfolio returns. Any help will be appreciated.
-
Data Delay after launching live trading using backtrader
Consider this scenario, I am trying to backtest a simple sma crossover strategy with moving average of 30 days. It will be fine in backtesting the strategy and backtrader actually waits for 30 days before it starts trading. But what about when you make that strategy live? You already have enough data to start trading but when we run the same code for live trading, is it gonna wait for 30 days to get sma values? If so, what should I do to use all the past available data on the first day of running the code live?
-
self.buy() usage to short one stock while go long in another stock
I am trying to replicate the code given on this page. According to this when have to long a spread, I have to just call self.buy(). But I have to buy x amount of 1 stock while short beta*x amount of another stock. Where do I put that logic in self.buy()? It doesn't even calculate beta which is required for this type of algorithm to work.
-
Running multiple strategies with different brokers
I have created various algorithms that are working fine when traded live but I'm not such a good programmer so I have to use different brokers for different strategies and then run those strategies on different terminals. They are working fine for now but I'm not sure I will be able to manage and keep track of these strategies for long. There are now just too many terminals open on my screen trading money. Can someone please tell me how to wrap them up into a nice little application from where I can deploy them and manage them? Also, now I have to allocate money to any strategy manually via brokers but I want to manage my portfolio automatically for example if 5 strategies are running and I add a 6th one, it just automatically assigns them same risk. Any help will be much appreciated.
-
RE: cerebro.plot() error
@RandomTrader88 Exactly this happened with me. I tried to run a strategy with no buy/sell signal and got this error.