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/

    Start strategy from 2008 even if some stocks was listed later

    General Code/Help
    2
    2
    39
    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.
    • S
      strazak last edited by

      Hello guys,
      I prepared the following strategy based on some fundamental indicators I select 10 stock each month and buy them. Now my current output is a map where the key is a date of entry and as value, I have a map where the key is a stock and the value is the percent of the portfolio to invest.
      Something like this:
      2018-01-29: {'JPM': 0,5, 'AAPL': 0,5}
      I wanted to apply this map to bakctrader to see the strategy analyzer outputs to select the best fundamental indicators.

      Now I have a problem as for example when my calculation output is done for 2008-2021 range a lot of stocks was not listed in 2008 and backtrader is not able to start from 2008. Is any workaround for this?

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

        @strazak
        Backtrader prefers full lines.

        Input your data using a Pandas dataframe. Start by having a full datetime index in memory available for the period you want. I tend to copy a datetime index from another similar stock I know had trading on every day for the whole period. Then simply create a dataframe of your data, then reindex to the new index with

        method='ffill'
        

        Then

        fillna(0)
        

        RunBacktest.com

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