diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/basket_index.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py index c1b264a4..d595eef6 100644 --- a/python/analytics/basket_index.py +++ b/python/analytics/basket_index.py @@ -1,6 +1,7 @@ from .index_data import get_index_quotes, get_singlenames_curves from .db import _engine from dateutil.relativedelta import relativedelta +from functools import partial from pyisda.credit_index import CreditIndex from typing import List import numpy as np @@ -9,6 +10,13 @@ import datetime from scipy.optimize import brentq from pandas.tseries.offsets import BDay +def make_index(t, d, args): + instance = t.__new__(t) + for k, v in d.items(): + setattr(instance, k, v) + CreditIndex.__init__(instance, *args) + return instance + class BasketIndex(CreditIndex): index_type: str series: int @@ -50,6 +58,11 @@ class BasketIndex(CreditIndex): self.tweaks = [] super().__init__(self.issue_date, maturities, curves) + def __reduce__(self): + _, args = CreditIndex.__reduce__(self) + d = vars(self) + return partial(make_index, self.__class__), (d, args) + def _query_version(self, i): for lastdate, *data in self._version: if lastdate >= self.trade_date.date(): |
