Open contenrico opened 1 year ago
can you create a reproducible example using the sample data available in the package?
Sure:
triangle = cl.load_sample('quarterly')
incurred = triangle['incurred']
cl.Development(drop_valuation='2005').fit_transform(incurred).link_ratio
Hi @contenrico, did you ever resolve your issue?
My understanding is that you are just trying to drop the latest diagonal of your triangle, is that correct? There's no need to use cl.Development()
for this. You can do this:
import chainladder as cl
triangle = cl.load_sample('quarterly')
incurred = triangle['incurred']
incurred[incurred.valuation < '2006-1-1']
However, if you need the link ratios, excluding information from the latest diagonal, you can then do this:
cl.Development().fit(incurred[incurred.valuation < '2006-1-1']).ldf_
Does this help?
Hi @kennethshsu,
I was indeed trying to drop the latest diagonal from my triangle, but for the specific purpose of calculating link ratios - so I think I do need to use cl.Development()
.
Your second code snippet does exactly that, so I think that works! I guess the only improvement I need is to make that '2006-1-1'
dynamic based on the valuation date, so I can always exclude the latest diagonal (or latest two, three, etc.).
Thank you!
If you need to access 2006-1-1
as a TimeStamp
variable, you can call .valuation_date
on your Triangle
object. Continuing the example:
incurred.valuation_date
Then, you can calculate the ldfs or cdfs as usual:
cl.Development().fit(incurred[incurred.valuation < incurred.valuation_date]).cdf_
With this, you'll be able to manipulate incurred.valuation_date
, for example, excluding the latest 6 months, with
from dateutil.relativedelta import relativedelta
date_x6months = incurred.valuation_date - relativedelta(months=6)
cl.Development().fit(incurred[incurred.valuation < date_x6months]).cdf_
Now, with all that said, I don't know why drop_valuation
in cl.Development
isn't working as expected. I can try to look into this.
Tests:
# Annual development work
raa = cl.load_sample("raa")
assert cl.Development(drop_valuation='1981-12-31').fit_transform(raa).cdf_ != cl.Development(drop_valuation='1982-12-31').fit_transform(raa).cdf_
assert cl.Development(drop_valuation='1982-12-31').fit_transform(raa).cdf_ != cl.Development(drop_valuation='1983-12-31').fit_transform(raa).cdf_
assert cl.Development(drop_valuation='1981-12-31').fit_transform(raa).cdf_ != cl.Development(drop_valuation='1983-12-31').fit_transform(raa).cdf_
# but non-annual don't
assert cl.Development().fit_transform(incurred).cdf_ != cl.Development(drop_valuation='1995-03-31').fit_transform(incurred).cdf_
assert cl.Development().fit_transform(incurred).cdf_ != cl.Development(drop_valuation='1995-06-30').fit_transform(incurred).cdf_
assert cl.Development(drop_valuation='1995-03-31').fit_transform(incurred).cdf_ != cl.Development(drop_valuation='1995-06-30').fit_transform(incurred).cdf_ #this fails now
assert cl.Development(drop_valuation='1995-06-30').fit_transform(incurred).cdf_ != cl.Development(drop_valuation='1995-09-30').fit_transform(incurred).cdf_ #this fails now
Discussed in https://github.com/casact/chainladder-python/discussions/455