Category Archives: investing

CME Lumber Changes

While I don’t typically actively trade Lumber Futures, I do track their prices. I recently was confused by a change to the symbol at Barchart.com from LS to LB.

I found this very helpful article about the change in the contract. Much more changed than just the symbol, the dimensions and other specifics about the contract changed as well.

https://www.lesprom.com/en/news/Everything_you_need_to_know_about_new_CME_lumber_futures_contract_107712/

The size of the contract is much smaller, from about a train car of lumber to a truck of lumber. Also the prices don’t really match up so this should be added as a new item and not spliced back into the old Lumber contract. This is a fairly substantial change.

Backtrader–notes about multiple data timeframes

I attempted to make a system that uses ATR based on a different time frame than the signal I was considering. Bottom line, that wasn’t successful for trading (at least so far) but I did discover some errors and figured out a way to correct some of them.

First of all, to use multiple time frames I had to include some additional inputs into the original data.

I collected the data using a class I wrote that gets data into a pandas dataframe named data frame, so that is the entry point for the following code:

data = bt.feeds.PandasData(dataname=dataframe, name=symbol, ) 

If I wanted to use a different time frame, I had to modify this code to the following:

data = bt.feeds.PandasData(dataname=dataframe, name=symbol, timeframe = bt.TimeFrame.Minutes, compression = _) 

Then to resample the data, I could use the following statements:

cerebro.adddata(data) #data0
cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression = 720, name = '720m') # data1
cerebro.resampledata(data, timeframe=bt.TimeFrame.Days, compression = 1, name = '1d') # data2

This including this resampled data did cause some problems. I had an observer that intermittently caused errors when plotting which I removed to allow plotting to be reliable:

#cerebro.addobserver(bu.AcctValue)

Truth be told I didn’t really need that observer but it was in some code I copied when I was just getting started with backtrader.

I also had trouble with an analyzer, specifically the returns analyzer added with the following code.

cerebro.addanalyzer(bt.analyzers.Returns, _name="ret")

When I used the data feed that included “timeframe = bt.TimeFrame.Minutes” this analyzer would give a nonsensical answer. I don’t know why this subtle difference in the data that shouldn’t really change anything ruins the output of the analyzer but it seems to be the case.