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/

    Help!!

    General Discussion
    2
    2
    725
    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.
    • W
      waterylane last edited by

      Hi guys, it's been a couple days for me to start backtrader, before then I used zipline from Quantopian or bt (not backtrader, but the other one)..

      Obviously, this is one of the most comprehensive open source backtesting platform, but I don't know why I really confused with the codes.. So instead of building my sklearn indicators inside the system, I use my extended datafeed, but failed to feed it into the system......

      Can somebody help me to give example how feed the extended code and build the signals? I have read all the documentation, including extending datafeed but always failed to test it. Here's my datafeed, the idea is I'll buy when daily mean states > 0 and sell when daily mean states < 0. Thanks

      0_1517816381212_data.png

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

        See for example here:

        • https://community.backtrader.com/topic/158/how-to-feed-backtrader-alternative-data/15
        class CustomDataLoader(btfeeds.PandasData):
            lines = ('TOTAL_SCORE','Beta',)
            params = (
                ('openinterest',None), #None= column not present
                ('TOTAL_SCORE',-1),
                ('Beta',-1)
            )
            datafields = btfeeds.PandasData.datafields + (['TOTAL_SCORE','Beta'])
        

        and here

        • https://community.backtrader.com/topic/837/programmatically-extending-a-datafeed
        class PandasDataOptix(btfeeds.PandasData):
        
            lines = ('optix_close', 'optix_pess', 'optix_opt',)
            params = (('optix_close', -1),
                      ('optix_pess', -1),
                      ('optix_opt', -1))
        
            datafields = btfeeds.PandasData.datafields + (
        
        

        You have to add the name of your extra lines to the lines definition and extend the datafields definition.

        Once you have the lines available you only have to check in next:

        def next(self):
            if self.data.states > 0:
                self.buy()
        

        Where of course, position management may also play a role.

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