| Crates.io | tktax-money |
| lib.rs | tktax-money |
| version | 0.2.2 |
| created_at | 2025-02-01 01:39:45.175491+00 |
| updated_at | 2025-02-01 01:39:45.175491+00 |
| description | Statistical and algebraic operations on monetary amounts for the tktax project |
| homepage | |
| repository | https://github.com/klebs6/tktax |
| max_upload_size | |
| id | 1537990 |
| size | 126,510 |
A specialized Rust library for advanced monetary computations in taxation and financial analysis.
It integrates sophisticated mathematical and statistical routines (e.g. mean, median, standard deviation, skewness, kurtosis, correlation, linear regression) tailored to currency-valued data types.
rust_decimal::Decimal, preventing floating-point anomalies.BasicStats): mean, median, standard deviation, repeated-value detection, min/max, midrange.AdvancedMoneyStats): quartiles, IQR-based outlier detection, variance, skewness (ἔγκλισις), kurtosis (κύρτωσις), cumulative frequency.Add this to your Cargo.toml:
[dependencies]
tktax-money = { git = "https://github.com/klebs6/tktax", subdir = "tktax-money" }
Example for basic stats:
// Suppose you already have a slice of MonetaryAmount named `amounts`:
match amounts.mean() {
Ok(avg) => println!("Average transaction amount: {}", avg),
Err(e) => eprintln!("Error computing mean: {:?}", e),
}
// Finding repeated values (duplicates above count=1):
if let Ok(repeats) = amounts.repeated_values() {
for (val, count) in repeats {
println!("{} repeats {} times", val, count);
}
}
Advanced analytics example (quartiles, outliers):
// quartiles_iqr => (q1, median, q3, iqr)
if let Ok((q1, median, q3, iqr)) = amounts.quartiles_iqr() {
println!("Q1 = {}, Median = {}, Q3 = {}, IQR = {}", q1, median, q3, iqr);
// Outlier detection
if let Ok(outliers) = amounts.outliers_iqr() {
println!("Found {} outliers", outliers.len());
}
}
Dimensionless correlation:
// correlation => dimensionless measure of linear association
let x_data = vec![MonetaryAmount::from(1), MonetaryAmount::from(2)];
let y_data = vec![MonetaryAmount::from(2), MonetaryAmount::from(4)];
let corr = x_data.as_slice().correlation(&y_data);
println!("Correlation: {:?}", corr);
For more examples, review the tests within this crate (cargo test).
Licensed under either of:
at your option. See LICENSE for details.