Skip to content

Commit

Permalink
fix for #409
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt authored and kennethshsu committed Jun 15, 2023
1 parent 59b84b6 commit 35a6172
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion chainladder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def auto_sparse(auto_sparse=True):
from chainladder.methods import * # noqa (API Import)
from chainladder.workflow import * # noqa (API Import)

__version__ = "0.8.15"
__version__ = "0.8.16"
10 changes: 9 additions & 1 deletion chainladder/core/tests/test_grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_different_forms_of_grain(prism_dense, grain, trailing, alt, atol):
assert abs(a - b).sum().sum() < atol


def test_assymetrric_origin_grain(prism_dense):
def test_asymmetric_origin_grain(prism_dense):
x = prism_dense.iloc[..., 8:, :].incr_to_cum()
x = x[x.valuation < x.valuation_date]
assert x.grain("OYDM").development[0] == 1
Expand All @@ -90,6 +90,14 @@ def test_vector_triangle_grain_mismatch(prism):
assert (tri / exposure).development_grain == "Q"


def test_annual_trailing(prism):
tri = prism["Paid"].sum().incr_to_cum()
# (limit data to November)
tri = tri[tri.valuation < tri.valuation_date].incr_to_cum()
tri = tri.grain("OQDQ", trailing=True).grain("OYDY")
assert np.all(tri.ddims[:4] == np.array([3, 6, 9, 12]))


def test_development_age():
raa_tri = cl.load_sample("raa")
assert (raa_tri.ddims == [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]).all()
19 changes: 12 additions & 7 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,27 @@ def grain(self, grain="", trailing=False, inplace=False):
obj = self.dev_to_val()
if ograin_new != ograin_old:
freq = {"Y": "A", "S": "2Q"}.get(ograin_new, ograin_new)
mn = self.origin[-1].strftime("%b").upper() if trailing else "DEC"
if trailing or obj.origin.freqstr[-3:] != "DEC":
origin_period_end = self.origin[-1].strftime("%b").upper()
else:
origin_period_end = "DEC"
indices = (
pd.Series(range(len(self.origin)), index=self.origin)
.resample("-".join([freq, mn]))
.resample("-".join([freq, origin_period_end]))
.indices
)
groups = pd.concat(
[pd.Series([k] * len(v), index=v) for k, v in indices.items()], axis=0
).values
obj = obj.groupby(groups, axis=2).sum()
obj.origin_close = mn
if len(obj.ddims) > 1 and pd.Timestamp(obj.odims[0]).strftime(
"%Y%m"
) != obj.valuation[0].strftime("%Y%m"):
obj.origin_close = origin_period_end
d_start = pd.Period(
obj.valuation[0],
freq=dgrain_old if dgrain_old == 'M' else dgrain_old + obj.origin.freqstr[-4:]
).to_timestamp(how='s')
if (len(obj.ddims) > 1 and obj.origin.to_timestamp(how='s')[0] != d_start):
addl_ts = (
pd.period_range(obj.odims[0], obj.valuation[0], freq="M")[:-1]
pd.period_range(obj.odims[0], obj.valuation[0], freq=dgrain_old)[:-1]
.to_timestamp()
.values
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
descr = "Chainladder Package - P&C Loss Reserving package "
name = 'chainladder'
url = 'https://github.com/casact/chainladder-python'
version='0.8.15' # Put this in __init__.py
version='0.8.16' # Put this in __init__.py

data_path = ''
setup(
Expand Down

0 comments on commit 35a6172

Please sign in to comment.