Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    General Discussion
    2
    3
    2138
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Curtis Miller
      Curtis Miller last edited by

      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.

      Blog posts: Walk Forward Analysis Demonstration, Stock Trading Analytics and Optimization

      Books/Video Courses: Unpacking NumPy and Pandas

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        Curtis Miller 1 Reply Last reply Reply Quote 1
        • Curtis Miller
          Curtis Miller @backtrader last edited by

          @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.

          Blog posts: Walk Forward Analysis Demonstration, Stock Trading Analytics and Optimization

          Books/Video Courses: Unpacking NumPy and Pandas

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors