DI Futures Data
data(dates, month_start=False, pre_filter=False, all_columns=True)
Retrieves DI Futures contract data for a specific trade date.
Provides access to DI futures data, allowing adjustments to expiration dates (to month start) and optional filtering based on LTN and NTN-F bond maturities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
DateScalar
|
The trade dates for which to retrieve DI contract data. |
required |
month_start
|
bool
|
If True, adjusts all expiration dates to the first day of their respective month (e.g., 2025-02-01 becomes 2025-01-01). Defaults to False. |
False
|
pre_filter
|
bool
|
If True, filters DI contracts to include only those whose expiration dates match known prefixed Treasury bond (LTN, NTN-F) maturities from the TPF dataset nearest to the given trade date. Defaults to False. |
False
|
all_columns
|
bool
|
If True, returns all available columns from the DI dataset. If False, returns a subset of the most common columns. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the DI futures contract data for the specified dates, sorted by trade dates and expiration dates. Returns an empty DataFrame if no data is found |
Examples:
>>> from pyield import di1
>>> df = di1.data(dates="16-10-2024", month_start=True)
>>> df.iloc[:5, :5] # Show the first five rows and columns
TradeDate ExpirationDate TickerSymbol BDaysToExp OpenContracts
0 2024-10-16 2024-11-01 DI1X24 12 1744269
1 2024-10-16 2024-12-01 DI1Z24 31 1429375
2 2024-10-16 2025-01-01 DI1F25 52 5423969
3 2024-10-16 2025-02-01 DI1G25 74 279491
4 2024-10-16 2025-03-01 DI1H25 94 344056
Source code in pyield/b3/di1.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
eod_dates()
Returns all unique end-of-day trade dates available in the DI dataset.
Retrieves and lists all distinct 'TradeDate' values present in the historical DI futures data cache, sorted chronologically.
Returns:
Type | Description |
---|---|
Series
|
pd.Series: A sorted Series of unique trade dates (pd.Timestamp) for which DI data is available. |
Examples:
>>> from pyield import di1
>>> # DI Futures series starts from 1995-01-02
>>> di1.eod_dates().head(5)
0 1995-01-02
1 1995-01-03
2 1995-01-04
3 1995-01-05
4 1995-01-06
dtype: datetime64[ns]
Source code in pyield/b3/di1.py
interpolate_rate(date, expiration, extrapolate=False)
Interpolates or retrieves the DI rate for a single expiration date.
Fetches DI contract data for the specified trade date
and determines the
settlement rate for the given expiration
. If an exact match for the
expiration date exists, its rate is returned. Otherwise, the rate is
interpolated using the flat-forward method based on the rates of surrounding
contracts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date
|
DateScalar
|
The trade date for which to retrieve DI data. |
required |
expiration
|
DateScalar
|
The target expiration date for the rate. |
required |
extrapolate
|
bool
|
If True, allows extrapolation if the
|
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The exact or interpolated DI settlement rate for the specified
date and expiration. Returns |
Examples:
>>> from pyield import di1
>>> # Get rate for an existing contract expiration
>>> di1.interpolate_rate("25-04-2025", "01-01-2027")
0.13901
>>> # Get rate for a non-existing contract expiration
>>> di1.interpolate_rate("25-04-2025", "01-11-2027")
0.13576348733268917
>>> # Extrapolate rate for a future expiration date
>>> di1.interpolate_rate("25-04-2025", "01-01-2050", extrapolate=True)
0.13881
Source code in pyield/b3/di1.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
interpolate_rates(dates, expirations, extrapolate=True)
Interpolates DI rates for specified trade dates and expiration dates.
Calculates interpolated DI rates using the flat-forward method for given sets of trade dates and expiration dates. This function is well-suited for vectorized calculations across multiple date pairs.
If DI rates are unavailable for a given trade date, the corresponding interpolated rate(s) will be NaN.
Handles broadcasting: If one argument is a scalar and the other is an array, the scalar value is applied to all elements of the array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dates
|
DateScalar | DateArray
|
The trade date(s) for the rates. |
required |
expirations
|
DateScalar | DateArray
|
The corresponding expiration date(s).
Must be compatible in length with |
required |
extrapolate
|
bool
|
Whether to allow extrapolation beyond the range of known DI rates for a given trade date. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Series
|
pd.Series: A Series containing the interpolated DI rates (as floats). Values will be NaN where interpolation is not possible (e.g., no DI data for the trade date). |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Examples:
>>> from pyield import di1
>>> # Note: by default, pandas shows floats with 6 decimal places
>>> # Interpolate rates for multiple trade and expiration dates
>>> # There is a contract with expiration 01-01-2027 in 08-05-2025
>>> # The rate is not interpolated (settlement rate is used)
>>> # There is no contract with expiration 25-11-2027 in 09-05-2025
>>> # The rate is interpolated (flat-forward method)
>>> # There is no data for trade date 10-05-2025 (Saturday) -> NaN
>>> # Note: 0.13461282461562996 is shown as 0.134613
>>> di1.interpolate_rates(
... dates=["08-05-2025", "09-05-2025", "10-05-2025"],
... expirations=["01-01-2027", "25-11-2027", "01-01-2030"],
... )
0 0.13972
1 0.134613
2 <NA>
dtype: Float64
>>> # Interpolate rates for a single trade date and multiple expiration dates
>>> # There is no DI Contract in 09-05-2025 with expiration 01-01-2050
>>> # The longest available contract is used to extrapolate the rate
>>> # Note: extrapolation is allowed by default
>>> di1.interpolate_rates(
... dates="25-04-2025",
... expirations=["01-01-2027", "01-01-2050"],
... )
0 0.13901
1 0.13881
dtype: Float64
>>> # With extrapolation set to False, the second rate will be NaN
>>> # Note: 0.13576348733268917 is shown as 0.135763
>>> di1.interpolate_rates(
... dates="25-04-2025",
... expirations=["01-11-2027", "01-01-2050"],
... extrapolate=False,
... )
0 0.135763
1 <NA>
dtype: Float64
Notes
- All available settlement rates are used for the flat-forward interpolation.
- The function handles broadcasting of scalar and array-like inputs.
Source code in pyield/b3/di1.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|