public void Test_SellCondo_SellsTheHomeAndTheMortgage() { var purchasePrice = 2000.00M; // Buy condo var balanceSheet = Subject .SetInitialCash(purchasePrice) .AddCondoWithFixedRateMortgageAtDownPaymentPercentage("first", purchasePrice, 0.25M); var condo = Subject.GetHomes().First(); var purchasedAt = condo.PurchasedAt; // Sell the condo var soldAt = purchasedAt.AddYears(5); var homeInflation = new CompoundYearlyInflation(0.05M); var soldPrice = homeInflation.GetValueAt(purchasePrice, purchasedAt, soldAt); Subject.SellHome(condo, soldAt, soldPrice); Assert.That(Subject.GetHomes(), Is.Empty); var activity = Subject .Build(); var actualHistories = activity.GetHistories() .ToList(); Assert.That(actualHistories, Has.Exactly(2).Items); var inflationAdjustment = Inflations.ConsumerPriceIndex; Assert.That( actualHistories[0].TransactionalPrice, Is.EqualTo(new decimal[] { -2000.00M, inflationAdjustment.GetValueAt( -1000.00M, HomePurchaseStrategy.InflationStartsAt, purchasedAt ), inflationAdjustment.GetValueAt( -8500.00M, HomePurchaseStrategy.InflationStartsAt, purchasedAt ), inflationAdjustment.GetValueAt( -800.00M, HomePurchaseStrategy.InflationStartsAt, purchasedAt ) }.Sum()) ); Assert.That(actualHistories[0].Type, Is.EqualTo(Types.Purchase)); Assert.That(actualHistories[0].At, Is.EqualTo(InitiatedAt.GetNext())); Assert.That(actualHistories[0].Product, Is.TypeOf <Home>()); Assert.That(actualHistories[1].TransactionalPrice, Is.EqualTo(10.41M)); Assert.That(actualHistories[1].Type, Is.EqualTo(Types.Sale)); Assert.That(actualHistories[1].At, Is.EqualTo(soldAt)); Assert.That(actualHistories[1].Product, Is.TypeOf <Home>()); }
// private static Activity GetActivity(ICashFlow cashFlow, DateTime startAt) // { // var result = new Activity(cashFlow, startAt); // // return result; // } private static Activity BuyAndSellOneHouse(ICashFlow cashFlow, DateTime startAt, DateTime soldAt, decimal downPaymentRate) { var condoAppreciation = new CompoundYearlyInflation(0.05M); var soldPrice = new Money(500000, startAt) .GetValueAt(condoAppreciation, soldAt); return(new MagicEstateBuilder(cashFlow, startAt) .SetInitialCash(50000.00M) .AddCondoWithFixedRateMortgageAtDownPaymentPercentage("first", 500000, downPaymentRate) .SellHome("first", soldAt, soldPrice) .Build()); }
public void Test_SellCondo_BeforeHomeWasPurchased(int yearsBeforeHomeWasPurchased) { var purchasePrice = new Money(2000.00M, InitiatedAt); // Buy condo var balanceSheet = Subject .SetInitialCash(purchasePrice) .AddCondoWithFixedRateMortgageAtDownPaymentPercentage("first", purchasePrice, 0.25M); var condo = Subject.GetHomes().First(); var purchasedAt = condo.PurchasedAt; // Sell the condo var soldAt = purchasedAt.AddYears(0 - yearsBeforeHomeWasPurchased); var homeInflation = new CompoundYearlyInflation(0.05M); Assert.Throws <ArgumentException>(() => { Subject.SellHome("first", soldAt, new Money(5000.00M, soldAt)); }); }
private static decimal PrintCashFlow(decimal downPaymentRate, ICashFlow cashFlow, DateTime startedAt, DateTime soldAt, decimal previousCash) { var activity = BuyAndSellOneHouse(cashFlow, startedAt, soldAt, downPaymentRate); var consumerPriceIndex = new CompoundYearlyInflation(0.02M); // var netWorth = activity.GetNetWorth(consumerPriceIndex, atTwentyYears.AddDays(1)); var cash = activity.GetCashAt(Inflations.NoopInflation, soldAt.AddDays(1)); var condoPurchase = activity.GetHistories() .Where(action => action.Type == Types.Purchase) .Where(action => action.Product.GetType() == typeof(Home)) .First(); Console.WriteLine($"\tPurchased with {downPaymentRate * 100} per cent down at {condoPurchase.At} after 20 years"); Console.WriteLine($"\t- Cash:\t\t{cash}"); if (previousCash != 0.00M) { Console.WriteLine($"\t- %+- Change:\t{((cash / previousCash) - 1).ToString("#0.00 %")}"); } return(cash); }
public CompoundYearlyInflationTests() { Subject = new CompoundYearlyInflation(); }