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/

    Optimization: How to test strategy on different datafeeds

    General Code/Help
    2
    2
    475
    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.
    • J
      jf last edited by

      Dear community,

      I managed to test different parameters of a strategy (eg. different moving-average window lengths) on a fixed datafeed. However, I failed so far to test a fixed set of parameters on different datafeeds.

      For example (simplified), I would like to test a simple moving average crossover strategy with a window length of 7 days for three different stocks such as Apple, Google, Facebook, etc and see where it performs best.

      I created a list with the different tickers, and then use

      asset = random.sample(tickerlist,1)

      Then for import something like:

      data = bt.feeds.PandasData(dataname=asset)

      This way I get a ticker out of my list. I then set all the optimization parameters that could affect data pre-loading to false:

      cerebro = bt.Cerebro(stdstats=False, optreturn=False, runonce=False, preload=False, optdatas=False, maxcpus=1)

      However, it seems that the "random.sample" is not re-executed at each run, as it always re-loads the same datafeed.

      Any idea on how I could solve this would be highly appreciated!

      Thanks,
      Jascha

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

        Some selected code lines don't really help. But most probably you believe that you can run multiple times, which isn't true. You need to create and run a new cerebro instance for each scenario you want to tes.

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