resampling Pandas dataframe
not sure if anyone else has had trouble with loading data from a pandas dataframe and then using cerebro.resample, but we did. The dataframe for minute data loads find and then when I go to pass the dataframte to cerebro.resample I get nan values. if I use a csv it loads and resamples with no problems
so we ended up using pandas own resample feature which works just fine
If you can share an example it can for sure be looked into.
Directly resampling with
pandasis of course ok. The resampling in backtrader is there to keep the code the same across (for example) backtesting data and live data.
not sure how to get the formatted code to paste
startdate = datetime.datetime(2012, 1, 1) enddate = datetime.datetime(2013, 1, 3) def get_mstar_data(sym, startdate, enddate): s = startdate.year e = enddate.year df = None for i in range(s, e + 1): for filename in glob.glob("%s/%d/%s*_1min.gz" % (m_star_cbot_path, i, sym)): filedf = _create_df(filename) filedf = filedf.ix[startdate:enddate] print (len(filedf.index)) df = filedf if df is None else df.append(filedf) return mstar( fromdate=startdate, todate=enddate, dataname=df, name=sym, datetime=None ) data = get_mstar_data('ZC0Y', startdate, enddate): cerebro.adddata(data) cerebro.resampledata(data, name=ZC0Y15m, timeframe=bt.Timeframe.Minutes, compression=15)
note we solved it by creating a new cerebro class that lets us do the following
cerebro.add_feeds(startdate, enddate, portfolio_symbols, conflations)
The code is clear but the actual problem you faced (at least on this side) is not yet clear.
To format the code use the
markdownconventions. The following will do:
- Indent everything 4 spaces
- Code contained in a block with opening and closing lines with: ```
When you are writing a message there is a
Compose ?link on the top right corner of the editing area. That will guide you to the full reference (which is here: commonmark.org)