For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Using self CSV data failed



  • Hi, I just moved from the another platform and everything here is new to me.

    This question may be raised by the others already but I couldn't find one that I am looking for right now.

    So I tried using sample data with my own excel csv file:

    0_1537148784265_4d0d3543-b88e-45a1-b675-1ffd938fc2cc-image.png

    With this data, I wanted to see the data format on the notebook but... I failed and here are the lines that I used :

    0_1537149641335_ab756128-97cf-4476-a63f-63c152505108-image.png
    As you can see, I get None. I don't know what has gone wrong here.

    Could you help me??

    Thank you!



  • Oops, wrong code! sorry guys
    This is the one that I tried :

    0_1537149614954_b9a23f08-2c5d-4fc6-ba4d-739ab237c619-image.png

    But still getting none :p



  • Both posts contain the same scripts.

    I am really surprised that you get None: testing(...) is not defined in your posts, should be an error returned.



  • @ab_trader yup just noticed that I mixed up my codes. Sorry for this confusion.

    This is it :

    0_1537158598324_cf688c10-f4c6-4350-bddd-dc16d077fb4a-image.png

    In fact, I solved this problem using Pandas DataFeed. But I still want to figure out what I am missing here.

    Thanks again :)


  • administrators

    Glad it is solved

    @crespecular said in Using self CSV data failed:

    But I still want to figure out what I am missing here.

    Things that would be important for someone to be able to tell you

    • Don't post images, post actual code in text form and post something complete
    • Post the actual csv data (part of it) and not what you see on screen with a spreadsheet
    • Post the error message you have or if no error has happened, what your strategy logged.

    For example, I would like to now quote this thing you did print(data.getfeed()) and ask about what you tried. But I can't quote an image.

    For posting see the top of the forum (quoting it here)

    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    


  • Thanks for your response!

    From now on, I will follow your instructions so that the others can contribute in the future.

    so I tried two different things:

    class EIKON_HLOC(bt.feeds.GenericCSVData):'''
        params = (
    ('nullvalue' , float('NaN')),
            ('dtformat', '%Y-%m-%d'),
            ('datetime', 0),
            ('open', 1),
            ('high', 2),
            ('low', 3),
            ('close', 4),
            ('volume', 5),
            ('openinterest', -1),
        )
    
    #This will load pre-made CSV (using Eikon) data
    datalist = []
    tickers = ['WMT','IBM','C','AAPL.O','MSFT.O']
    for ticker in ticker_list:
        datalist.append(('{}.csv'.format(ticker), ticker))
    
    #First option using class
    datalist = []
    for ticker in ticker_list:
        datalist.append(('{}.csv'.format(ticker), ticker))
    
    for i in range(len(datalist)):
        data = EIKON_HLOC(dataname = datalist[i][0])
        cerebro.adddata(data, name=datalist[i][1])
    
    #Second Option using Pandas dataframe
    datalist = []
    for ticker in ticker_list:
        datalist.append(('{}.csv'.format(ticker), ticker))
        
    for i in range(len(datalist)):
        # Create a Data Feed
        dataframe = pd.read_csv(datalist[i][0], index_col = 0)
        dataframe = dataframe.set_index(pd.DatetimeIndex(dataframe.index))
        data = bt.feeds.PandasData(dataname=dataframe)    
        # Add the Data Feed to Cerebro
        cerebro.adddata(data)
    

    After several trials, both worked. So finally I can create my own strategies to digest personal data (but still trying to understand the coding structures).

    Is there any example sources that I can refer to ?

    Thank you!


  • administrators

    A classic example is in the Docs - Quickstart. But there is no specific documentation about classic strategies (some examples you may find implement a Moving Average CrossOver)