Stock trading analytics and optimization with PyFolio and R's PerformanceAnalytics (blog post)



  • I've written a new blog post on using backtrader. In this article, I discuss performance analytics using backtrader Analyzers, writing custom Analyzers, using R PerformanceAnalytics functions in backtrader Analyzers, and PyFolio. I also took my walk forward analysis code and turned it into a function, for easier use.

    I would love to hear feedback.


  • administrators

    I attempted to use another analyzer, AnnualReturn, which computes annualized return metrics, but unfortunately it does not seem to work.

    This analyzer should be removed. It was the 1st ever implementation and was never really reworked because TimeReturn (which allows customization of the timeframe independently of the data's actual timeframe) took over.

    Noted.

    class VaR(bt.Analyzer):
        """
       Computes the value at risk metric for the whole account using the strategy, based on the R package
       PerformanceAnalytics VaR function
       """
       ...
    

    Here the proposal would be to create an Indicator first and then use the indicator inside the analyzer. The advantage is that you can plug the indicator directly into the Strategy, in an Observer or in an Analyzer.

    This is how it is actually done with the non-public ValueAtRisk indicator which is used for the management of the Morningstar - Backtrader Fund

    It's not a must, not a canonical way. It' simply handy.

    For some reason, create_full_tear_sheet() does not seem to be aware of other symbols being traded than Nvidia (NVDA). I have no idea why.

    PyFolio is a moving target. You may in any case try: create_position_tear_sheet rather than create_full...

    I recently read a response to a Quora question, written by Prof. Ben Y. Zhao at the University of Chicago that rattled me.

    Don't let yourself be bothered by someone who probably only speaks about one single thing at every social event and who only sees peers in those with a PhD an his level of focus in a single topic. This may be wrong and he may be the soul of every party, run marathons every weekend and attend charity events on Tuesdays. Even in that case, don't let yourself be bothered.

    Long story short, time is an even scarcer commodity now than it used to be for me. I’m worried about my academic success if I keep burning time like this. It also doesn’t seem like any of my new content “sticks” (it doesn’t bump up what you might call my “latent” viewership rate).

    Thus, I’m planning on this being my last “long-form” article for some time

    Time is scarce everywhere. Shorter posts will free up some time and you'll probably keep on enjoying your own posting.



  • @backtrader said in Stock trading analytics and optimization with PyFolio and R's PerformanceAnalytics (blog post):

    This analyzer should be removed. It was the 1st ever implementation and was never really reworked because TimeReturn (which allows customization of the timeframe independently of the data's actual timeframe) took over.

    Noted.

    Here the proposal would be to create an Indicator first and then use the indicator inside the analyzer. The advantage is that you can plug the indicator directly into the Strategy, in an Observer or in an Analyzer.

    I knew there had to be a better way than what I was doing. Thanks!

    Don't let yourself be bothered by someone who probably only speaks about one single thing at every social event and who only sees peers in those with a PhD an his level of focus in a single topic. This may be wrong and he may be the soul of every party, run marathons every weekend and attend charity events on Tuesdays. Even in that case, don't let yourself be bothered.

    Time is scarce everywhere. Shorter posts will free up some time and you'll probably keep on enjoying your own posting.

    Thanks for the words of encouragement! I'm going to try to keep up the blog but not make an effort to be regular about my posts. That is too much of a commitment. Anyway, I appreciate the thought.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.