vectorbt icon indicating copy to clipboard operation
vectorbt copied to clipboard

Import data from .csv file

Open brankoo124 opened this issue 3 years ago • 3 comments

Hi, I am trying to import data from .csv file, which structure is exactly same as the csv's exported from yahoo finance (cryptocurrencies, so no AdjClose column). Is there any built in way of doing it?

brankoo124 avatar Apr 30 '22 18:04 brankoo124

Hi, you can use pd.read_csv (https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html) to load the data into a DataFrame

polakowo avatar May 12 '22 09:05 polakowo

Hi I am trying the same but no luck. I try these:

vbt.Data.from_data(df.close)

utekakca avatar Jun 15 '22 06:06 utekakca

@utekakca @brankoo124 you can try something like this:

def get_data(asset="BTCUSD", start=0, end=0):
    filename = "data/{}.csv".format(asset)
    df = pd.read_csv(filename)
    df['Date'] = pd.to_datetime(df['Date'])
    df = df.set_index('Date')

    if (end != 0):
        df = df[start:end]
    return df

def get_vector_data(asset="BTCUSD", start=0, end=0):
    class CustomData(vbt.Data):
         @classmethod
         def download_symbol(cls, symbol, start=0, end=0):
             return get_data(symbol, start, end)

    return CustomData.download([asset], start=start, end=end).get()

data = get_vector_data("BTCUSD")

piotryordanov avatar Jun 22 '22 06:06 piotryordanov