Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
#30

Reworked the alogirthm to create weights that VXX etc.  use.

Note that the weights now use the three front month expirations
run `vixutil -w w.xlsx` to see the new columns T1W, T2W, T3W
which weight the front three futures.

commit 59727e0
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 20:34:35 2024 -0700

    checkpoint

commit be58bd5
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 20:29:24 2024 -0700

    checkpoint

commit 4abda16
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 20:07:52 2024 -0700

    removed some output debugging.

commit 218e465
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 19:54:39 2024 -0700

    checkpoint

commit 586ecea
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 19:39:05 2024 -0700

    checkpoint

commit 0777a78
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 18:30:25 2024 -0700

    checkpoint

commit 9c86a9d
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 16:42:44 2024 -0700

    checkpoint.

commit ea396cc
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 16:06:53 2024 -0700

    Trim the date range looping through to that of interest for
    generating weights.  Mostly useful in debugging (not intended to be a performance enhancement)

commit a775224
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 10:52:55 2024 -0700

    checkpoint

commit cff78b9
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 09:30:04 2024 -0700

    checkpoint

commit 7420a6e
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 09:03:02 2024 -0700

    checkpoint

commit 918c0b3
Author: Doug Ransom <[email protected]>
Date:   Fri May 24 08:22:52 2024 -0700

    checkpoint

commit 482dab7
Author: Doug Ransom <[email protected]>
Date:   Thu May 23 09:22:14 2024 -0700

    More clearly identify the roll periods.

commit 7956468
Author: Doug Ransom <[email protected]>
Date:   Wed May 22 20:19:28 2024 -0700

    checkpoint.

commit 9987370
Author: Doug Ransom <[email protected]>
Date:   Wed May 22 18:01:05 2024 -0700

    Added assertion to detect weights out of allowed range.

commit 7d6a99a
Author: Doug Ransom <[email protected]>
Date:   Tue May 21 10:08:25 2024 -0700

    Test refactoring so we can select smaller sets of CFE open days.

commit 6e216bf
Author: Doug Ransom <[email protected]>
Date:   Tue May 21 08:49:23 2024 -0700

    Refactored to facilitate testing.

commit e52bbba
Author: Doug Ransom <[email protected]>
Date:   Mon May 20 19:52:48 2024 -0700

    Added a test to highlight
    #30
  • Loading branch information
dougransom committed May 25, 2024
1 parent 1b231b2 commit e62e8e9
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
/dist
/test_output
/docs/_build
/foo
/foo
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ At some point they need to be patched in if they exist.
```
There seem to be a few dates where spot indexes are missing, you will have to workaround by using fill feature of Pandas datafame, or skip those days, in any analysis.
~~~
## Developing
https://numpydoc.readthedocs.io/en/latest/format.html

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies= [
"aiohttp[speedups]",
"openpyxl",
"appdirs",
"more_itertools"]
"more_itertools",
"icecream"]


[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/vix_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A library for preparing VIX Futures and Cash Term Structures for analysis,
including a continuous maturity VIX Futures term structure.
"""
__version__ = '0.1.6'
__version__ = '0.1.7'

from .download_vix_futures import \
pivot_futures_on_monthly_tenor,select_monthly_futures,async_load_vix_term_structure,load_vix_term_structure
Expand Down
20 changes: 11 additions & 9 deletions src/vix_utils/continuous_maturity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def do_weighting_months(trades_df : pd.DataFrame,weight_df:pd.DataFrame,weights_
"""
return sum(do_weight(trades_df,weight_df,n,t) for n,t in weights_and_tenors )

_weights_and_tenors_vix_front_months=[('Front Month Weight',1), ('Next Month Weight',2)]
_weights_and_tenors_vix_front_months=[(f"T{i}W",i) for i in range(1,4)]

def do_weighting_front_two_months(trades_df : pd.DataFrame,weight_df : pd.DataFrame) -> pd.DataFrame:
def do_weighting_front_three_months(trades_df : pd.DataFrame,weight_df : pd.DataFrame) -> pd.DataFrame:
"""
produces a weighted mean of the two nearest monthly futures resulting in an average of maturity one month.
produces a weighted mean of the nearest monthly futures resulting in an average of maturity one month.
parameters:
----------
trades_df: a DataFrame indexed by trade date on axis 0, and by Tenor_Monthly (as the first level index) on axis 1.
Expand Down Expand Up @@ -117,22 +117,24 @@ def continuous_maturity_one_month(monthly_wide_records : pd.DataFrame)->pd.DataF

weights_all=vix_constant_maturity_weights(df)

#we only need the weigths we for dates we have trades
#we only need the weigths for dates we have trades
weights=weights_all[weights_all.index.isin(futures_history.index)]

#select the front two months and the columns that have trade values
#select the front three months and the columns that have trade values
#we need three because at times teh front month is ignored and the back two contracts are used.

with pd.option_context('display.max_columns',None):
logging.debug(f"\n{'*'*50}\nColumns to weight:\n{futures_history}")
front_two_months=futures_history[[1,2]]
futures_history_trade_value_columns=front_two_months.swaplevel(axis=1)[_weighted_column_names].swaplevel(axis=1)
front_three_months=futures_history[[1,2,3]]
futures_history_trade_value_columns=front_three_months.swaplevel(axis=1)[_weighted_column_names].swaplevel(axis=1)

weighted_values=do_weighting_front_two_months(futures_history_trade_value_columns,weights)
weighted_values=do_weighting_front_three_months(futures_history_trade_value_columns,weights)

#should have the same number of rows
assert weighted_values.shape[0]==futures_history_trade_value_columns.shape[0]


df_file=front_two_months.swaplevel(axis=1)["File"]
df_file=front_three_months.swaplevel(axis=1)["File"]
weighted_values["File"]=df_file[1]+"+"+df_file[2]

weighted_values['Expiry']=weights['Expiry']
Expand Down
Loading

0 comments on commit e62e8e9

Please sign in to comment.