I can confirm it was the case for long time, now it seems it's fixed, I even posted about it on reddit AlgoTrading
Best posts made by MrKalindro
-
RE: Forum registration is broken
-
RE: PnL for every data
@run-out You are right, I thought there may be some ready option for it, but just simple:
def __init__(self): self.coins_indicators[d]["pnl"] = 0 def notify_trade(self, trade): if trade.isclosed: self.coins_indicators[trade.data]["pnl"] += trade.pnl
Get's the job done, thank you!
Latest posts made by MrKalindro
-
RE: PnL for every data
@run-out You are right, I thought there may be some ready option for it, but just simple:
def __init__(self): self.coins_indicators[d]["pnl"] = 0 def notify_trade(self, trade): if trade.isclosed: self.coins_indicators[trade.data]["pnl"] += trade.pnl
Get's the job done, thank you!
-
PnL for every data
Hello guys,
I was wondering what could be the best approach to track PnL (and maybe drawdown, that would be amazing) for every data in scenario where I backtest a set of datas (250) as a form of portfolio with ranking? I would love to evaluate which assets brought the most profit/DD, not only the overall portfolio return. I can imagine that instead of running a backtest for a set of data, I could split the logic to run 250 single backtest, but it's not the best approach. I was also thinking about appending a dict on every next() with some trade_notify, is there some more sophisticated way to approach thsi topic?
-
RE: Forum registration is broken
I can confirm it was the case for long time, now it seems it's fixed, I even posted about it on reddit AlgoTrading
-
RE: Backtrader
I love backtrader but I'm not playing on futures. I know that TradeStation is perfect for it. I imagine I will move to futures soon. But I'm curious since TS is apparently so good, what are the advantages of backtrader that you want to use it instead of TS?
-
RE: Array index out of range for lower period params
I made it work. I had to delete enough rows so the 1h dataframe that the data is taken from starts on any day but at 23:00:00. I still don't know why it matters and how. I guess it's coding in a nutshell (fixing the error I don't know why exists by guessing). I can only guess, maybe data resampling from 1 hour to 1 day only occurs when there is a full day available (from 00:00 to 24:00)? And when the data stated on for ex. 2:00, there were 22 1h candles that envelope wanted to plot on (with a lower period than 22 it could), where ATR couldn't even start as there was no 1D candle. And when it starts at 23:00 both can start plotting on next candle. If someone knows what is/was the issue I'm happy to listen, hope it won't show again at some point.
-
RE: Array index out of range for lower period params
When I drop a few rows it works with a particular period. To be exact, when I drop 12 rows (12 hours of data), I'm able to use 10-period envelope (for 9 period it crashes). When I drop 13 rows, I can use 9 (and it goes to 21 rows for period 1). When I delete more than 21 it crashes again for numbers it didn't crash before removing that much. I can see that it's connected to those periods and the amount of it or something but I'm going insane a bit as I can't wrap my head around what's the exact problem.
-
RE: Array index out of range for lower period params
I noticed that if I drop 5 first rows of the dataframe the datas use (data_1d is resampled data_1h so they are born from the same dataframe) it happens on different datasets. I guess it's some issue with coupling? Or it's maybe when the backtest start's in the middle of the week or something? So it makes me think even more I have to trim the data somehow to make it work.
-
RE: Date Axis does not show up on plot
Afaik it's matplotlib issue, there are many of them with the newest version. I recommend downgrading to lower version (3.0.3 works perfectly for me).
-
Array index out of range for lower period params
Hello! So I coded a bit with backtrader, my backtests works just as intended to a point. When I change the period of Envelope to 16 and below (I swear some tweaks ago it was 22 and below...) I get an error:
Traceback (most recent call last): File "F:/xxx/Showoff.py", line 102, in <module> Cerebro.run() File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies self._runnext(runstrats) File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1630, in _runnext strat._next() File "F:\xxx\venv\lib\site-packages\backtrader\strategy.py", line 347, in _next super(Strategy, self)._next() File "F:\xxx\venv\lib\site-packages\backtrader\lineiterator.py", line 263, in _next indicator._next() File "F:\xxx\venv\lib\site-packages\backtrader\lineiterator.py", line 263, in _next indicator._next() File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 621, in _next self.nextstart() File "F:\xxx\venv\lib\site-packages\backtrader\lineroot.py", line 144, in nextstart self.next() File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 744, in next self[0] = self.operation(self.a[0], self.b[0]) File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 163, in __getitem__ return self.array[self.idx + ago] IndexError: array index out of range Process finished with exit code 1
The problem is it only works on some datasets, for some it works with any period.
The probe of the code that works standalone and causes the error is:
class ATRP(bt.indicators.AverageTrueRange): def next(self): self.lines.atr[0] = (self.lines.atr[0] / self.data[0]) * 100 class MovingAverageSimpleEnvelope(bt.indicators.MovingAverageSimpleEnvelope): params = (("period", 10),) class Envelope_strategy(bt.Strategy): def __init__(self): self.ATRP = ATRP(data_1d) self.perc = self.ATRP / 2 self.Envelope = MovingAverageSimpleEnvelope(data_1h, perc = self.perc)
I think I understand what is the problem, it's because I set Envelope perc as the ATRP I created. When it's set as a fixed int it works perfectly. So my small brain thinks that with a lower period the Envelope tries to plots sooner, before the ATRP gives data (and it requires the data from it) and it causes the error. I'm not sure how could I fix if that's the problem, make the Envelope wait a bit? (But I think it's implemented in Cerbero to some extent). Or remove some rows from Envelope data so it's equal? Thanks for help!
-
RE: Envelope indicators are not available, can't pass params
Yeah thanks @ab_trader it's Pycharm or other big IDE's thing. It's just notification errors, the script runs smoothly but the autofill doesn't work with many commands. Just gotta know that it's a thing and not worry about ugly prompts.