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/

    Looking for a Quandl/Sharadar CSV Data Loader

    General Code/Help
    2
    4
    158
    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.
    • C
      carsten last edited by

      I'm new to backtrader (coming from Zipline) and I'm looking for a pice of code which correctly load a Quandl Sharadar price csv datafile. (SEP )
      Could someone provide this? I tried to change may Zipline ingesting code but it's not working...

      thanks in advance

      1 Reply Last reply Reply Quote 0
      • C
        carsten last edited by

        I build this data Loader, which reads around 16.000 tickers from the Sharadar SEP file.(draft copy from my Zipline loader)
        I'm not sure if I handle the ticker correctly.

        Inside the loop I read for one ticker all dates and pass it to the data=PandasData(dataname=df)
        and then to cerebro.adddata(data, symbol) ; symbol contains the stain of the ticker, like 'AAPL'
        Where to supply the ticker correctly?

        Thanks

        import backtrader as bt
        import pandas as pd
        from datetime import datetime
        from tqdm import tqdm 
        
        
        class PandasData(bt.feeds.PandasData):
                   
                params = (
                ('datetime', None),
                ('open','open'),
                ('high','high'),
                ('low','low'),
                ('close','close'),
                ('volume','volume'),
                ('openinterest',None),
                                        )
        
        def read_Quand_SEP_dump(startdate,enddate):
        
            file_name='/Users/carsten/ziplinetools/data/quandl/SHARADAR_SEP.csv'
            
            print("starting ingesting data from: {}".format(file_name))
        
            df = pd.read_csv(file_name, index_col='date', parse_dates=['date'], na_values=['NA'])
            print('loaded the dump')
            
            # drop unused columns, dividends will be used later
            df = df.drop(['lastupdated', 'dividends', 'closeunadj'], axis=1)   
            
            for index, df in tqdm(df.groupby('ticker')):   
                    
                df_new = df.sort_index()    
                #print(df)    
                
                symbol = df.iloc[0,0] # get ticker symbol
                #print(symbol)    
          
                df=df.drop(df[  df.index < startdate ].index)
        
                df=df.drop(df[  enddate < df.index ].index)
                
                df = df.drop(['ticker'], axis=1)
                
                data=PandasData(dataname=df)
                
                cerebro.adddata(data, symbol)       
                
            
        cerebro = bt.Cerebro()
        read_Quand_SEP_dump(datetime(2010,1,1) , datetime(2015,12,31))
        
        
        
        1 Reply Last reply Reply Quote 0
        • C
          crunchypickle last edited by

          looks fine to me

          1 Reply Last reply Reply Quote 0
          • C
            crunchypickle last edited by

            if its not working maybe you're missing session start and end params

            https://community.backtrader.com/topic/3269/compression-using-daily-and-minute-timeframes-unsuccessful-during-replaydata/10

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