finance-solution 0.0.0

A library for finance time-value-of-money functions with detailed solutions and pretty-printed tables.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#![allow(unused_imports)]

//! The internal module which supports the solution struct for the Cashflow family of functions (e.g., `payment`).

// use std::fmt::Debug;
use std::fmt;
// use colored::*;

// Import needed for the function references in the Rustdoc comments.
use crate::*;
use std::cmp::max;
use std::ops::Deref;

pub mod future_value_annuity;
#[doc(inline)]
pub use future_value_annuity::*;

pub mod payment;
#[doc(inline)]
pub use payment::*;

pub mod present_value_annuity;
#[doc(inline)]
pub use present_value_annuity::*;

pub mod net_present_value;
#[doc(inline)]
pub use net_present_value::*;

pub mod nper;
#[doc(inline)]
pub use nper::*;

#[derive(Debug, Clone)]
pub enum CashflowVariable {
    PresentValueAnnuity,
    PresentValueAnnuityDue,
    FutureValueAnnuity,
    Payment,
    FutureValueAnnuityDue,
    NetPresentValue,
}

impl CashflowVariable {
    /// Returns true if the variant is CashflowVariable::PresentValueAnnuity indicating that the
    /// solution was created by calculating the present value of an annuity with the payment due at
    /// the end of the month.
    pub fn is_present_value_annuity(&self) -> bool {
        match self {
            CashflowVariable::PresentValueAnnuity => true,
            _ => false,
        }
    }

    /// Returns true if the variant is CashflowVariable::FutureValueAnnuity indicating that the
    /// solution was created by calculating the future value of an annuity with the payment due at
    /// the end of the month.
    pub fn is_future_value_annuity(&self) -> bool {
        match self {
            CashflowVariable::FutureValueAnnuity => true,
            _ => false,
        }
    }

    /// Returns true if the variant is CashflowVariable::Payment indicating that the solution
    /// was created in a call to [`payment_solution`].
    pub fn is_payment(&self) -> bool {
        match self {
            CashflowVariable::Payment => true,
            _ => false,
        }
    }

    /// Returns true if the variant is CashflowVariable::PresentValueAnnuityDue indicating that
    /// the solution was created by calculating the present value of an annuity with the payment due
    /// at the beginning of the month.
    pub fn is_present_value_annuity_due(&self) -> bool {
        match self {
            CashflowVariable::PresentValueAnnuityDue => true,
            _ => false,
        }
    }

    /// Returns true if the variant is CashflowVariable::FutureValueAnnuityDue indicating that
    /// the solution was created by calculating the future value of an annuity with the payment due
    /// at the beginning of the month.
    pub fn is_future_value_annuity_due(&self) -> bool {
        match self {
            CashflowVariable::FutureValueAnnuityDue => true,
            _ => false,
        }
    }

    /// Returns true if the variant is CashflowVariable::NetPresentValue indicating that the
    /// solution was created by calculating a net present value.
    pub fn is_net_present_value(&self) -> bool {
        match self {
            CashflowVariable::NetPresentValue => true,
            _ => false,
        }
    }
}

impl fmt::Display for CashflowVariable {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            CashflowVariable::PresentValueAnnuity => write!(f, "Present Value Annuity"),
            CashflowVariable::FutureValueAnnuity => write!(f, "Future Value Annuity"),
            CashflowVariable::Payment => write!(f, "Payment"),
            CashflowVariable::PresentValueAnnuityDue => write!(f, "Present Value Annuity Due"),
            CashflowVariable::FutureValueAnnuityDue => write!(f, "Future Value Annuity Due"),
            CashflowVariable::NetPresentValue => write!(f, "Net Present Value"),
        }
    }
}

/// A record of a cash flow calculation such as payment, net present value, or the present value or
/// future value of an annuity.
#[derive(Clone, Debug)]
pub struct CashflowSolution {
    calculated_field: CashflowVariable,
    rate: f64,
    periods: u32,
    present_value: f64,
    future_value: f64,
    due_at_beginning: bool,
    payment: f64,
    sum_of_payments: f64,
    sum_of_interest: f64,
    formula: String,
    symbolic_formula: String,
    // pub input_in_percent: String,
}

impl CashflowSolution {
    pub(crate) fn new(
        calculated_field: CashflowVariable,
        rate: f64,
        periods: u32,
        present_value: f64,
        future_value: f64,
        due_at_beginning: bool,
        payment: f64,
        formula: &str,
        symbolic_formula: &str,
    ) -> Self {
        assert!(!formula.is_empty());
        let sum_of_payments = payment * periods as f64;
        let sum_of_interest = sum_of_payments + present_value + future_value;
        Self {
            calculated_field,
            rate,
            periods,
            present_value,
            future_value,
            due_at_beginning,
            payment,
            sum_of_payments,
            sum_of_interest,
            formula: formula.to_string(),
            symbolic_formula: symbolic_formula.to_string(),
        }
    }

    pub fn calculated_field(&self) -> &CashflowVariable {
        &self.calculated_field
    }

    pub fn rate(&self) -> f64 {
        self.rate
    }

    pub fn periods(&self) -> u32 {
        self.periods
    }

    pub fn present_value(&self) -> f64 {
        self.present_value
    }

    pub fn future_value(&self) -> f64 {
        self.future_value
    }

    pub fn due_at_beginning(&self) -> bool {
        self.due_at_beginning
    }

    pub fn payment(&self) -> f64 {
        self.payment
    }

    pub fn sum_of_payments(&self) -> f64 {
        self.sum_of_payments
    }

    pub fn sum_of_interest(&self) -> f64 {
        self.sum_of_interest
    }

    pub fn formula(&self) -> &str {
        &self.formula
    }

    pub fn symbolic_formula(&self) -> &str {
        &self.symbolic_formula
    }

}

/*
impl Debug for CashflowSolution {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{{{}{}{}{}{}{}{}{}{}{}{}\n}}",
               &format!("\n\tcalculated_field: {}", self.calculated_field.to_string().magenta()),
               &format!("\n\trate (r): {}", format!("{:?}", self.rate).yellow()),
               &format!("\n\tperiods (n): {}", self.periods.to_string().yellow()),
               &format!("\n\tpresent_value (pv): {}", self.present_value),
               &format!("\n\tfuture_value (fv): {}", self.future_value),
               &format!("\n\tdue_at_beginning: {}", self.due_at_beginning),
               //    if self.calculated_field.is_net_present_value() { format!("\n\tcashflow: {}", self.cashflow.to_string().red()) } else { "".to_string() },
               //    if self.calculated_field.is_net_present_value() { format!("\n\tcashflow_0: {}", self.cashflow_0.to_string().red()) } else { "".to_string() },
               &format!("\n\tpayment (pmt): {}", if self.calculated_field.is_payment() || self.calculated_field.is_payment_due() { self.payment.to_string().green() } else { self.payment.to_string().normal() }),
               &format!("\n\tsum_of_payments: {}", self.sum_of_payments),
               &format!("\n\tsum_of_interest: {}", self.sum_of_interest),
               &format!("\n\tformula: {:?}", self.formula),
               &format!("\n\tsymbolic_formula: {:?}", self.symbolic_formula),
               // &format!("input_in_percent: {:.6}%", self.input_in_percent),
               // &format!("output: {}", self.output.to_string().green()),
        )
    }
}
*/

#[derive(Clone, Debug)]
pub struct CashflowSeries(Vec<CashflowPeriod>);

impl CashflowSeries {
    pub(crate) fn new(series: Vec<CashflowPeriod>) -> Self {
        Self {
            0: series,
        }
    }

    pub fn filter<P>(&self, predicate: P) -> Self
        where P: Fn(&&CashflowPeriod) -> bool
    {
        Self {
            0: self.iter().filter(|x| predicate(x)).cloned().collect()
        }
    }

    pub fn print_table(
        &self,
        include_running_totals: bool,
        include_remaining_amounts: bool)
    {
        self.print_table_locale_opt(include_running_totals, include_remaining_amounts, None, None);
    }

    pub fn print_table_locale(
        &self,
        include_running_totals: bool,
        include_remaining_amounts: bool,
        locale: &num_format::Locale,
        precision: usize) {
        self.print_table_locale_opt(include_running_totals, include_remaining_amounts, Some(locale), Some(precision));
    }

    fn print_table_locale_opt(
        &self,
        include_running_totals: bool,
        include_remaining_amounts: bool,
        locale: Option<&num_format::Locale>,
        precision: Option<usize>)
    {
        let columns = columns_with_strings(&[
            ("period", "i", true),
            ("payments_to_date", "f", include_running_totals), ("payments_remaining", "f", include_remaining_amounts),
            ("principal", "f", true), ("principal_to_date", "f", include_running_totals), ("principal_remaining", "f", include_remaining_amounts),
            ("interest", "f", true), ("interest_to_date", "f", include_running_totals), ("interest_remaining", "f", include_remaining_amounts)]);
        let data = self.iter()
            .map(|entry| vec![entry.period.to_string(), entry.payments_to_date.to_string(), entry.payments_remaining.to_string(),
                              entry.principal.to_string(), entry.principal_to_date.to_string(), entry.principal_remaining.to_string(),
                              entry.interest.to_string(), entry.interest_to_date.to_string(), entry.interest_remaining.to_string()])
            .collect::<Vec<_>>();
        print_table_locale_opt(&columns, data, locale, precision);
    }

    pub fn print_ab_comparison(
        &self,
        other: &CashflowSeries,
        include_running_totals: bool,
        include_remaining_amounts: bool)
    {
        self.print_ab_comparison_locale_opt(other, include_running_totals, include_remaining_amounts, None, None);
    }

    pub fn print_ab_comparison_locale(
            &self,
            other: &CashflowSeries,
            include_running_totals: bool,
            include_remaining_amounts: bool,
            locale: &num_format::Locale,
            precision: usize) {
        self.print_ab_comparison_locale_opt(other, include_running_totals, include_remaining_amounts, Some(locale), Some(precision));
    }

    pub(crate) fn print_ab_comparison_locale_opt(
            &self,
            other: &CashflowSeries,
            include_running_totals: bool,
            include_remaining_amounts: bool,
            locale: Option<&num_format::Locale>,
            precision: Option<usize>) {
        let columns = columns_with_strings(&[("period", "i", true),
                           ("payment_a", "f", true), ("payment_b", "f", true),
                           ("pmt_to_date_a", "f", include_running_totals), ("pmt_to_date_b", "f", include_running_totals),
            // ("pmt_remaining_a", "f", include_remaining_amounts), ("pmt_remaining_b", "f", include_remaining_amounts),
            ("pmt_remaining_a", "f", false), ("pmt_remaining_b", "f", false),
                           ("principal_a", "f", true), ("principal_b", "f", true),
                           ("princ_to_date_a", "f", include_running_totals), ("princ_to_date_b", "f", include_running_totals),
                           ("princ_remaining_a", "f", include_remaining_amounts), ("princ_remaining_b", "f", include_remaining_amounts),
                           ("interest_a", "f", false), ("interest_b", "f", false),
                           ("int_to_date_a", "f", include_running_totals), ("int_to_date_b", "f", include_running_totals),
                           ("int_remaining_a", "f", false), ("int_remaining_b", "f", false)]);
        let mut data = vec![];
        let rows = max(self.len(), other.len());
        for row_index in 0..rows {
            data.push(vec![
                (row_index + 1).to_string(),
                self.get(row_index).map_or("".to_string(), |x| x.payment.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.payment.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.payments_to_date.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.payments_to_date.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.payments_remaining.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.payments_remaining.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.principal.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.principal.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.principal_to_date.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.principal_to_date.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.principal_remaining.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.principal_remaining.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.interest.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.interest.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.interest_to_date.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.interest_to_date.to_string()),
                self.get(row_index).map_or("".to_string(), |x| x.interest_remaining.to_string()),
                other.get(row_index).map_or("".to_string(), |x| x.interest_remaining.to_string()),
            ]);
        }
        print_table_locale_opt(&columns, data, locale, precision);
    }

}

impl Deref for CashflowSeries {
    type Target = Vec<CashflowPeriod>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Clone, Debug)]
pub struct CashflowPeriod {
    period: u32,
    rate: f64,
    due_at_beginning: bool,
    // pub cashflow: f64,
    // pub cashflow_0: f64,
    payment: f64,
    payments_to_date: f64,
    payments_remaining: f64,
    principal: f64,
    principal_to_date: f64,
    principal_remaining: f64,
    interest: f64,
    interest_to_date: f64,
    interest_remaining: f64,
    formula: String,
    symbolic_formula: String,
    // pub input_in_percent: String,
}

impl CashflowPeriod {
    pub(crate) fn new(
        period: u32,
        rate: f64,
        due_at_beginning: bool,
        payment: f64,
        payments_to_date: f64,
        payments_remaining: f64,
        principal: f64,
        principal_to_date: f64,
        principal_remaining: f64,
        interest: f64,
        interest_to_date: f64,
        interest_remaining: f64,
        formula: String,
        symbolic_formula: String,
    ) -> Self {
        Self {
            period,
            rate,
            due_at_beginning,
            payment,
            payments_to_date,
            payments_remaining,
            principal,
            principal_to_date,
            principal_remaining,
            interest,
            interest_to_date,
            interest_remaining,
            formula,
            symbolic_formula,
        }
    }

    pub fn rate(&self) -> f64 {
        self.rate
    }

    pub fn period(&self) -> u32 {
        self.period
    }

    pub fn payment(&self) -> f64 {
        self.payment
    }

    pub fn payments_to_date(&self) -> f64 {
        self.payments_to_date
    }

    pub fn payments_remaining(&self) -> f64 {
        self.payments_remaining
    }

    pub fn principal(&self) -> f64 {
        self.principal
    }

    pub fn principal_to_date(&self) -> f64 {
        self.principal_to_date
    }

    pub fn principal_remaining(&self) -> f64 {
        self.principal_remaining
    }

    pub fn interest(&self) -> f64 {
        self.interest
    }

    pub fn interest_to_date(&self) -> f64 {
        self.interest_to_date
    }

    pub fn interest_remaining(&self) -> f64 {
        self.interest_remaining
    }

    pub fn due_at_beginning(&self) -> bool {
        self.due_at_beginning
    }

    pub fn formula(&self) -> &str {
        &self.formula
    }

    pub fn symbolic_formula(&self) -> &str {
        &self.symbolic_formula
    }

    pub fn print_flat(&self, precision: usize) {
        println!("CashflowPeriod = {{ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }}",
                 &format!("period: {}", self.period),
                 &format!("due_at_beginning: {}", self.due_at_beginning),
                 &format!("payment: {:.prec$}", self.payment, prec = precision),
                 &format!("payments_to_date: {:.prec$}", self.payments_to_date, prec = precision),
                 &format!("payments_remaining: {:.prec$}", self.payments_remaining, prec = precision),
                 &format!("principal: {:.prec$}", self.principal, prec = precision),
                 &format!("principal_to_date: {:.prec$}", self.principal_to_date, prec = precision),
                 &format!("principal_remaining: {:.prec$}", self.principal_remaining, prec = precision),
                 &format!("interest: {:.prec$}", self.interest, prec = precision),
                 &format!("interest_to_date: {:.prec$}", self.interest_to_date, prec = precision),
                 &format!("interest_remaining: {:.prec$}", self.interest_remaining, prec = precision),
                 &format!("formula: {:?}", self.formula),
                 &format!("symbolic_formula: {:?}", self.symbolic_formula));
    }
}

// pub fn print_series_filtered(series: &[TvmPeriod], filter: )

/*
pub fn print_series_table(series: &[CashflowPeriod], precision: usize) {
    if series.len() == 0 {
        return;
    }
    let period_width = max("period".len(), series.iter().map(|x| x.period().to_string().len()).max().unwrap());
    let payments_to_date_width = max("payments_to_date".len(), series.iter().map(|x| format!("{:.prec$}", x.payments_to_date(), prec = precision).len()).max().unwrap());
    let payments_remaining_width = max("payments_remaining".len(), series.iter().map(|x| format!("{:.prec$}", x.payments_remaining(), prec = precision).len()).max().unwrap());
    let principal_width = max("principal_width".len(), series.iter().map(|x| format!("{:.prec$}", x.principal(), prec = precision).len()).max().unwrap());
    let principal_to_date_width = max("principal_to_date".len(), series.iter().map(|x| format!("{:.prec$}", x.principal_to_date(), prec = precision).len()).max().unwrap());
    let principal_remaining_width = max("principal_remaining".len(), series.iter().map(|x| format!("{:.prec$}", x.principal_remaining(), prec = precision).len()).max().unwrap());
    let interest_width = max("interest".len(), series.iter().map(|x| format!("{:.prec$}", x.interest(), prec = precision).len()).max().unwrap());
    let interest_to_date_width = max("interest_to_date".len(), series.iter().map(|x| format!("{:.prec$}", x.interest_to_date(), prec = precision).len()).max().unwrap());
    let interest_remaining_width = max("interest_remaining".len(), series.iter().map(|x| format!("{:.prec$}", x.interest_remaining(), prec = precision).len()).max().unwrap());
    println!("\ndue_at_beginning: {}", series[0].due_at_beginning);
    println!("payment: {:.prec$}", series[0].payment, prec = precision);
    println!("{:>pe$}  {:>pmtd$}  {:>pmr$}  {:>pr$}  {:>prtd$}  {:>prr$}  {:>i$}  {:>itd$}  {:>ir$}",
             "period", "payments_to_date", "payments_remaining", "principal", "principal_to_date", "principal_remaining", "interest", "interest_to_date", "interest_remaining",
             pe = period_width, pmtd = payments_to_date_width, pmr = payments_remaining_width,
             pr = principal_width, prtd = principal_to_date_width, prr = principal_remaining_width,
             i = interest_width, itd = interest_to_date_width, ir = interest_remaining_width);
    println!("{}  {}  {}  {}  {}  {}  {}  {}  {}",
             "-".repeat(period_width), "-".repeat(payments_to_date_width), "-".repeat(payments_remaining_width),
             "-".repeat(principal_width), "-".repeat(principal_to_date_width), "-".repeat(principal_remaining_width),
             "-".repeat(interest_width), "-".repeat(interest_to_date_width), "-".repeat(interest_remaining_width));
    for entry in series.iter() {
        println!("{:>pe$}  {:>pmtd$.prec$}  {:>pmr$.prec$}  {:>pr$.prec$}  {:>prtd$.prec$}  {:>prr$.prec$}  {:>i$.prec$}  {:>itd$.prec$}  {:>ir$.prec$}",
                 entry.period(), entry.payments_to_date(), entry.payments_remaining(),
                 entry.principal(), entry.principal_to_date(), entry.principal_remaining(),
                 entry.interest(), entry.interest_to_date(), entry.interest_remaining(),
                 pe = period_width, pmtd = payments_to_date_width, pmr = payments_remaining_width,
                 pr = principal_width, prtd = principal_to_date_width, prr = principal_remaining_width,
                 i = interest_width, itd = interest_to_date_width, ir = interest_remaining_width, prec = precision);
    }
}
*/

/*
pub fn print_series_table_locale(series: &[CashflowPeriod], locale: &num_format::Locale, precision: usize) {
    if series.len() == 0 {
        return;
    }
    let period_width = max("period".len(), series.iter().map(|x| format_int_locale(x.period(), locale).len()).max().unwrap());
    let payments_to_date_width = max("payments_to_date".len(), series.iter().map(|x| format_float_locale(x.payments_to_date(), locale, precision).len()).max().unwrap());
    let payments_remaining_width = max("payments_remaining".len(), series.iter().map(|x| format_float_locale(x.payments_remaining(), locale, precision).len()).max().unwrap());
    let principal_width = max("principal".len(), series.iter().map(|x| format_float_locale(x.principal(), locale, precision).len()).max().unwrap());
    let principal_to_date_width = max("principal_to_date".len(), series.iter().map(|x| format_float_locale(x.principal_to_date(), locale, precision).len()).max().unwrap());
    let principal_remaining_width = max("principal_remaining".len(), series.iter().map(|x| format_float_locale(x.principal_remaining(), locale, precision).len()).max().unwrap());
    let interest_width = max("interest".len(), series.iter().map(|x| format_float_locale(x.interest(), locale, precision).len()).max().unwrap());
    let interest_to_date_width = max("interest_to_date".len(), series.iter().map(|x| format_float_locale(x.interest_to_date(), locale, precision).len()).max().unwrap());
    let interest_remaining_width = max("interest_remaining".len(), series.iter().map(|x| format_float_locale(x.interest_remaining(), locale, precision).len()).max().unwrap());
    println!("\ndue_at_beginning: {}", series[0].due_at_beginning);
    println!("payment: {:.prec$}", series[0].payment, prec = precision);
    println!("{:>pe$}  {:>pmtd$}  {:>pmr$}  {:>pr$}  {:>prtd$}  {:>prr$}  {:>i$}  {:>itd$}  {:>ir$}",
             "period", "payments_to_date", "payments_remaining", "principal", "principal_to_date", "principal_remaining", "interest", "interest_to_date", "interest_remaining",
             pe = period_width, pmtd = payments_to_date_width, pmr = payments_remaining_width,
             pr = principal_width, prtd = principal_to_date_width, prr = principal_remaining_width,
             i = interest_width, itd = interest_to_date_width, ir = interest_remaining_width);
    println!("{}  {}  {}  {}  {}  {}  {}  {}  {}",
             "-".repeat(period_width), "-".repeat(payments_to_date_width), "-".repeat(payments_remaining_width),
             "-".repeat(principal_width), "-".repeat(principal_to_date_width), "-".repeat(principal_remaining_width),
             "-".repeat(interest_width), "-".repeat(interest_to_date_width), "-".repeat(interest_remaining_width));
    for entry in series.iter() {
        println!("{:>pe$}  {:>pmtd$}  {:>pmr$}  {:>pr$}  {:>prtd$}  {:>prr$}  {:>i$}  {:>itd$}  {:>ir$}",
                 format_int_locale(entry.period(), locale), format_float_locale(entry.payments_to_date(), locale, precision), format_float_locale(entry.payments_remaining(), locale, precision),
                 format_float_locale(entry.principal(), locale, precision), format_float_locale(entry.principal_to_date(), locale, precision), format_float_locale(entry.principal_remaining(), locale, precision),
                 format_float_locale(entry.interest(), locale, precision), format_float_locale(entry.interest_to_date(), locale, precision), format_float_locale(entry.interest_remaining(), locale, precision),
                 pe = period_width, pmtd = payments_to_date_width, pmr = payments_remaining_width,
                 pr = principal_width, prtd = principal_to_date_width, prr = principal_remaining_width,
                 i = interest_width, itd = interest_to_date_width, ir = interest_remaining_width);
    }
}
*/

/*
pub fn print_series_table_filtered(series: &[CashflowPeriod], predicate: P, precision: usize)
    where P: FnMut(&CashflowPeriod) -> bool
{
}
*/