FRENESDE

Loading data (DataFeed)

A DataFeed is the stream of bars that Cerebro replays. Each bar holds a date, the OHLC prices (open, high, low, close) and the volume.
With pandas, you read your CSV with dates as the index (index_col=0, parse_dates=True), then create bt.feeds.PandasData(dataname=df). By default it looks for columns named open, high, low, close and volume.
You can limit the tested period with fromdate and todate. Keeping the last years aside leaves you out-of-sample data to check your strategy later.
Beware of raw data: an unadjusted split looks like a crash. For a multi-year backtest, use adjusted prices.

Examples

Key terms

DataFeed
Stream of price bars given to Cerebro
OHLCV
Open, high, low, close and volume of a bar
PandasData
The Backtrader feed that reads a pandas DataFrame
Adjusted price
Price corrected for splits, and often dividends
Take the mission on Doji Academy

← Back to the index