codypd

Crude Roll Trade Simulator

65
EDIT: The screen cap was unintended with the script publication. The yellow arrow is pointing to a different indicator I wrote. The "Roll Sim" indicator is shown below that one. Yes I could do a different screen cap, but then I'd have to rewrite this and frankly I don't have time. END EDIT

If you have ever wanted to visualize the contango / backwardation pressure of a roll trade, this script will help you approximate it.

I am writing this description in haste so go with me on my rough explanations.

A "roll trade" is one involving futures that are continually rolled over into future months. Popular roll trade instruments are USO (oil futures) and UVXY (volatility futures).

Roll trades suffer hits from contango but get rewarded in periods of backwardation. Use this script to track the contango / backwardation pressure on what you are trading.

That involves identifying and providing both the underlying indexes and derivatives for both the front and back month of the roll trade. What does that mean? Well the defaults simulate (crudely) the UVXY roll trade: The folks at Proshares buy futures that expire 60 days away and then sell those 30 days later as short term futures (again, this is a crude description - see the prospectus) and we simulate that by providing the Roll Sim indicator the symbols VIX and VXV along with VIXY and VIXM. We also provide the days between the purchase and sale of the rolled futures contract (in sessions, which is 22 days by my reckoning).

The script performs ema smoothing and plots both the index lines (VIX and VXV as solid lines in our case) and the derivatives (VIXY and VIXM as dotted lines in our case) with the line graphs offset by the number of sessions between the buy and sell. The gap you see represents the contango / backwardation the derivative roll trades are experiencing and gives you an idea how much movement has to happen for that gap to widen, contract or even invert. The background gets painted red in periods of backwardation (when the longer term futures cost less than when sold as short term futures).

Fortunately indexes are calibrated to the same underlying factors, so their values relative to each other are meaningful (ie VXV of 18 and VIX of 15 are based on the same calculation on premiums for S&P500 symbols, with VXV being normally higher for time value). That means the indexes graph well without and adjustments needed. Unfortunately derivatives suffer contango / backwardation at different rates so the value of VIXY vs VIXM isn't really meaningful (VIXY may take a reverse split one year while VIXM doesn't) ... what is meaningful is their relative change in value day to day. So I have included a "front month multiplier" which can be used to get the front month line "moved up or down" on the screen so it can be compared to the back month.

As a practical matter, I have come to hide the lines for the derivatives (like VIXY and VIXM) and just focus on the gap changes between the indexes which gives me an idea of what is going on in the market and what contango/backwardation pressure is likely to exist next week.

Hope it is useful to you.

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?
study("Roll Sim")

BMSYM=input(title="Back Month Symbol", type=symbol, defval="VXV")
BMETF=input(title="Back Month ETN", type=symbol, defval="VIXM")
FMSYM=input(title="Front Month Symbol", type=symbol, defval="VIX")
FMETF=input(title="Front Month ETN", type=symbol, defval="VIXY")
SYMOFFSET=input(title="Offset", type=integer, defval=22)
FMMULT=input(title="Front Month Multiplier", type=float, defval=1.0)



BMSYMPRICE = ema(security(BMSYM, period , close), SYMOFFSET)
FMSYMPRICE = ema(security(FMSYM, period , close), SYMOFFSET)

BMETFPRICE = ema(security(BMETF, period , close), SYMOFFSET)
FMETFPRICE = ema(security(FMETF, period , close), SYMOFFSET)


plotbm=plot(BMSYMPRICE, color=red, offset=SYMOFFSET)
plotfm=plot(FMMULT*FMSYMPRICE, color=black)

plotbme=plot(BMETFPRICE, style=circles, color=red, offset=SYMOFFSET)
plotfme=plot(FMMULT*FMETFPRICE, style=circles, color=black)

bgcolor(FMSYMPRICE> BMSYMPRICE[SYMOFFSET] ? red : white, 60 )