Using Python and Pandas to Create Continuous Futures Contracts
quantstart.com
quantstart.com
There are many more differences between futures and equities, but one big thing to keep in mind is the leverage you can get with futures. The CL contract he's talking about is for physical delivery (or receipt) of 1000 barrels of WTI light sweet crude oil in Cushing, OK. The front month contract is currently trading around $97/barrel so the total value value of one contract is about $97,000. The CME will let you buy or sell a single contract with a little less than $4,000 worth of margin. That's like 20x or 25x leverage if you are trading close to the margin limits. I guess what I'm saying is that it's a pretty easy way to blow yourself up if you don't know what you're doing.
I saw first hand what happens when you're sweating the market going against your trades. My father would smoke heavily and not sleep at night.
Now that I'm 31, we joke about those times. I still build algos with Quantopian for fun (and share them with my dad over a beer, throwing the backtest up on a 70" TV), and make a few bucks here and there, but you would be fucking insane to try to be a day trader now (competing against people with crazy financial and technological resources).
Ernest Chan provides some good examples re GLD/GDX spreads, for instance.
It amazes me just how much more there is to learn, no matter how much I think I know about a topic. For example, I have never heard about the importance of smoothing the price between futures months. Even though I was in the front-office of a large energy trading firm for over 6 years[1]. (I lead a small tech team handling pre-trade research data so my experience was tangential to the actual trading).
It seemed to me that the traders compartmentalized the trading months. They trade prompt right up to expiry, then they start trading a new prompt (of course they were also trading spot and other stuff, not only prompt month). Nobody ever seemed to care about the price disjunction when the month rolled.
So I find this idea of different methods to smooth that price really interesting. What kind of trading are you doing where that matters?
[1] and I really miss it. Hope I can go back to something like that again someday.
I'm not sure what is meant by the rollover smoothing increasing transaction costs, this might have caused you some confusion if you're familiar with futures trading. Generally the actual mechanics of trading with the continuous series is that trade entries and exits and position sizing are calculated from the artificial continuous series and a trade that spans a roll will be rolled over (ie the previous contract position closed and a matching position in the new contract opened) on the roll date just as a traditional position would be. There would be no need to trade every day of the roll window, it would just be a paper exercise to come up with a proportional price for the artificial continuous contract.
Python does have a library for everything, you know.
just had a quick scan through the code and it looks there's one thing missing (apologies if not as I haven't had the time yet to really run the code). if you actually want to create a tradable backtest you have to bear in mind that you are selling/buying during the roll period meaning that if you invest amount x before rolling over what you end up with after the roll is not equal to the value of your perpetual series.
to give you a simple example: if you roll over 1 day only and CLG14 settles at t1=100, t2=110 and CLH14 settles at t1=90, t2=95 your position after the roll is worth 105.56 (not 95).
makes sense?