public static decimal TotalInflatedValue <T>(this IEnumerable <T> self, IInflation inflation, DateTime at) where T : Money { return(self .Select(item => item.GetValueAt(inflation, at)) .Select(adjusted => adjusted.Value) .Sum()); }
private decimal CostAt(decimal expenseAtInitiation, IInflation expenseInflation, DateTime at) { return(new Money( expenseAtInitiation, InitiatedAt ).GetValueAt( expenseInflation, at ).Value); }
public virtual decimal GetCash(IInflation inflation, DateTime startAt, DateTime endAt) { if (endAt <= startAt) { throw new ArgumentOutOfRangeException(nameof(startAt), startAt, $"Should be later than {endAt}"); } var result = DailyProfit * endAt.Subtract(startAt).Days; return decimal.Round(result, 2); }
public decimal GetNetWorthAt(IInflation inflation, DateTime at) { if (at <= InitiatedAt) { throw new ArgumentOutOfRangeException(nameof(at), at, $"Should be later than {InitiatedAt}"); } var result = 0.00M; result += GetCashAt(inflation, at); result += GetValueAt(at); result -= GetCostAt(at); return(result); }
// TODO: Use inflation in DailyProfit public decimal GetCash(IInflation inflation, DateTime startAt, DateTime endAt) { if (endAt <= startAt) { throw new ArgumentOutOfRangeException(nameof(endAt), endAt, $"Should be later than {startAt}"); } var result = 0.00M; result += CashFlow.DailyProfit * endAt.Subtract(startAt).Days; result += GetHistories() .Where(action => action.At >= startAt) .Where(action => action.At < endAt) .Select(action => action.TransactionalPrice) .Sum(); return(decimal.Round(result, 2)); }
public DateTime HasAvailableCashAt(decimal expenseAtInitiation, IInflation expenseInflation) { var atFiftyYears = InitiatedAt.AddYears(50); DateTime at = InitiatedAt; decimal available, required; do { if (at > atFiftyYears) { throw new InvalidOperationException($"Unable to find enough money to pay for {expenseAtInitiation} by ${atFiftyYears.ToString("yyyy-MM-dd")}"); } at = at.GetNext(); available = CashFlow.GetCash(expenseInflation, InitiatedAt, at); required = CostAt(expenseAtInitiation, expenseInflation, at); } while (available < required); return(at); }
// TODO: Use inflation in DailyProfit public decimal GetCashAt(IInflation inflation, DateTime at) { if (at <= InitiatedAt) { throw new ArgumentOutOfRangeException(nameof(at), at, $"Should be later than {InitiatedAt}"); } var result = 0.00M; result += InitialCash; result -= InitialDebt; // Adjust for inflation result += CashFlow.DailyProfit * at.Subtract(InitiatedAt).Days; result += GetHistories() .Where(action => action.At >= InitiatedAt) .Where(action => action.At < at) .Select(action => action.TransactionalPrice) .Sum(); return(decimal.Round(result, 2)); }
public Money GetValueAt(IInflation inflation, DateTime targetAt) { return(inflation.GetValueAt(Value, At, targetAt)); }
private RealEstateBuilder AddHomeWithFixedRateMortgage(DateTime purchasedAt, decimal purchasePriceAtInitiation, IInflation inflation) { var purchasePriceWhenPurchased = new Money(purchasePriceAtInitiation, InitiatedAt) .GetValueAt(new CompoundYearlyInflation(0.05M), purchasedAt); var availableCash = Result.GetCashAt(inflation, purchasedAt); var downPaymentAmount = availableCash < purchasePriceAtInitiation ? availableCash : purchasePriceAtInitiation; var mortgage = Mortgages.GetFixedRateMortgage( new Money(purchasePriceWhenPurchased.Value - downPaymentAmount, purchasedAt), 0.0319M, 300, purchasedAt, new Money(downPaymentAmount, purchasedAt) ); var home = new Home( "foobar", purchasedAt, new Money(purchasePriceWhenPurchased, purchasedAt), new Money(downPaymentAmount, purchasedAt), mortgage ); Result.Buy(home, purchasedAt); Result.Buy(mortgage, purchasedAt); return(this); }