gs-quant
gs-quant copied to clipboard
IRSwap does not round trip. IRSwap.from_dict(swap.as_dict()) throws type error
When attempting to round trip an unresolved IRSwap instrument a TypeError is thrown.
The issue is not with IRSwap instrument but the way that the "Base" classes method __from_dict() handles datetime.dates. In 0.8.149 setting a instrument property to a datetime and then attempting to roundtrip via Instrument.from_dict(inst.as_dict()) will fail as Base.__from_dict() cannot handle datetime.date inputs.
To Reproduce import datetime from gs_quant.instrument import IRSwap swap = IRSwap('Pay', termination_date=datetime.date(2030, 1, 2), fixed_rate='atm', notional_currency='eur') swap.as_dict() new_swap = IRSwap.from_dict(swap.as_dict())
Expected behavior new_swap should be a new IRSwap instrument.
This used to work as expected in prior versions, eg 0.8.90.
Screenshots If applicable, add screenshots to help explain your problem.
Systems setup:
- OS: Windows 10
- Python version 3.7
- GS-Quant version 0.8.149
Additional context
Error is:
File "
Issue is around line 280 of gs_quant.base.py:
elif issubclass(prop_type, dt.date): try: setattr(self, prop, dateutil.parser.isoparse(prop_value).date()) except ValueError: if str in additional_types: setattr(self, prop, prop_value)
suggest the except clause should be extended to include TypeError
This didn't occur in earlier versions of gs_quant as in this case prop_type (line 259) evaluated to None so this section of code ran: if prop_type is None: # This shouldn't happen setattr(self, prop, prop_value)