@run-out Amazing, thanks a lot! Your help in this regard is highly appreciated!
Best posts made by jf
-
RE: Indicator for Log Returns of data feeds
-
RE: Save cerebro plot to file
Ok great, thanks! On my search I also came across this website, where the author shows how he creates nice backtrader performance reports in PDF format. It is not exactly what I was looking for, but helped me a lot on the way. You can find the code / template files on github.
Best,
Jascha -
RE: Analyzers.Returns - ValueError: math domain error
I get the same error with bt.analyzers.LogReturnsRolling and as far as I understood the problem the issue was also a 0 in the calculation. I assume that a similar fix could be the solution?
Once I also stumbled uppon a zero division error in the vwr analyzer in line 154 of vwr.py (dt = pn / (pi * math.exp(ravg * n)) - 1.0)
Best, J
Latest posts made by jf
-
RE: LinePlotterIndicator: plot y-axis in log scale
@ab_trader Thanks for your quick reply, this is highly appreciated!
I tried to do this, but it did not work. I guess the issue is that the indicator that I plan to plot is not a plain-vanilla indicator, but rather an indicator that I divided by a value.
import numpy as np
... (blabla)...
self.inds['signal1'] = self.inds['signalA']/np.log(23) #just taking 23 to make things understandable, this is not what I am actually doing :-)... self.inds['signal1'].plotinfo.plotlog = True signalplotter = bt.LinePlotterIndicator(self.inds['signal1'])
Without the "self.inds['signal1'].plotinfo.plotlog = True" the line is plotted nicely, just not in log scale. When I add the ".plotinfo.plotlog" then I receive the following Error:
AttributeError: 'LinesOperation' object has no attribute 'plotinfo'
I also tried to define the logplot for "self.inds['signalA']". While I don't get an error message there (which makes sense because it is an indicator and not a "LinesOperation"), the information seems to get lost on the way down to the LinePlotterIndicator...
Would be amazing if you have an idea how to solve this puzzle :-)!
Best,
J -
LinePlotterIndicator: plot y-axis in log scale
Dear Community,
I succeeded in plotting a custom-built indicator with bt.LinePlotterIndicator, but I just couldn't figure out how to convert the y-axis to log-scale.
This is my first attempt:
signalplotter = bt.LinePlotterIndicator(self.inds['signal1'], plotlog=True)
And I also tried:
signalplotter = bt.LinePlotterIndicator(self.inds['signal1']) signalplotter.plotinfo.plotlog = True
... but this also did not work.
It would be fantastic if someone could point me into the right direction!
Thanks a lot,
J -
RE: Indicator for Log Returns of data feeds
@run-out Amazing, thanks a lot! Your help in this regard is highly appreciated!
-
RE: Indicator for Log Returns of data feeds
Thanks for pointing this out. I also came across the analyzer, but as far as I understand the backtrader platform this approach doesn't work as analyzers are "a different type of animal" when compared to indicators. Or have you been able to use an analyzer as an input inside next?
-
Indicator for Log Returns of data feeds
Dear Community, dear @backtrader
I try to create an indicator that lets me calculate the log-returns for a given period for each "data". The following code failed, I assume that I made a mistake with ApplyN?
class LogReturns(bt.Indicator): lines = ('logreturns',) def __init__(self): self.lines.logreturns = bt.ind.ApplyN(bt.ind.PercentChange(self.data, period=1) + 1, func=lambda x: math.log(x[0]))
Can you kindly show me how I can correctly calculate a log-return indicator?
Thanks!
J -
RE: cerebro.plot on Colab not displaying chart
I was struggling with the same problem, this is some kind of workaround...
from google.colab import files cerebro.plot()[0][0].savefig('samplefigure.png', dpi=300) files.download('samplefigure.png')
-
RE: Analyzers.Returns - ValueError: math domain error
I get the same error with bt.analyzers.LogReturnsRolling and as far as I understood the problem the issue was also a 0 in the calculation. I assume that a similar fix could be the solution?
Once I also stumbled uppon a zero division error in the vwr analyzer in line 154 of vwr.py (dt = pn / (pi * math.exp(ravg * n)) - 1.0)
Best, J
-
RE: Plot observer (StopLoss/TakeProfit) on corresponding price plots
@ab_trader Hi ab_trader: I would like to achieve the same as you (create an observer to plot a trailing stop-loss). Would it be possible that you share how you achieved that? What exactly is the definition of self._owner.sl_price? Thanks for your help!
-
RE: ploting StopLimit, StopTrail observers
@silverbald I have the same issue, would you mind posting your solution that works? Thanks! J
-
Optimization: How to test strategy on different datafeeds
Dear community,
I managed to test different parameters of a strategy (eg. different moving-average window lengths) on a fixed datafeed. However, I failed so far to test a fixed set of parameters on different datafeeds.
For example (simplified), I would like to test a simple moving average crossover strategy with a window length of 7 days for three different stocks such as Apple, Google, Facebook, etc and see where it performs best.
I created a list with the different tickers, and then use
asset = random.sample(tickerlist,1)
Then for import something like:
data = bt.feeds.PandasData(dataname=asset)
This way I get a ticker out of my list. I then set all the optimization parameters that could affect data pre-loading to false:
cerebro = bt.Cerebro(stdstats=False, optreturn=False, runonce=False, preload=False, optdatas=False, maxcpus=1)
However, it seems that the "random.sample" is not re-executed at each run, as it always re-loads the same datafeed.
Any idea on how I could solve this would be highly appreciated!
Thanks,
Jascha