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/

    Multiple assets backtest using bt

    Indicators/Strategies/Analyzers
    2
    3
    912
    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.
    • Sabir Jana
      Sabir Jana last edited by

      Hello,
      Thanks for the great project!
      I have optimized weights for multiple assets and would like to backtest with monthly rebalancing. Any suggestions on how to proceed with backtesting with bt? Let me give an example on how to do this using zipline

      def initialize(context):
          context.securities = {
                              'AAPL': 0.25, 
                              'ABBV': 0.3, 
                              'ABC': 0.3, 
                              'CAT': 0.075, 
                              'CSCO': 0.075
          }
          schedule_function(rebalance, date_rules.month_start(), time_rules.market_open())
      
      def rebalance(context, data):
          # Loop through the securities
          for sec, weight in context.securities.items():
              sym = symbol(sec)
              if data.can_trade(sym):
                  # Reset the weight
                  order_target_percent(sym, weight)
      

      Appreciate any help!!

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

        Have a look at this article and see if it helps.

        RunBacktest.com

        1 Reply Last reply Reply Quote 2
        • Sabir Jana
          Sabir Jana last edited by

          I found this helpful
          https://backtest-rookies.com/2020/05/09/backtrader-portfolio-rebalancing-with-alpha-vantage/
          Thanks
          SJ

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