Skip to content

Commit 9767a6f

Browse files
committed
Marimo Notebook update
1 parent eaf8e75 commit 9767a6f

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ notebooks/outputs/
6565
notebooks/*.parquet
6666
notebooks/*.csv
6767
notebooks/archived
68+
notebooks/__marimo__
6869

6970
# Ruff cache
7071
.notebooks/.ruff_cache/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Some notes**:
66

77
- The main reference is [Basic term S](https://lifelib.io/libraries/basiclife/BasicTerm_S.html). Model S, M and SC are basically the same.
8+
- The computation heavy work load is performed with Rust.
89
- Post run analysis is stored at [notebooks](notebooks) folder. This is a [Marimo Notebook](https://marimo.io/) notebook. Its purpose is to explain a practical smoothing technique after crude premium calculation is performed by Rust model. The method is reproducible and reduces labor intensity from manual practise.
910

1011
**What can be taken out from this repo?**

notebooks/analysis.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ def _(mo):
4343
4444
This notebook shows how the premium rates are smoothed after being calculated using Rust model.
4545
46-
The intension at first is to used Rust for analysis. However, at the time of this is produced, due to its Rust language's nature (compiled), it takes significant time to produce the output. On another hand, Python reactive notebook is more advanced and packed with featured. Hence, Python is used for post anlysis.
46+
The intension at first is to used Rust for analysis.
47+
However, at the time of production, Rust language compilation nature takes significant time to produce the output in reactive notebook environment.
48+
On another hand, Python reactive notebook is more advanced and packed with featured.
49+
Hence, Python is used for post analysis.
4750
48-
After premium rate is calculated using Rust model, the premium rates are still jumpy at several model points. This notebook shows how the premium rate is smoothed using common p-sline technique.
51+
What is done in this notebook?
52+
After premium rate is calculated using Rust model, the premium rates are still jumpy at several model points.
53+
This notebook shows how the premium rate is smoothed using common p-sline technique.
4954
50-
In practise, it is observed that many actuaries are performing this step manually with interpolation. However, it is not recommended as not being reproducible and labor intensive.
55+
In practise, this step is usually performed manually with interpolation. However, it is not recommended as not being reproducible and labor-intensive.
5156
5257
## Crude premium rate
5358
@@ -119,7 +124,7 @@ def _(Ridge, SplineTransformer, make_pipeline, np, plt, prem_rate_pd):
119124
smoothed_points = []
120125

121126
for term, group in prem_rate_pd.groupby("term"):
122-
#
127+
#
123128
group = group.sort_values("age")
124129
X = group["age"].values.reshape(-1, 1)
125130
y = group["ave_prem_rate"].values
@@ -131,10 +136,10 @@ def _(Ridge, SplineTransformer, make_pipeline, np, plt, prem_rate_pd):
131136
Ridge(alpha=0.0)
132137
)
133138
model.fit(X, y)
134-
139+
135140
# Predict at each observed age
136141
y_smooth = model.predict(X)
137-
142+
138143
# Store smoothed values
139144
group_smoothed = group.copy()
140145
group_smoothed["smoothed_prem_rate"] = y_smooth
@@ -203,7 +208,7 @@ def _(pl, smoothed_pl):
203208
def _(mo):
204209
mo.md(
205210
r"""
206-
As observed there is still one points that is has a negative slope. We can either iterate over different subset of variable to smooth out the curve.
211+
As observed there is still one points that is has a negative slope. We can either iterate over different subset of variable to smooth out the curve.
207212
208213
However, I make an objective decision if tolerance is small enough, it will be ignored. Else, we will obtain the rate from the previous period to make the difference 0.
209214
"""

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() -> PolarsResult<()> {
4848

4949
let multi_run_results = run_setups.projection_runs()?;
5050

51-
multi_run_results.export("src/results/third_test")?;
51+
multi_run_results.export("src/results/first_test")?;
5252

5353
// Print the time taken for the runs
5454
let duration = start.elapsed();

0 commit comments

Comments
 (0)