Navigation

    Backtrader Community

    • Register
    • 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/

    Portfolio strategies

    Indicators/Strategies/Analyzers
    2
    4
    437
    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.
    • A
      andi last edited by

      Hello!

      I am considering to give backtrader a try. However, before diving deep into the code, I've got a general question regarding portfolio strategies.

      Let's assume I have a pandas dataframe in wide format, i.e. columns representing individual assets and rows representing returns at a given time.
      I am looking for setting up a relative momentum strategy. Therefore, for every row, I need to compute a ranking. The top N assets will then be bought while the worst N assets will be sold short.

      At the end of the day, I am interested in the overall portfolio performance. Is a "portfolio strategy" like this possible to implement using backtrader or is backtrader more suited to analyze individual asset strategies?

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @andi last edited by

        @andi Yes you can definitely do this in Backtrader. Based upon what you are saying, there are two way I could recommend.

        1. You could preprocess for each stock their momentum in Pandas, and then calculate a ranking. You could then import this into Backtrader and use the ranking line.
        2. Or you could just import the OHLCV into Backtrader, and then use the built in momentum indicator to calculate the momentum for each stock at each bar. Then you could right a script to rank the results.

        Once ranked using either one or two, you sort your list and go long the best N assets and short the poorest N assets.

        Handling this type of backtest I would label as moderately difficult and may take you a bit of time to get up the backtrader learning curve.

        We're here to help as you go through it.

        Good luck.

        RunBacktest.com

        A 1 Reply Last reply Reply Quote 0
        • A
          andi @run-out last edited by

          @run-out Sounds good to me. However, just to clearify a point with respect to "portfolio evaluation": I definitely need performance reports/plots on an aggregated portfolio level. Is this possible or is the performance report only available for individual securities?

          Also, just out of curiosity, I already have a pandas dataframe with trading signals as per close in the form of +1 / -1 for long and short signals. Would it be possible to use this dataframe?

          run-out 1 Reply Last reply Reply Quote 0
          • run-out
            run-out @andi last edited by

            @andi Yes you can build reports at the portfolio level. There is an area called analyzers with built in modules or you can create your own custom reports to suit your needs.

            RunBacktest.com

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