Hello, after further investigating the subject, I asked in a telegram group called "Python for trading"
in this group, I managed to find the answer, many thanks to @ultra1971 , he is the one who generated the code and after my question he quickly answered with a valid answer which allows to obtain the quantstats sheet without having to use pyfolio adding modifications in the timeframe in which the backtrader runs. The solution is the next.
First a custom analyzer is created.
class QuantStats(bts.Analyzer):
"""
Analyzer returning market and bechmark values for report returns to quantstats
"""
params = (('benchmark', 0),)
def start(self):
super().start()
def create_analysis(self):
self.rets = {}
#self.vals = 0.0
def notify_cashvalue(self, cash, value):
#self.vals = (value)
benchmark_value = self.datas[self.p.benchmark].close[0]
self.rets[self.strategy.datetime.datetime()] = (value, benchmark_value)
def get_analysis(self):
return self.rets
Then added to Cerebro.
cerebro.addanalyzer(QuantStats, _name='qs')
thestrats = cerebro.run()
thestrat = thestrats[0]
returns_analyzer = thestrat.analyzers.getbyname("qs").get_analysis()
df_qs = pd.DataFrame(returns_analyzer).T
returns = qs.utils.to_returns(df_qs.iloc[:, 0])
qs.reports.html(returns,output='test_qs.html', )
Finally, the analyzer data is obtained and the modified returns are added to the sheet.
I hope this helps the community, I had seen many people with these questions and could not find an answer.
Thanks to @ultra1971, who managed to solve the problem and clear up all my doubts, thank you very much!