pub struct PeriodicSavingsNeeded {
pub future_value: f64,
pub interest_rate: f64,
pub time_periods: f64,
}
Expand description
Calculates the periodic investments required to accumulate a future value
§Examples
use com_croftsoft_core::math::finance_lib::PeriodicSavingsNeeded;
assert_eq!(
PeriodicSavingsNeeded {
future_value: 1_000_000.0, // To have a million dollars in the future
interest_rate: 0.12, // At 12% interest compounded annually
time_periods: 10.0, // Investing each year for ten years
}.calculate(),
56_984.164_159_844_026); // Invest ~$57k per year
assert_eq!(
PeriodicSavingsNeeded {
future_value: 100_000_000.0, // To have a hundred million cents
interest_rate: 0.01, // At 1% interest compounded monthly
time_periods: 120.0, // Investing each month for 120 months
}.calculate(),
434_709.484_025_873_1); // Invest ~435k cents per month (~$52k per year)
let mut calculated_values = [0.0; 12];
let mut periodic_savings_needed = PeriodicSavingsNeeded {
future_value: 1_000_000.0,
interest_rate: 0.00,
time_periods: 10.0,
};
for index in 0..12 {
periodic_savings_needed.interest_rate = (index + 1) as f64 / 100.0;
calculated_values[index] = periodic_savings_needed.calculate();
}
assert_eq!(calculated_values[ 0], 95_582.076_551_171_35 ); // @ 1%
assert_eq!(calculated_values[ 4], 79_504.574_965_456_62 ); // @ 5%
assert_eq!(calculated_values[ 7], 69_029.488_697_075_34 ); // @ 8%
assert_eq!(calculated_values[11], 56_984.164_159_844_026); // @ 12%
Fields§
§future_value: f64
Future value desired
interest_rate: f64
Periodic interest rate (use 0.01 for 1%)
time_periods: f64
Number of time periods of investment
Implementations§
Trait Implementations§
Source§impl Clone for PeriodicSavingsNeeded
impl Clone for PeriodicSavingsNeeded
Source§fn clone(&self) -> PeriodicSavingsNeeded
fn clone(&self) -> PeriodicSavingsNeeded
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PeriodicSavingsNeeded
impl Debug for PeriodicSavingsNeeded
impl Copy for PeriodicSavingsNeeded
Auto Trait Implementations§
impl Freeze for PeriodicSavingsNeeded
impl RefUnwindSafe for PeriodicSavingsNeeded
impl Send for PeriodicSavingsNeeded
impl Sync for PeriodicSavingsNeeded
impl Unpin for PeriodicSavingsNeeded
impl UnwindSafe for PeriodicSavingsNeeded
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more