Skip to content

Commit 42f4af0

Browse files
committed
Add clean workflow documentation with proper base
1 parent f8717af commit 42f4af0

File tree

14 files changed

+157
-78
lines changed

14 files changed

+157
-78
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ rayon = "1.10.0"
1111
spreadsheet-ods = "0.25.0"
1212
uuid = "1.17.0"
1313
serde_json = "1.0.140"
14+
itertools = "0.14.0"
15+
chrono = "0.4.41"

src/assumptions/assumptions.ods

1.17 KB
Binary file not shown.

src/model_points.rs

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,21 @@
1+
use chrono::NaiveDate;
12
use ndarray::prelude::*;
23
use ndarray_rand::RandomExt;
34
use ndarray_rand::rand::SeedableRng;
45
use ndarray_rand::rand::rngs::StdRng;
56
use ndarray_rand::rand_distr::Uniform;
67
use polars::prelude::*;
78

8-
//---------------------------------------------------------------------------------------------------------
9-
// STRUCTS
10-
//---------------------------------------------------------------------------------------------------------
11-
pub struct ModelPoint {
12-
pub model: String,
13-
pub id: i32,
14-
pub entry_age: i32,
15-
pub gender: String,
16-
pub term: i32,
17-
pub policy_count: f64,
18-
pub sum_insured: f64,
19-
pub duration_mth: Option<i32>, // For SE model
20-
pub issue_date: Option<String>, // For ASL_SE model
21-
pub payment_freq: Option<i32>, // For ASL_SE model - 1, 4, 6, 12
22-
pub payment_term: Option<i32>, // For ASL_SE model
23-
}
9+
pub mod asl_se_mp_gen;
10+
pub mod pricing_mp_gen;
11+
pub mod s_mp_gen;
12+
pub mod se_mp_gen;
13+
14+
2415

2516
//---------------------------------------------------------------------------------------------------------
2617
// PUBLIC
2718
//---------------------------------------------------------------------------------------------------------
28-
pub fn generate_s_model_points(mp_size: usize, seed: usize) -> PolarsResult<DataFrame> {
29-
// Get seed for random number generation
30-
let mut rng = StdRng::seed_from_u64(seed as u64);
31-
32-
// Issue Age (Integer): Random 20 - 59 year old
33-
let entry_age = Array1::random_using(mp_size, Uniform::new(20, 60), &mut rng); // 60 is exclusive, so range is 20-59
34-
35-
// Gender (String): Random "M" and "F"
36-
let gender_binary = Array1::random_using(mp_size, Uniform::new(0, 2), &mut rng); // 0 or 1
37-
let gender: Vec<&str> = gender_binary
38-
.iter()
39-
.map(|&x| if x == 0 { "M" } else { "F" }) // map 0 to "M" and 1 to "F"
40-
.collect();
41-
42-
// Policy term (Integer): Random 10, 15 or 20
43-
let term = (Array1::random_using(mp_size, Uniform::new(2, 5), &mut rng)) * 5;
44-
45-
// Policy count
46-
let policy_count = Array1::<f64>::ones(mp_size);
47-
48-
// Sum insured (Float): Random values between 100,000 and 1,000,000 (multiple of 1000)
49-
let sum_insured = Array1::random_using(mp_size, Uniform::new(0.0f64, 1.0f64), &mut rng) // Random floats between 0 and 1
50-
.mapv(|x| (((900_000.0 * x + 100_000.0) / 1000.0).round() * 1000.0));
51-
52-
// Create a DataFrame with the generated data
53-
let model_points_df = df![
54-
"id" => (1..(mp_size+1) as i32).collect::<Vec<i32>>(),
55-
"entry_age" => entry_age.to_vec(),
56-
"gender" => gender,
57-
"term" => term.to_vec(),
58-
"policy_count" => policy_count.to_vec().into_iter().collect::<Vec<f64>>(),
59-
"sum_insured" => sum_insured.to_vec(),
60-
]?;
61-
62-
Ok(model_points_df)
63-
}
6419

6520
pub fn convert_model_points_df_to_vector(df: &DataFrame) -> PolarsResult<Vec<ModelPoint>> {
6621
let id = df.column("id")?.i32()?;
File renamed without changes.

src/model_points/pricing_mp_gen.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use super::*;
2+
use itertools::iproduct;
3+
4+
pub fn generate_s_model_points() -> PolarsResult<DataFrame> {
5+
let age: Vec<i32> = (20..60).collect();
6+
let term: Vec<i32> = vec![10, 15, 20];
7+
let gender: Vec<&str> = vec!["M", "F"];
8+
9+
// Generate all combinations of age, term and gender
10+
let combinations: Vec<(i32, i32, &str)> = iproduct!(age.iter(), term.iter(), gender.iter())
11+
.map(|(&a, &t, &g)| (a, t, g))
12+
.collect();
13+
14+
let model: Vec<&str> = vec!["s_model"; combinations.len()];
15+
let id: Vec<i32> = (1..=combinations.len() as i32).collect();
16+
let age: Vec<i32> = combinations.iter().map(|(a, _, _)| *a).collect();
17+
let term: Vec<i32> = combinations.iter().map(|(_, t, _)| *t).collect();
18+
let gender: Vec<&str> = combinations.iter().map(|(_, _, g)| *g).collect();
19+
// If more information on demographics is needed, it can be added here.
20+
let policy_count: Vec<f64> = vec![1.0; combinations.len()];
21+
let sum_insured: Vec<f64> = vec![1000.0; combinations.len()];
22+
23+
let df = df![
24+
"model" => model,
25+
"id" => id,
26+
"age" => age,
27+
"term" => term,
28+
"gender" => gender,
29+
"policy_count" => policy_count,
30+
"sum_insured" => sum_insured,
31+
]?;
32+
33+
Ok(df)
34+
}

src/model_points/s_mp_gen.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use super::*;
2+
3+
pub fn generate_s_model_points(mp_size: usize, seed: usize) -> PolarsResult<DataFrame> {
4+
// Get seed for random number generation
5+
let mut rng = StdRng::seed_from_u64(seed as u64);
6+
7+
// Issue Age (Integer): Random 20 - 59 year old
8+
let entry_age = Array1::random_using(mp_size, Uniform::new(20, 60), &mut rng); // 60 is exclusive, so range is 20-59
9+
10+
// Gender (String): Random "M" and "F"
11+
let gender_binary = Array1::random_using(mp_size, Uniform::new(0, 2), &mut rng); // 0 or 1
12+
let gender: Vec<&str> = gender_binary
13+
.iter()
14+
.map(|&x| if x == 0 { "M" } else { "F" }) // map 0 to "M" and 1 to "F"
15+
.collect();
16+
17+
// Policy term (Integer): Random 10, 15 or 20
18+
let term = (Array1::random_using(mp_size, Uniform::new(2, 5), &mut rng)) * 5;
19+
20+
// Policy count
21+
let policy_count = Array1::<f64>::ones(mp_size);
22+
23+
// Sum insured (Float): Random values between 100,000 and 1,000,000 (multiple of 1000)
24+
let sum_insured = Array1::random_using(mp_size, Uniform::new(0.0f64, 1.0f64), &mut rng) // Random floats between 0 and 1
25+
.mapv(|x| (((900_000.0 * x + 100_000.0) / 1000.0).round() * 1000.0));
26+
27+
// Create a DataFrame with the generated data
28+
let model_points_df = df![
29+
"id" => (1..(mp_size+1) as i32).collect::<Vec<i32>>(),
30+
"entry_age" => entry_age.to_vec(),
31+
"gender" => gender,
32+
"term" => term.to_vec(),
33+
"policy_count" => policy_count.to_vec().into_iter().collect::<Vec<f64>>(),
34+
"sum_insured" => sum_insured.to_vec(),
35+
]?;
36+
37+
Ok(model_points_df)
38+
}
File renamed without changes.

src/projections/projection_mp.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::assumptions::assumption_scenario::AssumptionScenario;
2-
use polars::prelude::*; // Add this line or adjust the path as needed
2+
use chrono::NaiveDate;
3+
use ndarray::Array1;
4+
use polars::prelude::*;
35

4-
pub mod asl_se_model;
5-
pub mod s_model;
6-
pub mod se_model;
6+
pub mod asl_se;
7+
pub mod structs;
8+
pub mod s;
9+
pub mod se;

src/projections/projection_mp/asl_se.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)