Struct PeriodicSavingsNeeded

Source
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

Source§

fn clone(&self) -> PeriodicSavingsNeeded

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PeriodicSavingsNeeded

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for PeriodicSavingsNeeded

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.