Skip to content

Commit

Permalink
exposure triangle init fix
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bogaardt committed Feb 13, 2020
1 parent dcc93f3 commit 812db0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chainladder/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ def __init__(self, data=None, origin=None, development=None,
orig = dict(zip(orig, range(len(orig))))
kdims = {v:k for k, v in key.sum(axis=1).to_dict().items()}
orig_idx = origin_date.map(orig).values[np.newaxis].T
dev_idx = dev_lag.map(dev).values[np.newaxis].T
if development:
dev_idx = dev_lag.map(dev).values[np.newaxis].T
else:
dev_idx = (dev_lag*0).values[np.newaxis].T
key_idx = data_agg[index].sum(axis=1).map(kdims).values[np.newaxis].T
val_idx = ((np.ones(len(data_agg))[np.newaxis].T)*range(len(columns))).reshape((1,-1), order='F').T
coords = np.concatenate(tuple([np.concatenate((orig_idx, dev_idx), axis=1)]*len(columns)), axis=0)
coords = np.concatenate((np.concatenate(tuple([key_idx]*len(columns)), axis=0), val_idx, coords), axis=1)
amts = data_agg[columns].unstack().values.astype('float64')
values = sparse.COO(coords.T, amts, shape=(len(key), len(columns), len(orig), len(dev))).todense()
values = sparse.COO(coords.T, amts, shape=(len(key), len(columns), len(orig), len(dev) if development else 1)).todense()
values[values==0.] = np.nan
self.kdims = np.array(key)
self.odims = np.sort(date_axes['origin'].unique())
Expand Down
4 changes: 4 additions & 0 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def dev_to_val(self, inplace=False):
Updated instance of triangle with valuation periods.
'''
if inplace:
if self.is_val_tri:
return self
self = self._val_dev_chg('dev_to_val') if not self.is_val_tri else self
return self
return self._val_dev_chg('dev_to_val') if not self.is_val_tri else copy.deepcopy(self)
Expand Down Expand Up @@ -327,6 +329,8 @@ def val_to_dev(self, inplace=False):
def _val_dev_chg(self, kind):
xp = cp.get_array_module(self.values)
obj = copy.deepcopy(self)
if hasattr(obj, '_nan_triangle_'):
del obj._nan_triangle_
o_vals = obj._expand_dims(xp.arange(len(obj.origin))[:, xp.newaxis])
if self.shape[-1] == 1:
return obj
Expand Down

0 comments on commit 812db0c

Please sign in to comment.