diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b779ec2..91f0ac7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,6 +106,9 @@ jobs: # A workbook following 20,000 prices one at a time, checked against # LibreOffice for the first 300 and a second graph at the end. - run: cargo run --locked --release -p watershed-xlsx --example live -- 20000 + # A pension statement's workbook for 20,000 members, checked against + # LibreOffice for 300, and each answer it seeks checked to be the least. + - run: cargo run --locked --release -p watershed-gpu --example illustrations -- 20000 web: name: Web demo (WebAssembly) diff --git a/README.md b/README.md index 7f47f89..98b5d68 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,9 @@ with its checks and timings. of its inputs comes with it, for a few times the cost of the answer. A rating workbook gives every quote it can, 16 million of them, in half a minute. A risk desk's workbook follows a price feed at 68,000 prices a - second, working out only what each price reaches. + second, working out only what each price reaches. A pension statement's + workbook is run for 300,000 members, and then tried again and again to + find what each member who is short would have to pay in. - **Live tables in the browser.** A grid whose cells, columns and totals are formulas, updated as edits arrive, as a TypeScript package with components for [Solid](packages/grid-solid) and [React](packages/grid-react). The diff --git a/crates/watershed-gpu/README.md b/crates/watershed-gpu/README.md index 3c3da50..46fcd89 100644 --- a/crates/watershed-gpu/README.md +++ b/crates/watershed-gpu/README.md @@ -113,6 +113,7 @@ Where a time is scaled up from a smaller run, it says so. | `audit` | The same workbook tried at 200,000 points spread over its inputs' ranges and at every corner of them, each input then moved through its range from 300 starting points, and a later version of the workbook run for the same points | its own findings when run on its own: the two cells changed, and which loans the slip in one of them reaches | not run | 17 s for all of it, on the same 4 cores | | | `sensitivities` | The same workbook's provision with its derivative by 689 inputs (17 of the bank's choices and every quarter of three paths of the economy), for 50,000 mortgages | nudging each input up and down for the workbook's own loan: all 689 agree, the furthest by 4×10⁻⁹ | not run | 7.6 s, against 1.4 s for the provision alone, on the same 4 cores | nudging each for the book, 1,378 runs of it: 32 minutes (scaled) | | `quotes` | A car insurance rating workbook, priced for every customer it can quote: 16 million combinations of age, area, vehicle group, years without a claim, mileage, excess and cover. Then again with next quarter's rates | LibreOffice recalculating the workbook for each of 300 customers: every answer the same to the penny; 2,000 quotes against the graph | not run | 31 s, on 4 cores of a different machine (a cloud VM) | LibreOffice, a quote at a time, at the 9.73 ms it took on that machine: 43 hours (scaled). A quote looked up in the finished table: 54 ns | +| `illustrations` | A workbook that works out one member's pension statement (1,168 formulas: the pot year by year to retirement at three rates of growth), for a scheme of 300,000 members. Then, for each of the 180,801 who are short, the least they could pay in that would put them on track | LibreOffice recalculating the workbook for each of 300 members: every answer agrees; 2,000 members against the graph, bit for bit | not run | 2.1 s for the statements and 6.1 s for 844,377 tries of the workbook, on 4 cores of a different machine (a cloud VM) | LibreOffice, a member at a time, at the 15.6 ms it took on that machine: 78 minutes for the statements alone (scaled) | | `dosing` | An antibiotic's dosing protocol tried on 5 million made-up patients, each followed for 72 hours | SciPy's LSODA solver, 300 patients: 1.7×10⁻¹⁰ | 60 ms a protocol, 51 protocols in 3.0 s | 1.8 s a protocol | the graph: 70 s (scaled) | | `monte_carlo` | 200,000 positions on 500 shares, 100,000 futures | the graph, bit for bit | 1.6 s | about 29 s (scaled) | the graph: about 25 minutes (scaled) | | `tax_benefit` | A country's tax and benefit rules over 10 million households | the graph, bit for bit | 0.7 s | 0.5 s | the graph: 28 s (scaled) | @@ -446,6 +447,12 @@ What is taken from somewhere, and what is made up. `examples/shared/rating.py` and worked out by LibreOffice, which the same script then drives through 300 customers for the reference. Every rate in it is made up, as are next quarter's. +- **`illustrations`.** The workbook, `examples/shared/illustration.xlsx`, is + written by `examples/shared/illustration.py` and worked out by + LibreOffice, which the same script then drives through 300 members for + the reference. The members, the rates of growth, the income a pot buys + and the income to aim for are all made up, so the share of members on + track says nothing about any real scheme. - **`backtest`, `experts`.** Daily prices from 2010 to 2025 for shares with a price throughout, from the FINSABER data set on Hugging Face (`finsaber-team/FINSABER-V2-Data`), which does not say where its prices @@ -476,6 +483,7 @@ cargo run --release --features cuda --example credit_loss cargo run --release --features cuda --example audit cargo run --release --features cuda --example sensitivities cargo run --release --features cuda --example quotes +cargo run --release --features cuda --example illustrations ``` Without `--features cuda` each runs on the CPU, with fewer scenarios unless diff --git a/crates/watershed-gpu/examples/illustrations.rs b/crates/watershed-gpu/examples/illustrations.rs new file mode 100644 index 0000000..881ecdb --- /dev/null +++ b/crates/watershed-gpu/examples/illustrations.rs @@ -0,0 +1,449 @@ +//! One member's pension statement, worked out for the whole scheme. +//! +//! Every year a pension scheme tells each member what their pot might buy +//! when they retire. The sums live in a workbook: the member at the top, +//! the pot followed year by year to retirement at a low, a middle and a +//! high rate of growth, and at the bottom an income in today's money and +//! whether it is the income the member should be aiming for. The workbook +//! answers for one member. The scheme has hundreds of thousands, and the +//! statements are a mail merge that runs overnight. +//! +//! This reads the workbook with `watershed-xlsx` and works every member's +//! statement out at once. Nothing is rewritten by hand. It checks itself +//! against the values saved in the workbook, against LibreOffice +//! recalculating the workbook for each of 300 members, and against the +//! graph a member at a time. +//! +//! Then it does what a statement cannot. A statement says "you are not on +//! track"; a member wants to know what would put them on track. A +//! spreadsheet answers that with Goal Seek, for the one member on the +//! screen. Here every member who is short gets their own answer: the least +//! they could pay in that would do it, found by trying rates between the +//! one they pay now and thirty percent, each try a run of the workbook. +//! +//! cargo run --release --features cuda --example illustrations +//! +//! then optionally how many members (300,000). +//! +//! The workbook is `shared/illustration.xlsx`, written by +//! `shared/illustration.py`, which also has LibreOffice make the reference. +//! The members and every assumption are made up; the shape of the +//! calculation is the usual one. The `pensions` example is a different +//! kind of scheme, one that has promised its members a pension, written +//! straight onto a graph. + +use std::time::{Duration, Instant}; + +use watershed_core::Value; +use watershed_gpu::Scenarios; +use watershed_xlsx::{Model, Workbook}; + +type Result = std::result::Result>; + +const WORKBOOK: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/examples/shared/illustration.xlsx" +); +/// What LibreOffice made of the workbook for some members, one at a time. +const REFERENCE: &str = include_str!("shared/illustration_reference.csv"); + +/// The member's cells: age, pay, the pot today, what the member and the +/// employer pay in as shares of pay, and the age the member retires at. +const MEMBER: [&str; 6] = [ + "Member!B4", + "Member!B5", + "Member!B6", + "Member!B7", + "Member!B8", + "Member!B9", +]; +/// Where a member's own rate is among those. +const PAYS: usize = 3; +/// The pot at retirement and the income a year on the middle figures, the +/// income on the low and the high, whether the member is on track, and how +/// far short a year. +const ANSWERS: [&str; 6] = [ + "Member!C13", + "Member!C17", + "Member!B17", + "Member!D17", + "Member!B21", + "Member!B22", +]; +const INCOME: usize = 1; +const ON_TRACK: usize = 4; +/// Rates are tried in steps of half a point of pay, up to thirty points. +const STEP: f64 = 0.005; +const MOST: f64 = 0.30; + +/// A plan, on the GPU when there is one. +struct Runner { + #[cfg(feature = "gpu")] + gpu: watershed_gpu::Gpu, +} + +impl Runner { + fn new() -> Result { + Ok(Runner { + #[cfg(feature = "gpu")] + gpu: watershed_gpu::Gpu::new()?, + }) + } + + fn run(&self, plan: &Scenarios, members: &[[f64; 6]]) -> Result> { + #[cfg(feature = "gpu")] + return Ok(self.gpu.run(plan, members.as_flattened())?); + #[cfg(not(feature = "gpu"))] + Ok(plan.run_cpu(members.as_flattened())) + } + + /// Whether each member is on track. + fn on_track(&self, plan: &Scenarios, members: &[[f64; 6]]) -> Result> { + Ok(self + .run(plan, members)? + .chunks(ANSWERS.len()) + .map(|answer| answer[ON_TRACK] == 1.0) + .collect()) + } +} + +/// A small deterministic random number generator, so every run is the same. +struct Rng(u64); +impl Rng { + fn unit(&mut self) -> f64 { + self.0 ^= self.0 << 13; + self.0 ^= self.0 >> 7; + self.0 ^= self.0 << 17; + ((self.0 >> 11) as f64 + 0.5) / (1u64 << 53) as f64 + } + + fn pick(&mut self, among: &[f64]) -> f64 { + among[((self.unit() * among.len() as f64) as usize).min(among.len() - 1)] + } +} + +/// One member of a made-up scheme, as the six numbers the workbook asks for. +fn made_up_member(rng: &mut Rng) -> [f64; 6] { + let age = (22 + (43.0 * rng.unit()) as u32) as f64; + let pay = (170.0 * (1.9 * rng.unit().powf(1.5)).exp()).round() * 100.0; + // A pot is some years of contributions, more for the older. + let pot = (pay * 0.08 * (age - 21.0) * (0.2 + 1.6 * rng.unit()) / 100.0).round() * 100.0; + let pays = rng.pick(&[0.03, 0.04, 0.05, 0.05, 0.05, 0.06, 0.08, 0.10]); + let employer = rng.pick(&[0.03, 0.03, 0.04, 0.05, 0.06, 0.08]); + let retires = rng + .pick(&[60.0, 63.0, 65.0, 66.0, 67.0, 67.0, 67.0, 68.0]) + .max(age + 1.0); + [age, pay, pot, pays, employer, retires] +} + +/// The same to about twelve figures. +fn close(a: f64, b: f64) -> bool { + (a - b).abs() <= 1e-9 * a.abs().max(b.abs()).max(1e-6) +} + +fn main() -> Result<()> { + let count: usize = match std::env::args().nth(1) { + Some(n) => n.replace('_', "").parse()?, + None => 300_000, + }; + let runner = Runner::new()?; + + // ---- The workbook ---- + println!("1. The workbook"); + let started = Instant::now(); + let book = Workbook::open(WORKBOOK)?; + let cells = |names: &[&str]| -> Result> { + Ok(names + .iter() + .map(|name| book.cell(name)) + .collect::>()?) + }; + let inputs = cells(&MEMBER)?; + let answers = cells(&ANSWERS)?; + let mut model = Model::build(&book, &inputs, &answers)?; + let wrong = model.check(); + if let Some(first) = wrong.first() { + return Err(format!("the graph does not agree with the workbook: {first}").into()); + } + println!( + " illustration.xlsx: {} formulas, {} of them between the member and the statement, each as the workbook has it", + book.formulas(), + model.translated() + ); + println!( + " read and translated in {}; it uses {}", + time(started.elapsed()), + model + .functions() + .iter() + .map(|(name, n)| format!("{name} ×{n}")) + .collect::>() + .join(", ") + ); + let output_ids = model.outputs(); + let plan = Scenarios::new(model.graph(), &model.inputs(), &output_ids)?; + let own: [f64; 6] = model.workbook_inputs()[..].try_into().expect("six cells"); + println!(); + + // ---- Against LibreOffice ---- + println!("2. Against LibreOffice, a member at a time"); + let mut lines = REFERENCE.lines(); + let note = lines.next().ok_or("the reference is empty")?; + let each_ms: f64 = note + .rsplit(": ") + .next() + .and_then(|took| took.strip_suffix(" ms a member")) + .ok_or("the reference does not say how long a member took")? + .parse()?; + let rows: Vec> = lines + .skip(1) + .map(|line| line.split(',').map(str::parse).collect()) + .collect::>()?; + let theirs: Vec<[f64; 6]> = rows + .iter() + .map(|row| row[..MEMBER.len()].try_into().expect("six numbers")) + .collect(); + let ours = runner.run(&plan, &theirs)?; + for (row, here) in rows.iter().zip(ours.chunks(ANSWERS.len())) { + for (&there, &here) in row[MEMBER.len()..].iter().zip(here) { + assert!( + close(here, there), + "{here} here and {there} in LibreOffice, for the member {:?}", + &row[..MEMBER.len()] + ); + } + } + println!( + " {} members, six answers each: every one agrees", + rows.len() + ); + println!( + " LibreOffice took {each_ms} ms a member, the member's cells set and the workbook recalculated" + ); + println!(); + + // ---- The scheme ---- + println!("3. The scheme"); + let mut rng = Rng(0x2545_F491_4F6C_DD1D); + let members: Vec<[f64; 6]> = (0..count).map(|_| made_up_member(&mut rng)).collect(); + let started = Instant::now(); + let statements = runner.run(&plan, &members)?; + let took = started.elapsed(); + println!( + " {} statements in {} ({} a second); LibreOffice, at {each_ms} ms a member, would take {}", + commas(count as f64), + time(took), + commas(count as f64 / took.as_secs_f64()), + time(Duration::from_secs_f64(each_ms / 1000.0 * count as f64)) + ); + // The graph itself, a member at a time, as the spreadsheet would do it: + // it must agree with the plan to the last bit. + let few = count.min(2_000); + let started = Instant::now(); + for (member, statement) in members + .iter() + .zip(statements.chunks(ANSWERS.len())) + .take(few) + { + model.set(member)?; + for (&id, &x) in output_ids.iter().zip(statement) { + let Value::F64(here) = model.graph().value(id) else { + unreachable!("an answer is a number") + }; + assert!( + here.to_bits() == x.to_bits(), + "the graph and the plan differ" + ); + } + } + println!( + " the graph, a member at a time, agrees to the last bit for the first {}: {} a member", + commas(few as f64), + time(started.elapsed() / few as u32) + ); + println!(); + println!( + " {:<10} {:>10} {:>26} {:>10}", + "age", "members", "income a year, half below", "on track" + ); + let on_track: Vec = statements + .chunks(ANSWERS.len()) + .map(|s| s[ON_TRACK] == 1.0) + .collect(); + for (from, to) in [(22, 29), (30, 39), (40, 49), (50, 59), (60, 64), (22, 64)] { + let these: Vec = (0..count) + .filter(|&m| (from..=to).contains(&(members[m][0] as u32))) + .collect(); + if these.is_empty() { + continue; + } + let mut incomes: Vec = these + .iter() + .map(|&m| statements[m * ANSWERS.len() + INCOME]) + .collect(); + incomes.sort_by(f64::total_cmp); + println!( + " {:<10} {:>10} {:>26} {:>9.1}%", + match (from, to) { + (22, 64) => "all".to_string(), + _ => format!("{from} to {to}"), + }, + commas(these.len() as f64), + commas(incomes[incomes.len() / 2]), + 100.0 * these.iter().filter(|&&m| on_track[m]).count() as f64 / these.len() as f64 + ); + } + let statement = runner.run(&plan, &[own])?; + println!( + " the workbook's own member (aged {}, paid {}, a pot of {}): {} a year, or {} to {}; short by {}", + own[0], + commas(own[1]), + commas(own[2]), + commas(statement[1]), + commas(statement[2]), + commas(statement[3]), + commas(statement[5]) + ); + println!(); + + // ---- If they all did one thing ---- + println!("4. If every member did one thing"); + let share = |members: &[[f64; 6]]| -> Result { + let on = runner.on_track(&plan, members)?; + Ok(100.0 * on.iter().filter(|&&on| on).count() as f64 / on.len() as f64) + }; + let mut changed = members.clone(); + for member in &mut changed { + member[PAYS] += 0.01; + } + let a_point_more = share(&changed)?; + let mut changed = members.clone(); + for member in &mut changed { + member[5] += 1.0; + } + let a_year_longer = share(&changed)?; + let now = 100.0 * on_track.iter().filter(|&&on| on).count() as f64 / count as f64; + println!(" on track now: {now:.1}%"); + println!(" if each paid in one more point of pay: {a_point_more:.1}%"); + println!(" if each worked a year longer: {a_year_longer:.1}%"); + assert!(a_point_more >= now && a_year_longer >= now); + println!(); + + // ---- What it would take, member by member ---- + println!("5. What it would take, member by member"); + let short: Vec = (0..count).filter(|&m| !on_track[m]).collect(); + // The steps of half a point between what each pays now and the most. + // `low` is a count of steps known to fall short, `high` one known to do. + let steps = |m: usize| ((MOST - members[m][PAYS]) / STEP).round() as u32; + let at = |m: usize, step: u32| { + let mut member = members[m]; + member[PAYS] += f64::from(step) * STEP; + member + }; + let started = Instant::now(); + let most: Vec<[f64; 6]> = short.iter().map(|&m| at(m, steps(m))).collect(); + let can = runner.on_track(&plan, &most)?; + let mut runs = most.len(); + // Those thirty points would put on track: halve the gap until it is a step. + let mut seeking: Vec<(usize, u32, u32)> = short + .iter() + .zip(&can) + .filter(|&(_, &can)| can) + .map(|(&m, _)| (m, 0, steps(m))) + .collect(); + let never = short.len() - seeking.len(); + let mut rounds = 0; + while seeking.iter().any(|&(_, low, high)| high - low > 1) { + let tries: Vec<[f64; 6]> = seeking + .iter() + .map(|&(m, low, high)| at(m, (low + high) / 2)) + .collect(); + let enough = runner.on_track(&plan, &tries)?; + runs += tries.len(); + rounds += 1; + for ((_, low, high), enough) in seeking.iter_mut().zip(enough) { + if *high - *low > 1 { + let middle = (*low + *high) / 2; + match enough { + true => *high = middle, + false => *low = middle, + } + } + } + } + println!( + " {} members are short; {} tries of the workbook in {} ({} rounds of halving)", + commas(short.len() as f64), + commas(runs as f64), + time(started.elapsed()), + rounds + ); + // Each answer is the least that does: it does, and half a point less does not. + let check = seeking.len().min(5_000); + let does: Vec<[f64; 6]> = seeking[..check] + .iter() + .map(|&(m, _, high)| at(m, high)) + .collect(); + let does_not: Vec<[f64; 6]> = seeking[..check] + .iter() + .map(|&(m, _, high)| at(m, high - 1)) + .collect(); + assert!(runner.on_track(&plan, &does)?.iter().all(|&on| on)); + assert!(runner.on_track(&plan, &does_not)?.iter().all(|&on| !on)); + let mut more: Vec = seeking + .iter() + .map(|&(_, _, high)| f64::from(high) * STEP * 100.0) + .collect(); + more.sort_by(f64::total_cmp); + let within = |points: f64| more.iter().filter(|&&m| m <= points).count(); + println!(" the least more each would have to pay in, as points of pay:"); + for points in [1.0, 2.0, 5.0, 10.0] { + println!( + " {:>4} or less: {:>9} ({:.1}% of those short)", + points, + commas(within(points) as f64), + 100.0 * within(points) as f64 / short.len() as f64 + ); + } + println!( + " more than 10: {:>9}; half of those who can get there need {} or less", + commas((more.len() - within(10.0)) as f64), + more[more.len() / 2] + ); + println!( + " thirty points of pay would not do it for {} ({:.1}%)", + commas(never as f64), + 100.0 * never as f64 / short.len() as f64 + ); + Ok(()) +} + +fn commas(x: f64) -> String { + let digits = format!("{:.0}", x.abs()); + let mut out = String::new(); + for (i, c) in digits.chars().enumerate() { + if i > 0 && (digits.len() - i) % 3 == 0 { + out.push(','); + } + out.push(c); + } + if x < 0.0 && digits != "0" { + out.insert(0, '-'); + } + out +} + +fn time(d: Duration) -> String { + let s = d.as_secs_f64(); + if s < 0.001 { + format!("{:.1} µs", s * 1e6) + } else if s < 1.0 { + format!("{:.0} ms", s * 1e3) + } else if s < 120.0 { + format!("{s:.1} s") + } else if s < 7200.0 { + format!("{:.0} minutes", s / 60.0) + } else { + format!("{:.1} hours", s / 3600.0) + } +} diff --git a/crates/watershed-gpu/examples/shared/illustration.py b/crates/watershed-gpu/examples/shared/illustration.py new file mode 100644 index 0000000..0f29510 --- /dev/null +++ b/crates/watershed-gpu/examples/shared/illustration.py @@ -0,0 +1,282 @@ +"""Writes `illustration.xlsx`, the workbook the `illustrations` example reads, +and `illustration_reference.csv`, what LibreOffice makes of it for some +members. + +The workbook is the kind a pension scheme's administrator keeps for the +yearly statement: one member on the `Member` sheet, what is assumed on +`Assumptions`, and the member's pot followed year by year to retirement on +`Projection`, at a low, a middle and a high rate of growth. It says what the +pot might buy, in today's money, and whether that is the income the member +should aim for. Every number in it is made up; the shape is the usual one. + +It is written with `openpyxl` and worked out by LibreOffice, which must both +be installed: + + python3 crates/watershed-gpu/examples/shared/illustration.py + +Then LibreOffice is driven directly: the member's cells are set to each of +some made-up members in turn and the workbook recalculated, as a mail merge +of statements would. What it answers, and how long a member took, go in the +reference file for the example to check itself against. +""" + +import csv +import math +import os +import shutil +import subprocess +import sys +import tempfile +import time + +import openpyxl +from openpyxl.styles import Font + +HERE = os.path.dirname(os.path.abspath(__file__)) +YEARS = 58 # From today to the last year anyone could still be working. +FIRST = 5 +LAST = FIRST + YEARS - 1 +REFERENCE_MEMBERS = 300 + +# The member's cells, in the order the example and the reference file use. +INPUTS = ["B4", "B5", "B6", "B7", "B8", "B9"] +# What is read back: the pot at retirement and the income a year on the +# middle figures, the income on the low and the high, whether the member is +# on track, and how far short a year. +OUTPUTS = ["C13", "C17", "B17", "D17", "B21", "B22"] + + +def assumptions(ws): + ws["A1"] = "What is assumed" + for r, (what, value) in enumerate([ + ("Prices rise each year by", 0.025), + ("Pay rises faster than prices by", 0.01), + ("Charged on the pot each year", 0.005), + ("Growth a year: low", 0.02), + ("Growth a year: middle", 0.05), + ("Growth a year: high", 0.08), + ("Pay below this earns no contribution", 6240), + ("nor pay above this", 50270), + ("Share of the pot taken as cash, tax free", 0.25), + ("State pension a year", 11500), + ("paid from age", 67), + ("Growth of what is moved out of shares near retirement", 0.03), + ], start=4): + ws.cell(r, 1, what) + ws.cell(r, 2, value) + + def table(col, heads, rows): + for c, head in enumerate(heads): + ws.cell(4, col + c, head).font = Font(bold=True) + for r, row in enumerate(rows, start=5): + for c, value in enumerate(row): + ws.cell(r, col + c, value) + + table(4, ["Retiring from age", "Income a year for each 1 of pot"], [ + (55, 0.050), (58, 0.053), (60, 0.056), (62, 0.059), (64, 0.062), + (65, 0.064), (66, 0.066), (67, 0.068), (68, 0.070), (70, 0.075)]) + table(7, ["Years to retirement from", "Share still in shares"], [ + (0, 0.4), (3, 0.55), (5, 0.7), (7, 0.85), (10, 1.0)]) + table(10, ["Pay from", "Share of pay to aim for in retirement"], [ + (0, 0.80), (15000, 0.70), (27000, 0.67), (37000, 0.60), (62000, 0.50)]) + ws.column_dimensions["A"].width = 50 + + +# Where each rate of growth's columns start on Projection, and its cell. +RATES = [("Low", 11, "$B$7"), ("Middle", 15, "$B$8"), ("High", 19, "$B$9")] + + +def col(n): + return openpyxl.utils.get_column_letter(n) + + +def projection(ws): + ws["A1"] = "The pot, year by year" + heads = ["Years from now", "Age", "At work", "Pay", "Pay that counts", "Paid in", + "Years to retirement", "Share in shares", "Worth in today's money", "Retires this year"] + for c, head in enumerate(heads, start=1): + ws.cell(4, c, head).font = Font(bold=True) + for name, start, _ in RATES: + ws.cell(3, start, name).font = Font(bold=True) + for k, head in enumerate(["Pot at the start", "Growth", "Pot at the end", + "At retirement, in today's money"]): + ws.cell(4, start + k, head).font = Font(bold=True) + a = "Assumptions!" + for t in range(YEARS): + r = FIRST + t + ws.cell(r, 1, t) + ws.cell(r, 2, f"=Member!$B$4+A{r}") + ws.cell(r, 3, f"=IF(B{r}=B20,1,0)" + ws["A22"], ws["B22"] = "Short of it, a year", "=MAX(0,ROUND(B20*B5-C17,-1))" + for cell in ("A1", "A3"): + ws[cell].font = Font(bold=True) + ws.column_dimensions["A"].width = 50 + + +def write(path): + wb = openpyxl.Workbook() + sheet = wb.active + sheet.title = "Member" + member(sheet) + projection(wb.create_sheet("Projection")) + assumptions(wb.create_sheet("Assumptions")) + wb.save(path) + + +def worked_out(path, out_dir): + """Has LibreOffice work out every cell and save the workbook again.""" + with tempfile.TemporaryDirectory() as tmp: + subprocess.run( + ["soffice", "--headless", "--calc", "--convert-to", "xlsx", "--outdir", tmp, path], + check=True, + capture_output=True, + ) + shutil.move(os.path.join(tmp, os.path.basename(path)), os.path.join(out_dir, os.path.basename(path))) + + +class Rng: + """A small deterministic random number generator, the example's own kind.""" + + def __init__(self, seed): + self.state = seed + + def unit(self): + s = self.state + s ^= (s << 13) & 0xFFFFFFFFFFFFFFFF + s ^= s >> 7 + s ^= (s << 17) & 0xFFFFFFFFFFFFFFFF + self.state = s + return ((s >> 11) + 0.5) / float(1 << 53) + + +def made_up_member(rng): + """One member of a made-up scheme, of the kind `illustrations.rs` makes.""" + age = float(22 + int(43 * rng.unit())) + pay = round(17000 * math.exp(1.9 * rng.unit() ** 1.5), -2) + # A pot is some years of contributions, more for the older. + pot = round(pay * 0.08 * (age - 21) * (0.2 + 1.6 * rng.unit()), -2) + pays = [0.03, 0.04, 0.05, 0.05, 0.05, 0.06, 0.08, 0.10][int(8 * rng.unit())] + employer = [0.03, 0.03, 0.04, 0.05, 0.06, 0.08][int(6 * rng.unit())] + retires = max(age + 1, [60.0, 63.0, 65.0, 66.0, 67.0, 67.0, 67.0, 68.0][int(8 * rng.unit())]) + return [age, pay, pot, pays, employer, retires] + + +def reference(workbook, out): + """Drives LibreOffice through some members, one at a time.""" + import uno # noqa: F401 (LibreOffice's own Python bridge) + from com.sun.star.beans import PropertyValue + from com.sun.star.connection import NoConnectException + + port = 2002 + office = subprocess.Popen( + ["soffice", "--headless", "--norestore", f"--accept=socket,host=localhost,port={port};urp;"], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + try: + local = uno.getComponentContext() + resolver = local.ServiceManager.createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", local) + for _ in range(120): + try: + context = resolver.resolve( + f"uno:socket,host=localhost,port={port};urp;StarOffice.ComponentContext") + break + except NoConnectException: + time.sleep(0.5) + else: + raise SystemExit("LibreOffice did not start") + desktop = context.ServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", context) + hidden = PropertyValue() + hidden.Name, hidden.Value = "Hidden", True + doc = desktop.loadComponentFromURL( + uno.systemPathToFileUrl(workbook), "_blank", 0, (hidden,)) + sheet = doc.Sheets.getByName("Member") + rng = Rng(0x9E3779B97F4A7C15) + members = [made_up_member(rng) for _ in range(REFERENCE_MEMBERS)] + rows = [] + started = time.perf_counter() + for one in members: + for cell, value in zip(INPUTS, one): + sheet.getCellRangeByName(cell).Value = value + doc.calculateAll() + rows.append(one + [sheet.getCellRangeByName(c).Value for c in OUTPUTS]) + each = (time.perf_counter() - started) / len(members) + doc.close(True) + with open(out, "w", newline="") as f: + f.write(f"# LibreOffice recalculating illustration.xlsx for each member: " + f"{each * 1000:.1f} ms a member\n") + w = csv.writer(f) + w.writerow(["age", "pay", "pot", "pays", "employer", "retires", + "pot_at_retirement", "income", "income_low", "income_high", + "on_track", "short"]) + for row in rows: + w.writerow([repr(float(x)) for x in row]) + print(f"LibreOffice: {each * 1000:.1f} ms a member", file=sys.stderr) + finally: + office.terminate() + + +def main(): + target = os.path.join(HERE, "illustration.xlsx") + with tempfile.TemporaryDirectory() as tmp: + path = os.path.join(tmp, "illustration.xlsx") + write(path) + worked_out(path, HERE) + print("wrote", target, file=sys.stderr) + if "--no-reference" not in sys.argv: + reference(target, os.path.join(HERE, "illustration_reference.csv")) + + +if __name__ == "__main__": + main() diff --git a/crates/watershed-gpu/examples/shared/illustration.xlsx b/crates/watershed-gpu/examples/shared/illustration.xlsx new file mode 100644 index 0000000..eb56930 Binary files /dev/null and b/crates/watershed-gpu/examples/shared/illustration.xlsx differ diff --git a/crates/watershed-gpu/examples/shared/illustration_reference.csv b/crates/watershed-gpu/examples/shared/illustration_reference.csv new file mode 100644 index 0000000..bc0c3e2 --- /dev/null +++ b/crates/watershed-gpu/examples/shared/illustration_reference.csv @@ -0,0 +1,302 @@ +# LibreOffice recalculating illustration.xlsx for each member: 15.6 ms a member +age,pay,pot,pays,employer,retires,pot_at_retirement,income,income_low,income_high,on_track,short +58.0,27200.0,78000.0,0.04,0.03,67.0,101543.4583478203,16680.0,15940.0,17540.0,0.0,1540.0 +48.0,75400.0,258200.0,0.05,0.03,63.0,381114.6837143191,28360.0,23850.0,34500.0,0.0,9340.0 +36.0,17400.0,28300.0,0.08,0.03,67.0,107467.56023224203,16980.0,14730.0,21380.0,1.0,0.0 +64.0,38900.0,97300.0,0.06,0.03,67.0,108722.85948004053,17040.0,16840.0,17250.0,0.0,6300.0 +24.0,17400.0,6600.0,0.05,0.03,65.0,80742.92180402698,15370.0,13720.0,19080.0,1.0,0.0 +40.0,66200.0,120100.0,0.06,0.06,63.0,317945.98109675356,25570.0,20730.0,33470.0,0.0,7530.0 +42.0,37300.0,47600.0,0.06,0.03,65.0,154604.46055674614,18920.0,16570.0,22700.0,0.0,3460.0 +30.0,17900.0,3600.0,0.06,0.04,68.0,84153.85327874664,15920.0,14250.0,19260.0,1.0,0.0 +38.0,83500.0,84900.0,0.05,0.08,63.0,300033.6287808117,24780.0,20200.0,32480.0,0.0,16970.0 +52.0,22300.0,58500.0,0.05,0.06,68.0,108902.659201414,17220.0,15740.0,19260.0,1.0,0.0 +32.0,25600.0,24800.0,0.05,0.08,66.0,180522.52171332063,20440.0,16960.0,27340.0,1.0,0.0 +36.0,52000.0,72200.0,0.05,0.04,68.0,288100.2047661592,26630.0,20120.0,39680.0,0.0,4570.0 +50.0,23800.0,37900.0,0.05,0.03,67.0,78594.7785632938,15510.0,14450.0,17010.0,0.0,1150.0 +27.0,19200.0,2300.0,0.06,0.08,63.0,113623.08877438106,16530.0,14780.0,19810.0,1.0,0.0 +35.0,28500.0,41700.0,0.1,0.06,66.0,237377.61912537515,23250.0,18860.0,31510.0,1.0,0.0 +48.0,57800.0,219200.0,0.04,0.08,67.0,409865.20890665246,32400.0,25770.0,42360.0,0.0,2280.0 +42.0,31400.0,91700.0,0.06,0.03,67.0,216699.04350644664,22550.0,18280.0,30010.0,1.0,0.0 +33.0,32400.0,34900.0,0.03,0.03,67.0,146659.66698321965,18980.0,15700.0,25880.0,0.0,2730.0 +46.0,21600.0,76700.0,0.04,0.06,65.0,140763.41740585974,18260.0,16110.0,21480.0,1.0,0.0 +50.0,56300.0,27300.0,0.04,0.06,65.0,106015.31605728192,16590.0,15640.0,17820.0,0.0,17190.0 +24.0,18300.0,2600.0,0.05,0.04,67.0,93448.41046953978,16260.0,14300.0,20570.0,1.0,0.0 +47.0,21500.0,60600.0,0.05,0.04,63.0,104020.11290011385,16100.0,14870.0,17810.0,1.0,0.0 +41.0,34100.0,63100.0,0.08,0.04,67.0,218206.45196597563,22630.0,18690.0,29450.0,0.0,220.0 +47.0,17200.0,61700.0,0.1,0.03,67.0,122261.03218779713,17730.0,15710.0,20860.0,1.0,0.0 +45.0,17000.0,56500.0,0.06,0.04,66.0,109404.6106699613,16910.0,15030.0,19890.0,1.0,0.0 +47.0,54600.0,25700.0,0.04,0.06,66.0,129169.88566139108,17890.0,16400.0,20000.0,0.0,14870.0 +41.0,105100.0,113000.0,0.05,0.03,67.0,285431.9449558077,26050.0,20260.0,36390.0,0.0,26500.0 +26.0,55600.0,12700.0,0.03,0.06,66.0,247070.71427435445,23730.0,18500.0,35020.0,0.0,9630.0 +40.0,28900.0,58500.0,0.03,0.05,68.0,167011.58022582644,20260.0,16710.0,26900.0,1.0,0.0 +32.0,24600.0,19800.0,0.06,0.04,66.0,134997.34670048446,18190.0,15550.0,23430.0,1.0,0.0 +38.0,57600.0,121200.0,0.05,0.04,63.0,302424.6541793945,24880.0,19750.0,33790.0,0.0,9680.0 +53.0,70500.0,55700.0,0.06,0.06,67.0,148192.19262212684,19060.0,17600.0,20930.0,0.0,16190.0 +60.0,25200.0,77200.0,0.03,0.03,67.0,91985.2808139508,16190.0,15690.0,16750.0,0.0,1450.0 +34.0,18200.0,6500.0,0.05,0.03,67.0,62101.44361145244,14670.0,13530.0,16830.0,1.0,0.0 +44.0,84400.0,218300.0,0.03,0.08,60.0,363945.7846776574,26780.0,22610.0,32590.0,0.0,15420.0 +24.0,49100.0,10100.0,0.05,0.06,67.0,321516.6280435029,27900.0,20610.0,44400.0,0.0,1560.0 +48.0,101800.0,116800.0,0.06,0.08,63.0,246929.8407609792,22430.0,19930.0,25760.0,0.0,28470.0 +60.0,59600.0,161900.0,0.1,0.03,63.0,183228.6671672695,19610.0,19310.0,19910.0,0.0,16150.0 +63.0,18000.0,23000.0,0.03,0.05,66.0,26453.74275599654,12810.0,12760.0,12860.0,1.0,0.0 +53.0,20700.0,63200.0,0.05,0.06,67.0,103896.35740690821,16800.0,15570.0,18420.0,1.0,0.0 +46.0,17000.0,11700.0,0.1,0.06,67.0,64418.86989681956,14790.0,13970.0,15990.0,1.0,0.0 +25.0,37500.0,12000.0,0.05,0.03,67.0,207777.94177808877,22100.0,17540.0,32330.0,0.0,400.0 +40.0,31000.0,65700.0,0.05,0.08,65.0,209990.91043943417,21580.0,18070.0,27530.0,1.0,0.0 +30.0,18200.0,12800.0,0.05,0.08,67.0,122799.54343909922,17760.0,15250.0,23000.0,1.0,0.0 +25.0,19500.0,8700.0,0.04,0.06,67.0,120719.066943425,17660.0,15000.0,23690.0,1.0,0.0 +26.0,24500.0,10900.0,0.05,0.03,66.0,124160.9794089721,17650.0,15040.0,23390.0,1.0,0.0 +61.0,52900.0,300200.0,0.05,0.03,68.0,350033.71380121785,29880.0,27870.0,32090.0,0.0,1860.0 +59.0,33100.0,59700.0,0.08,0.06,67.0,97844.5610822203,16490.0,15940.0,17110.0,0.0,5690.0 +42.0,43700.0,51400.0,0.06,0.03,60.0,142397.49699610498,17480.0,15960.0,19640.0,0.0,8740.0 +32.0,53400.0,53500.0,0.08,0.03,68.0,333627.67426823766,29020.0,21330.0,45400.0,0.0,3020.0 +33.0,37300.0,9900.0,0.03,0.05,63.0,126133.252560488,17080.0,15290.0,20190.0,0.0,5300.0 +43.0,73900.0,213900.0,0.05,0.04,68.0,443070.2416837167,34760.0,25210.0,51640.0,0.0,2190.0 +25.0,21800.0,5600.0,0.05,0.04,67.0,118813.53349513513,17560.0,15040.0,23140.0,1.0,0.0 +53.0,33700.0,111000.0,0.04,0.05,66.0,170710.91652125295,19950.0,18100.0,22320.0,0.0,2630.0 +44.0,20100.0,29400.0,0.03,0.08,67.0,90437.98095880503,16110.0,14630.0,18510.0,1.0,0.0 +52.0,17200.0,59300.0,0.05,0.08,68.0,103647.23329760891,16940.0,15500.0,18940.0,1.0,0.0 +26.0,32700.0,22000.0,0.05,0.06,67.0,253762.8788653806,24440.0,18830.0,37130.0,1.0,0.0 +27.0,17300.0,9700.0,0.04,0.06,68.0,103224.23696578707,16920.0,14570.0,22260.0,1.0,0.0 +50.0,20800.0,42400.0,0.05,0.08,66.0,90867.69054996813,16000.0,14900.0,17500.0,1.0,0.0 +52.0,57400.0,186200.0,0.06,0.04,67.0,305213.3879180182,27070.0,23100.0,32420.0,0.0,7370.0 +48.0,18400.0,39800.0,0.08,0.05,67.0,92231.57238548511,16200.0,14850.0,18200.0,1.0,0.0 +44.0,18100.0,29100.0,0.05,0.05,68.0,82778.34139124409,15850.0,14350.0,18350.0,1.0,0.0 +50.0,34700.0,123300.0,0.05,0.06,66.0,217392.08028013524,22260.0,19410.0,26210.0,0.0,990.0 +58.0,37700.0,40900.0,0.08,0.05,67.0,85554.79503820783,15860.0,15360.0,16440.0,0.0,6760.0 +30.0,21300.0,13600.0,0.08,0.06,60.0,118087.10716489005,16460.0,14800.0,19410.0,1.0,0.0 +62.0,82400.0,392100.0,0.03,0.03,63.0,397700.3605605019,29100.0,28890.0,29300.0,0.0,12100.0 +60.0,102600.0,244000.0,0.05,0.06,68.0,308160.9101457433,27680.0,25650.0,29970.0,0.0,23620.0 +32.0,112700.0,111700.0,0.03,0.08,68.0,442556.5498610969,34740.0,23530.0,59850.0,0.0,21610.0 +49.0,43300.0,108700.0,0.08,0.05,67.0,250449.40277768605,24270.0,20800.0,29280.0,0.0,1710.0 +63.0,108300.0,253500.0,0.05,0.06,66.0,274575.35622032214,25090.0,24580.0,25610.0,0.0,29060.0 +45.0,105300.0,308900.0,0.05,0.05,68.0,569909.1058183714,41420.0,29630.0,61280.0,0.0,11230.0 +27.0,21800.0,5100.0,0.05,0.05,67.0,120066.89834323335,17620.0,15200.0,22720.0,1.0,0.0 +47.0,21300.0,59100.0,0.05,0.03,65.0,105528.57986970806,16560.0,15030.0,18800.0,1.0,0.0 +45.0,68900.0,47100.0,0.1,0.08,67.0,270018.30398513336,25270.0,21570.0,30850.0,0.0,9180.0 +34.0,35800.0,55200.0,0.05,0.03,65.0,203483.19181289137,21270.0,17210.0,29250.0,0.0,2720.0 +50.0,78900.0,96200.0,0.1,0.06,68.0,269435.15814546426,25640.0,22020.0,30810.0,0.0,13810.0 +39.0,105000.0,231100.0,0.05,0.03,60.0,409946.9979721559,28720.0,22460.0,38690.0,0.0,23780.0 +31.0,34200.0,39700.0,0.05,0.06,67.0,253153.19876296187,24410.0,18970.0,35930.0,1.0,0.0 +37.0,20600.0,15000.0,0.04,0.04,60.0,57647.54573597953,13920.0,13190.0,15070.0,0.0,500.0 +23.0,59100.0,13400.0,0.05,0.05,63.0,273086.4962525704,23580.0,18430.0,34680.0,0.0,11880.0 +52.0,18700.0,37000.0,0.05,0.04,67.0,66540.5387577323,14900.0,14070.0,16000.0,1.0,0.0 +51.0,35200.0,54100.0,0.08,0.03,65.0,118284.65534612376,17180.0,16010.0,18690.0,0.0,6400.0 +58.0,52200.0,157800.0,0.03,0.04,66.0,198882.343368209,21350.0,20110.0,22740.0,0.0,9970.0 +56.0,108400.0,149200.0,0.05,0.08,67.0,239394.35864352257,23710.0,21600.0,26260.0,0.0,30490.0 +59.0,64700.0,80400.0,0.05,0.05,67.0,124589.30346664289,17860.0,17130.0,18660.0,0.0,14490.0 +24.0,29200.0,3500.0,0.05,0.03,67.0,150580.70034861995,19180.0,16010.0,26110.0,0.0,380.0 +35.0,36100.0,43900.0,0.1,0.03,63.0,225737.17424938796,21490.0,18040.0,27560.0,0.0,2700.0 +24.0,24300.0,6900.0,0.1,0.08,65.0,251001.3231918755,23540.0,18760.0,33640.0,1.0,0.0 +29.0,27000.0,11900.0,0.1,0.03,63.0,166689.88510572742,18870.0,16240.0,23860.0,1.0,0.0 +59.0,72100.0,243900.0,0.08,0.04,67.0,311666.0144102141,27400.0,25410.0,29630.0,0.0,8650.0 +62.0,31000.0,125400.0,0.1,0.03,67.0,148366.72283322416,19070.0,18550.0,19610.0,0.0,1700.0 +22.0,75700.0,4200.0,0.08,0.06,67.0,418122.8890834578,32830.0,23210.0,54980.0,0.0,5020.0 +52.0,29200.0,54500.0,0.05,0.03,65.0,93159.03294998169,15970.0,15040.0,17160.0,0.0,3590.0 +41.0,32000.0,28800.0,0.05,0.04,63.0,108015.09408494408,16280.0,14900.0,18420.0,0.0,5160.0 +44.0,22500.0,43100.0,0.08,0.05,67.0,128398.6568350159,18050.0,15910.0,21490.0,1.0,0.0 +42.0,17600.0,7700.0,0.04,0.05,60.0,33426.95236283304,12900.0,12590.0,13340.0,1.0,0.0 +37.0,25300.0,13400.0,0.04,0.04,66.0,86932.10937235964,15810.0,14340.0,18400.0,0.0,1900.0 +37.0,64800.0,28700.0,0.05,0.06,65.0,213343.69406460205,21740.0,18330.0,27600.0,0.0,10660.0 +45.0,28400.0,10900.0,0.05,0.06,60.0,56885.525052093566,13890.0,13480.0,14410.0,0.0,5140.0 +50.0,76300.0,256400.0,0.05,0.06,63.0,376619.63808371476,28160.0,24420.0,32970.0,0.0,9990.0 +47.0,17700.0,45400.0,0.08,0.03,67.0,95431.8842928782,16360.0,14820.0,18730.0,1.0,0.0 +64.0,53400.0,67500.0,0.05,0.03,67.0,79790.25838524787,15570.0,15430.0,15720.0,0.0,16470.0 +49.0,37400.0,46600.0,0.05,0.08,66.0,144068.7544468748,18630.0,17000.0,20880.0,0.0,3810.0 +47.0,20000.0,39100.0,0.05,0.08,66.0,96134.12172881984,16260.0,14920.0,18230.0,1.0,0.0 +53.0,30900.0,56900.0,0.08,0.08,67.0,134215.5080186081,18340.0,16980.0,20100.0,0.0,2360.0 +38.0,25000.0,27200.0,0.05,0.08,65.0,136744.83454371904,18060.0,15870.0,21820.0,1.0,0.0 +25.0,34400.0,4800.0,0.1,0.03,66.0,271440.9030162813,24930.0,19650.0,35960.0,1.0,0.0 +46.0,48300.0,167200.0,0.05,0.06,60.0,278027.5378488417,23180.0,20460.0,26740.0,0.0,5800.0 +30.0,71600.0,47300.0,0.04,0.08,65.0,331926.265776082,27430.0,20750.0,41150.0,0.0,8370.0 +43.0,29000.0,90900.0,0.1,0.08,67.0,268347.3540436509,25180.0,20510.0,32970.0,1.0,0.0 +35.0,63800.0,66900.0,0.06,0.03,67.0,278909.64744761505,25730.0,19670.0,37810.0,0.0,6170.0 +27.0,26300.0,3800.0,0.08,0.03,66.0,154962.9787354396,19170.0,16260.0,25030.0,1.0,0.0 +31.0,94200.0,125600.0,0.05,0.03,67.0,404891.6290294317,32150.0,21630.0,56370.0,0.0,14950.0 +53.0,17000.0,23900.0,0.05,0.03,67.0,43677.517822745285,13730.0,13230.0,14370.0,1.0,0.0 +61.0,85900.0,63600.0,0.06,0.04,62.0,68439.18402360068,14530.0,14500.0,14560.0,0.0,28420.0 +64.0,38800.0,104600.0,0.05,0.08,67.0,120126.2305331523,17630.0,17410.0,17860.0,0.0,5650.0 +22.0,27500.0,1600.0,0.05,0.03,67.0,147083.63968852765,19000.0,15850.0,26060.0,1.0,0.0 +57.0,17700.0,13500.0,0.04,0.03,63.0,19435.029615268406,12360.0,12290.0,12430.0,0.0,30.0 +34.0,29100.0,7900.0,0.1,0.04,66.0,170329.33647228804,19930.0,17180.0,24800.0,1.0,0.0 +36.0,107600.0,61700.0,0.03,0.06,67.0,261163.93198642234,24820.0,19350.0,35450.0,0.0,28980.0 +44.0,19300.0,55700.0,0.06,0.05,66.0,122050.11906612795,17540.0,15450.0,20920.0,1.0,0.0 +56.0,80700.0,216600.0,0.03,0.05,60.0,238685.17442059625,21520.0,21000.0,22070.0,0.0,18830.0 +30.0,36700.0,13000.0,0.06,0.03,66.0,183127.8286441287,20560.0,17130.0,27350.0,0.0,4030.0 +49.0,73100.0,145800.0,0.08,0.06,67.0,317561.49040947267,27690.0,23150.0,34260.0,0.0,8860.0 +55.0,17500.0,62700.0,0.1,0.05,67.0,97474.83859418084,16470.0,15500.0,17690.0,1.0,0.0 +59.0,17900.0,25600.0,0.1,0.03,68.0,43567.75450086435,13790.0,13500.0,14120.0,1.0,0.0 +50.0,17700.0,41600.0,0.03,0.06,66.0,73301.19118190547,15130.0,14170.0,16460.0,1.0,0.0 +61.0,18000.0,40100.0,0.08,0.03,65.0,46875.32180342593,13750.0,13640.0,13870.0,1.0,0.0 +43.0,46500.0,50000.0,0.05,0.04,65.0,170833.29597511527,19700.0,17230.0,23550.0,0.0,8200.0 +42.0,37300.0,38200.0,0.04,0.03,67.0,132081.78501264262,18240.0,15940.0,22100.0,0.0,4140.0 +50.0,63700.0,191500.0,0.05,0.08,60.0,277831.88254161994,23170.0,21320.0,25360.0,0.0,8680.0 +62.0,46800.0,163500.0,0.05,0.03,66.0,182738.23991198614,20540.0,20080.0,21030.0,0.0,7540.0 +51.0,61300.0,133300.0,0.05,0.05,63.0,213742.44535034953,20960.0,19120.0,23250.0,0.0,15820.0 +38.0,103000.0,196100.0,0.04,0.08,68.0,526802.59714647,39160.0,26670.0,63910.0,0.0,12340.0 +41.0,46100.0,54100.0,0.05,0.04,65.0,190593.54728766906,20650.0,17650.0,25560.0,0.0,7010.0 +33.0,43100.0,60500.0,0.03,0.08,65.0,293516.6167456131,25590.0,19880.0,36790.0,0.0,270.0 +56.0,52800.0,216500.0,0.05,0.03,63.0,259447.14487967212,22980.0,21750.0,24340.0,0.0,8700.0 +25.0,45200.0,19700.0,0.05,0.05,67.0,299303.5006742012,26770.0,19890.0,42460.0,0.0,350.0 +36.0,35200.0,23100.0,0.03,0.03,67.0,119854.21533556786,17610.0,15280.0,22040.0,0.0,5970.0 +57.0,28300.0,83400.0,0.05,0.06,68.0,126645.99941353919,18150.0,16970.0,19570.0,0.0,810.0 +28.0,22600.0,7800.0,0.05,0.03,67.0,103811.7729356056,16790.0,14640.0,21370.0,1.0,0.0 +26.0,18200.0,11700.0,0.05,0.03,63.0,82862.20797383034,15170.0,13620.0,18480.0,1.0,0.0 +43.0,22300.0,22200.0,0.05,0.08,68.0,106224.08355888508,17070.0,15340.0,19920.0,1.0,0.0 +30.0,95500.0,99500.0,0.05,0.05,68.0,422293.73609333,33670.0,22610.0,59660.0,0.0,14080.0 +63.0,18600.0,86500.0,0.05,0.06,65.0,90542.48329801753,15850.0,15750.0,15940.0,1.0,0.0 +54.0,26000.0,93000.0,0.05,0.06,67.0,144716.54372967238,18880.0,17270.0,20940.0,1.0,0.0 +59.0,26300.0,32100.0,0.04,0.03,67.0,47355.38569887375,13920.0,13630.0,14230.0,0.0,4490.0 +49.0,96900.0,142300.0,0.08,0.04,66.0,284783.03908374714,25600.0,21770.0,31000.0,0.0,22850.0 +23.0,35900.0,1200.0,0.04,0.05,65.0,199544.28906251682,21080.0,17280.0,29040.0,0.0,2970.0 +26.0,48100.0,21100.0,0.05,0.05,68.0,306941.8878460856,27620.0,20280.0,44490.0,0.0,1240.0 +28.0,97500.0,65500.0,0.05,0.05,60.0,294582.0127442208,23870.0,18700.0,34130.0,0.0,24880.0 +30.0,19200.0,18300.0,0.05,0.05,67.0,116463.39506425028,17440.0,14890.0,22980.0,1.0,0.0 +28.0,21000.0,15300.0,0.08,0.04,66.0,145108.30467612005,18680.0,15720.0,25020.0,1.0,0.0 +57.0,111400.0,402500.0,0.05,0.03,67.0,495339.7589766419,36760.0,32400.0,41960.0,0.0,18940.0 +47.0,24100.0,71800.0,0.06,0.06,67.0,153939.27637232238,19350.0,16870.0,23130.0,1.0,0.0 +41.0,18800.0,48400.0,0.05,0.06,67.0,126131.97816058392,17930.0,15440.0,22360.0,1.0,0.0 +35.0,64200.0,29500.0,0.05,0.04,68.0,221876.39232221365,23150.0,18580.0,32020.0,0.0,8950.0 +37.0,95000.0,78700.0,0.05,0.08,60.0,269365.1775032862,22820.0,19220.0,28570.0,0.0,24680.0 +45.0,17200.0,57300.0,0.1,0.03,65.0,116192.87975552272,17080.0,15280.0,19830.0,1.0,0.0 +43.0,53100.0,54100.0,0.05,0.03,67.0,180681.65780220754,20710.0,17630.0,25800.0,0.0,11150.0 +25.0,83200.0,41600.0,0.05,0.03,66.0,289547.23486195056,25830.0,18870.0,42550.0,0.0,15770.0 +39.0,20700.0,23400.0,0.04,0.05,67.0,90935.63651057195,16140.0,14430.0,19220.0,1.0,0.0 +24.0,18200.0,3000.0,0.08,0.03,67.0,113014.82797726791,17260.0,14900.0,22450.0,1.0,0.0 +61.0,86000.0,442800.0,0.05,0.08,68.0,520075.2715973184,38810.0,35840.0,42080.0,0.0,4190.0 +40.0,17000.0,18100.0,0.1,0.03,66.0,80355.53836343021,15480.0,14170.0,17690.0,1.0,0.0 +37.0,20800.0,12300.0,0.08,0.03,65.0,85385.16942572875,15600.0,14270.0,17880.0,1.0,0.0 +33.0,30200.0,12200.0,0.05,0.04,65.0,126525.33722285987,17580.0,15450.0,21480.0,0.0,2650.0 +46.0,17500.0,14600.0,0.08,0.05,60.0,42208.52899001003,13270.0,12950.0,13690.0,1.0,0.0 +42.0,27800.0,49400.0,0.06,0.08,68.0,186052.87552590747,21270.0,17890.0,27060.0,1.0,0.0 +24.0,30600.0,9500.0,0.08,0.03,67.0,228550.14760906488,23160.0,18220.0,34260.0,1.0,0.0 +63.0,27500.0,22800.0,0.06,0.08,67.0,35791.78915345764,13330.0,13240.0,13410.0,0.0,5100.0 +48.0,58700.0,98400.0,0.1,0.03,63.0,216684.29539780773,21090.0,18930.0,23960.0,0.0,14130.0 +41.0,52000.0,89600.0,0.1,0.08,66.0,373019.25689535413,29960.0,23860.0,40100.0,0.0,1240.0 +57.0,67900.0,62600.0,0.05,0.06,67.0,121777.25895070231,17710.0,16850.0,18720.0,0.0,16240.0 +62.0,26300.0,91400.0,0.08,0.05,67.0,109504.95806114667,17080.0,16710.0,17490.0,0.0,1330.0 +59.0,22600.0,35900.0,0.05,0.06,67.0,54962.82514810894,14310.0,13980.0,14660.0,0.0,1510.0 +61.0,41100.0,59900.0,0.08,0.06,65.0,81998.32797822794,15440.0,15250.0,15630.0,0.0,9220.0 +30.0,26200.0,4200.0,0.05,0.03,67.0,106153.62696702639,16920.0,14910.0,20840.0,0.0,1420.0 +41.0,18400.0,36500.0,0.1,0.08,67.0,137828.06591578497,18530.0,16110.0,22680.0,1.0,0.0 +48.0,47500.0,77000.0,0.03,0.04,66.0,163381.23493278498,19590.0,17300.0,22890.0,0.0,8910.0 +33.0,19800.0,7300.0,0.05,0.03,67.0,72764.63931280316,15210.0,13840.0,17860.0,1.0,0.0 +42.0,30600.0,79800.0,0.03,0.03,68.0,176321.28255168296,20760.0,16930.0,27670.0,1.0,0.0 +47.0,106100.0,211800.0,0.1,0.08,67.0,472678.9915017758,35600.0,28050.0,47120.0,0.0,17450.0 +24.0,17500.0,4600.0,0.1,0.06,68.0,162604.21037984424,20030.0,16460.0,28060.0,1.0,0.0 +23.0,17100.0,4500.0,0.08,0.08,66.0,151563.24153775084,19000.0,15920.0,25800.0,1.0,0.0 +31.0,23300.0,27200.0,0.05,0.06,65.0,150870.05129466427,18740.0,15770.0,24790.0,1.0,0.0 +29.0,24100.0,11300.0,0.03,0.03,67.0,91038.20236258706,16140.0,14170.0,20420.0,0.0,730.0 +31.0,31800.0,27000.0,0.1,0.04,68.0,269313.94049697183,25640.0,19950.0,37460.0,1.0,0.0 +57.0,40500.0,122900.0,0.05,0.05,68.0,184594.13801184043,21190.0,19470.0,23280.0,0.0,3110.0 +59.0,18000.0,13700.0,0.05,0.05,67.0,25230.622897578018,12790.0,12660.0,12940.0,1.0,0.0 +51.0,22000.0,82900.0,0.05,0.06,67.0,139458.49215071826,18610.0,16690.0,21280.0,1.0,0.0 +46.0,82800.0,252800.0,0.04,0.06,60.0,377326.06053785904,27350.0,23470.0,32470.0,0.0,14050.0 +54.0,65800.0,139700.0,0.1,0.03,60.0,183549.81862176544,19210.0,18580.0,19890.0,0.0,13690.0 +43.0,60700.0,168300.0,0.03,0.06,63.0,322396.93024496036,25770.0,21010.0,33090.0,0.0,10650.0 +24.0,50500.0,13700.0,0.06,0.05,67.0,329687.7004345035,28320.0,20730.0,45680.0,0.0,1980.0 +59.0,18600.0,14300.0,0.08,0.08,63.0,22925.340345940363,12520.0,12470.0,12560.0,0.0,500.0 +27.0,19200.0,12800.0,0.08,0.04,67.0,136875.20426477073,18480.0,15510.0,25060.0,1.0,0.0 +61.0,38800.0,62200.0,0.05,0.03,68.0,86553.2389894065,16050.0,15590.0,16540.0,0.0,7230.0 +59.0,56700.0,75000.0,0.1,0.03,67.0,129494.72522575693,18100.0,17390.0,18900.0,0.0,15920.0 +31.0,54100.0,63300.0,0.03,0.08,68.0,363269.30409660056,30570.0,21860.0,49810.0,0.0,1890.0 +55.0,24000.0,14200.0,0.06,0.05,67.0,43429.94793764986,13710.0,13390.0,14120.0,0.0,3090.0 +31.0,31200.0,40700.0,0.06,0.05,67.0,236433.5288745989,23560.0,18390.0,34620.0,1.0,0.0 +28.0,19600.0,11200.0,0.03,0.05,60.0,73005.93555163896,14560.0,13420.0,16750.0,1.0,0.0 +41.0,20700.0,53000.0,0.04,0.03,68.0,122916.60212240872,17960.0,15230.0,22980.0,1.0,0.0 +48.0,23200.0,58000.0,0.05,0.06,65.0,114396.4910483467,16990.0,15500.0,19090.0,1.0,0.0 +30.0,17900.0,14800.0,0.03,0.04,63.0,69406.53128019118,14570.0,13310.0,17130.0,1.0,0.0 +54.0,19200.0,39200.0,0.05,0.04,68.0,67455.95878571314,15040.0,14240.0,16100.0,1.0,0.0 +61.0,30700.0,167700.0,0.06,0.03,67.0,192366.5813663743,21310.0,20450.0,22240.0,1.0,0.0 +54.0,28300.0,115700.0,0.1,0.03,67.0,182409.8796659144,20800.0,18790.0,23380.0,1.0,0.0 +46.0,111100.0,325800.0,0.08,0.06,63.0,540345.7570905497,35410.0,28380.0,45460.0,0.0,20140.0 +53.0,39600.0,74100.0,0.03,0.03,66.0,119129.71913577839,17400.0,16130.0,19020.0,0.0,6360.0 +55.0,95000.0,230800.0,0.03,0.04,67.0,312386.87772711314,27430.0,24070.0,31650.0,0.0,20070.0 +62.0,64400.0,312800.0,0.05,0.08,67.0,357493.13156613405,29730.0,28460.0,31070.0,0.0,2470.0 +63.0,19200.0,76100.0,0.08,0.06,66.0,83583.18774906539,15640.0,15490.0,15790.0,1.0,0.0 +40.0,18100.0,35900.0,0.08,0.06,66.0,117335.54096333888,17310.0,15220.0,20940.0,1.0,0.0 +57.0,40500.0,45000.0,0.06,0.08,63.0,77911.45447349832,14950.0,14700.0,15210.0,0.0,9350.0 +30.0,97300.0,17800.0,0.05,0.06,68.0,286314.15033471637,26530.0,20320.0,39460.0,0.0,22120.0 +62.0,30800.0,176400.0,0.03,0.03,67.0,192951.55628651782,21340.0,20640.0,22080.0,1.0,0.0 +37.0,18500.0,10100.0,0.05,0.05,66.0,69882.09674461959,14960.0,13800.0,17000.0,1.0,0.0 +56.0,19700.0,47000.0,0.04,0.06,63.0,60883.32429940311,14200.0,13910.0,14500.0,1.0,0.0 +42.0,35300.0,55000.0,0.06,0.04,67.0,182659.79112330018,20810.0,17610.0,26240.0,0.0,2840.0 +37.0,18200.0,20500.0,0.05,0.08,60.0,78701.74609894816,14800.0,13810.0,16380.0,1.0,0.0 +32.0,63700.0,12800.0,0.04,0.06,67.0,227730.39963182044,23120.0,18700.0,31630.0,0.0,8730.0 +60.0,26600.0,71800.0,0.1,0.03,65.0,89110.7958177191,15780.0,15490.0,16080.0,0.0,2840.0 +39.0,20500.0,33200.0,0.03,0.08,67.0,117675.0976579376,17500.0,15230.0,21640.0,1.0,0.0 +63.0,26800.0,86900.0,0.05,0.03,67.0,96814.31305375567,16440.0,16180.0,16700.0,0.0,2320.0 +35.0,42500.0,23900.0,0.06,0.06,67.0,245261.93974803318,24010.0,19550.0,32230.0,0.0,1490.0 +23.0,36800.0,7900.0,0.05,0.03,67.0,210279.5543671061,22220.0,17560.0,32900.0,0.0,2440.0 +29.0,90700.0,103100.0,0.04,0.08,66.0,461242.0712278472,34330.0,23350.0,59270.0,0.0,11020.0 +55.0,26000.0,27200.0,0.05,0.03,67.0,53701.92662290153,14240.0,13750.0,14840.0,0.0,3960.0 +43.0,20300.0,62300.0,0.1,0.08,60.0,134133.70298674767,17140.0,15660.0,19200.0,1.0,0.0 +40.0,17500.0,11200.0,0.1,0.03,67.0,75342.2418835067,15340.0,14140.0,17360.0,1.0,0.0 +24.0,92600.0,33200.0,0.04,0.03,67.0,262171.3521055522,24870.0,18220.0,41470.0,0.0,21430.0 +50.0,36900.0,113800.0,0.05,0.08,67.0,230269.9880917309,23240.0,20100.0,27690.0,0.0,1480.0 +43.0,96300.0,35900.0,0.05,0.05,67.0,178628.42852774946,20610.0,17840.0,25040.0,0.0,27540.0 +37.0,108900.0,106600.0,0.03,0.08,68.0,372261.59792401816,31040.0,22620.0,47740.0,0.0,23410.0 +62.0,42700.0,98600.0,0.1,0.04,68.0,136905.60156525526,18690.0,18120.0,19300.0,0.0,6930.0 +54.0,47000.0,155900.0,0.05,0.08,66.0,255379.8737669159,24140.0,21720.0,27150.0,0.0,4060.0 +27.0,27000.0,22000.0,0.05,0.06,63.0,175406.22471789303,19260.0,16120.0,25760.0,1.0,0.0 +47.0,22000.0,81600.0,0.04,0.03,68.0,144969.20104781134,19110.0,16360.0,23490.0,1.0,0.0 +27.0,27500.0,19300.0,0.08,0.04,67.0,216084.68070838106,22520.0,17840.0,32880.0,1.0,0.0 +43.0,71400.0,191700.0,0.03,0.03,68.0,369875.2889160289,30920.0,22710.0,45510.0,0.0,4780.0 +51.0,39600.0,151300.0,0.05,0.06,63.0,228705.97425174312,21620.0,19610.0,24130.0,0.0,2140.0 +63.0,17000.0,80300.0,0.04,0.06,67.0,87666.1030724118,15970.0,15740.0,16210.0,1.0,0.0 +38.0,97000.0,145900.0,0.06,0.08,67.0,461615.8812256066,35040.0,25280.0,53550.0,0.0,13460.0 +52.0,32200.0,87000.0,0.1,0.06,68.0,190677.34277038128,21510.0,19090.0,24820.0,0.0,60.0 +59.0,27100.0,55800.0,0.05,0.06,60.0,58494.53654381281,13960.0,13930.0,13980.0,0.0,4200.0 +31.0,18200.0,16500.0,0.05,0.06,60.0,84343.1802527014,15040.0,13780.0,17320.0,1.0,0.0 +42.0,26100.0,17100.0,0.04,0.06,60.0,66999.0228533058,14320.0,13670.0,15210.0,0.0,3950.0 +59.0,22400.0,35800.0,0.04,0.04,66.0,48344.99778651496,13890.0,13650.0,14160.0,0.0,1790.0 +60.0,96900.0,354100.0,0.05,0.08,61.0,362459.0272306809,26720.0,26550.0,26900.0,0.0,21730.0 +58.0,43500.0,102000.0,0.05,0.08,65.0,146137.67850184508,18520.0,17830.0,19270.0,0.0,7580.0 +37.0,31500.0,58900.0,0.04,0.05,66.0,192454.0408653747,21030.0,17190.0,28270.0,0.0,80.0 +59.0,38700.0,206200.0,0.05,0.03,67.0,249005.8777993203,24200.0,22570.0,26040.0,1.0,0.0 +58.0,20600.0,100300.0,0.05,0.05,63.0,112822.19482911902,16490.0,16140.0,16860.0,1.0,0.0 +60.0,75500.0,169100.0,0.05,0.03,67.0,208147.2241284025,22120.0,20990.0,23360.0,0.0,15630.0 +29.0,108100.0,78900.0,0.06,0.08,67.0,473766.37351130595,35660.0,24430.0,60980.0,0.0,18390.0 +61.0,17700.0,92100.0,0.05,0.08,67.0,107469.66144033038,16980.0,16510.0,17500.0,1.0,0.0 +34.0,20500.0,25400.0,0.03,0.04,66.0,93909.10766663417,16150.0,14160.0,20160.0,1.0,0.0 +54.0,74000.0,301000.0,0.1,0.08,68.0,489731.8403789926,37210.0,31170.0,45150.0,1.0,0.0 +55.0,107600.0,405600.0,0.08,0.03,67.0,541697.626494043,39130.0,33260.0,46480.0,0.0,14670.0 +42.0,55900.0,32200.0,0.08,0.04,67.0,206905.59043704314,22050.0,18860.0,27200.0,0.0,11490.0 +31.0,17400.0,4200.0,0.06,0.03,63.0,58207.77243145333,14070.0,13210.0,15630.0,1.0,0.0 +44.0,17900.0,46800.0,0.05,0.03,63.0,86008.78200807412,15310.0,14100.0,17120.0,1.0,0.0 +24.0,83200.0,15900.0,0.05,0.06,60.0,263254.38007078914,22560.0,18220.0,31150.0,0.0,19040.0 +29.0,94600.0,45300.0,0.06,0.03,60.0,233262.83286552996,21300.0,17440.0,28650.0,0.0,26000.0 +34.0,43500.0,38700.0,0.03,0.08,66.0,256818.52282288997,24210.0,19360.0,33450.0,0.0,1890.0 +39.0,23700.0,16100.0,0.1,0.03,60.0,84693.97607642844,15060.0,14160.0,16380.0,0.0,1530.0 +32.0,91300.0,101700.0,0.03,0.03,68.0,317705.9480082667,28180.0,19610.0,48000.0,0.0,17470.0 +54.0,18700.0,66500.0,0.03,0.03,60.0,75523.39743438295,14670.0,14390.0,14970.0,1.0,0.0 +26.0,28500.0,5200.0,0.05,0.05,65.0,158359.95507212568,19100.0,16180.0,25040.0,1.0,0.0 +26.0,94600.0,31700.0,0.05,0.05,68.0,330411.3009934961,28850.0,20680.0,48170.0,0.0,18450.0 +63.0,44400.0,41900.0,0.05,0.06,66.0,55686.71836309631,14260.0,14160.0,14350.0,0.0,12380.0 +48.0,73800.0,134800.0,0.05,0.08,67.0,305107.0473801703,27060.0,22480.0,33840.0,0.0,9840.0 +38.0,52900.0,36300.0,0.1,0.05,66.0,286366.2737318719,25670.0,20990.0,33680.0,0.0,6070.0 +48.0,47600.0,176200.0,0.03,0.03,63.0,263321.92160764115,23150.0,20060.0,27360.0,0.0,5410.0 +31.0,35200.0,10500.0,0.05,0.03,67.0,154231.44853947678,19360.0,16410.0,25210.0,0.0,4220.0 +22.0,66600.0,1300.0,0.05,0.06,65.0,303162.338275267,26050.0,19790.0,39750.0,0.0,7250.0 +39.0,35100.0,12100.0,0.08,0.04,67.0,158022.97545408382,19560.0,17150.0,23550.0,0.0,3960.0 +35.0,54500.0,95900.0,0.05,0.03,67.0,311097.5429041826,27360.0,20160.0,42170.0,0.0,5340.0 +32.0,17200.0,6000.0,0.05,0.03,66.0,59671.578041383436,14450.0,13370.0,16560.0,1.0,0.0 +28.0,26000.0,8300.0,0.05,0.06,68.0,168158.67722976653,20330.0,16780.0,27850.0,1.0,0.0 +28.0,17100.0,7000.0,0.05,0.06,60.0,72820.13569515747,14560.0,13500.0,16500.0,1.0,0.0 +28.0,36900.0,17900.0,0.04,0.03,67.0,175825.44258387538,20460.0,16650.0,28790.0,0.0,4260.0 +26.0,31100.0,5700.0,0.05,0.03,67.0,154514.7085425709,19380.0,16200.0,26190.0,0.0,1460.0 +33.0,51500.0,39900.0,0.05,0.04,63.0,216213.4399463777,21060.0,17460.0,27740.0,0.0,9840.0 +34.0,67200.0,94900.0,0.05,0.05,66.0,345563.594850862,28600.0,21080.0,43860.0,0.0,5000.0 +59.0,61400.0,213300.0,0.08,0.03,60.0,219715.28330400956,20730.0,20620.0,20830.0,0.0,16110.0 +28.0,33600.0,11600.0,0.05,0.03,67.0,167443.75113158938,20040.0,16580.0,27370.0,0.0,2470.0 +27.0,18100.0,5000.0,0.06,0.08,67.0,129404.3534627054,18100.0,15510.0,23500.0,1.0,0.0 +32.0,89600.0,98900.0,0.06,0.03,68.0,376145.96366949833,31250.0,21630.0,52930.0,0.0,13550.0 +32.0,17700.0,12400.0,0.04,0.03,65.0,64472.31755965376,14600.0,13350.0,17080.0,1.0,0.0 +34.0,22000.0,13700.0,0.05,0.05,67.0,106270.47024437264,16920.0,14900.0,20810.0,1.0,0.0 +51.0,17300.0,29300.0,0.06,0.04,66.0,56688.9585690922,14300.0,13650.0,15190.0,1.0,0.0 +43.0,19500.0,25800.0,0.04,0.03,67.0,69124.80787127832,15020.0,13780.0,17110.0,1.0,0.0 +62.0,90600.0,369100.0,0.05,0.03,68.0,414448.3250801179,33260.0,31330.0,35340.0,0.0,12040.0 +40.0,83300.0,69900.0,0.05,0.08,67.0,298844.949077009,26740.0,21310.0,36220.0,0.0,14910.0 +33.0,32900.0,36300.0,0.05,0.06,65.0,205768.46229200912,21380.0,17570.0,28740.0,0.0,660.0 +57.0,92200.0,340500.0,0.08,0.03,63.0,392021.5400540837,28850.0,27330.0,30490.0,0.0,17250.0 +58.0,64600.0,304500.0,0.05,0.05,60.0,317900.3071676249,24850.0,24550.0,25160.0,0.0,7450.0 diff --git a/crates/watershed-xlsx/README.md b/crates/watershed-xlsx/README.md index 4c535f8..da6898d 100644 --- a/crates/watershed-xlsx/README.md +++ b/crates/watershed-xlsx/README.md @@ -31,7 +31,9 @@ out one loan's expected credit loss, run for a whole loan book. `audit` tries a workbook over the whole of its inputs' ranges, and against a later version of itself. `sensitivities` asks the graph for an answer's derivative by hundreds of the workbook's cells at once. `quotes` works out -every price a rating workbook can give. +every price a rating workbook can give. `illustrations` works out a pension +statement for every member of a scheme, and then seeks, member by member, +the contribution that would put them on track. A workbook's graph can also be kept up to date as its inputs change, with no plan at all. The `live` example here follows a price feed with a risk