How to get future price beyond its auto_close_date

Hi,

I noticed that the front future is rolled at the auto_close_date rather than the actual expiration date.
How do I get the price of the actual front future beyond the auto_close_date?

My algorithm will not trade the futures, but need to use future prices as signals, so I'd need to use the actual expiry_date instead of the auto_close_date.

Thanks,
Daniel

2
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59f2a2cd9d8caf413191ded3
There was a runtime error.
7 responses

Can't you use history()?

For example, CLG14 has auto_close_date=2014-01-17 but you can still see its price after:

data = history(
"CLG14",
fields = ['price','contract'],
frequency = 'daily',
start = "2014-01-15",
end = "2015-01-01",
)


Output:

                           price                    contract
2014-01-15 00:00:00+00:00  94.30  Future(1058201402 [CLG14])
2014-01-16 00:00:00+00:00  94.16  Future(1058201402 [CLG14])
2014-01-17 00:00:00+00:00  94.09  Future(1058201402 [CLG14])
2014-01-20 00:00:00+00:00  93.72  Future(1058201402 [CLG14])
2014-01-21 00:00:00+00:00  94.88  Future(1058201402 [CLG14])


But I would need to know what the actual front contract every day, and then look at the price. I guess my question now translates to "How do I find the actual front contract every day using continuous_future?"

I guess what you want to do is create your own roll. I.e. continuous_futures are supposed to do the roll for you, either by volume or by calendar, but you're saying you don't like either. So you'll have to implement yours.

One possibility is to try and get guess names of contracts and ask for their history. For example, if in your algorithm execution the current date is 2014-01-20 (just after auto_close_date) you can still guess that if we're on year 2014 and the next month is Feb, the next contract should be named "CL" + "G" + "14" = "CLG14", and then feed this into history(). And at some point you'll get an error, I'm guessing, meaning you have to move on to the month after.

I'm not sure there's a built-in way to do this. Like I said, these are rolls but you don't like the default ones.

That is what I am thinking - building my own roll.

One way I can think of:
In certain month, for example January, the front contract can only be F or G, load F contract first, check its maturity date, if current date is before the maturity date, then we know it is the front contract, otherwise G is the front contract, and then load prices accordingly.

Will share my code once done.

Ideally, there is a roll method "actual" in continuous_future

Daniel, just a question. Do you realise that auto_close_date is normally about 2 days before end_date? What is it that you're trying to do that this would be a big factor?

I guess it is specific to my project. VIX future expires on Wednesdays. By adjusting 2 business days ahead, auto_close_date will move the roll date to Thursday or Friday in the earlier week, which is 4-5 calendar days before expiry. I just think it is too much of a gap to roll this way.

Here it is. May have over complicated things a little bit, but it works.

2
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59f3591556ce7f428454085b
There was a runtime error.