wrangle_contracts_on_oi.Rd
This is a helper function for determining when to roll futures contracts based on open interest and extracting data required for simulations that include the roll.
The roll happens the day after a new contract is identified as having the maximum open interest at the close.
Example: CME gold futures (GC) 2021-01-15: G has highest OI 2021-01-19: J has highest OI (no trading 16-19) 2021-01-20: we roll into J (previous_contract and close_previous_contract correspond to G, current_contract and close_current_contract to J)
wrangle_contracts_on_oi(contracts)
A dataframe of futures contract data including columns ticker, date, close, point_value, open_interest.
Long dataframe with columns: symbol: Futures symbol without contract designation (eg ES, GC, ZB, etc) date: In YYYY-MM-DD format close_current_contract: Closing USD value of the current contract (closepoint_value) current_contract: Contract designation for contract with highest open interest close_previous_contract: Closing USD value of yesterday's contract with highest open interest (closepoint_value) previous_contract: Contract designation for contract with highest open interest yesterday roll: Boolean specifying whether there was a roll event for the current observation
Note that unless there was a roll event, previous_contract == current_contract and close_previous_contract == close_current_contract
if (FALSE) wrangle_contracts_on_oi(futures)