public Bond(InterestRateCalculator irCalculator, double Coupon, int paymentPerYear) { eng = irCalculator; c = Coupon; nPeriods = eng.Periods; r = eng.Interest / (double)paymentPerYear; }
public void C7_11_1_OrdinaryAnnuityTest() { var A = 2.0 * Pow(10.0, 6); var interestEngine = new InterestRateCalculator(15, 0.08); Debug.WriteLine(interestEngine.OrdinaryAnnuity(A)); }
public Bond(InterestRateCalculator calculator, double coupon, int paymentPerYear) { eng = calculator; this.Coupon = coupon; NumberOfPeriods = calculator.NumberOfPeriods; Rate = eng.Rate / (double)paymentPerYear; }
public void ThereAreNoLenders() { var calculator = new InterestRateCalculator(); var rate = calculator.GetAverageInterestRate(new List <LoanLender>()); Assert.AreEqual(0, rate); }
public void CalculatePayments() { var interestRateCalculator = new InterestRateCalculator(); var interestRate = 0M; if (Ccy == "PLN") { interestRate = interestRateCalculator.CalculateInterestRatePLN(Commission, NumberOfMonths); } else { interestRate = interestRateCalculator.CalculateInterestRatePLN(Commission, NumberOfMonths); } if (Vehicle.GetType() == typeof(CarBase)) { var car = Vehicle as CarBase; var leasingPaymentsCalculator = new LeasingPaymentsCalculator(interestRate, NumberOfMonths, car.NumberOfDoors, false, car.Price + EquipmentPackage.GetPackagePrice(), OwnContribution); Payments = leasingPaymentsCalculator.Calculate(); } else if (Vehicle.GetType() == typeof(TruckBase)) { var truck = Vehicle as TruckBase; var leasingPaymentsCalculator = new LeasingPaymentsCalculator(interestRate, NumberOfMonths, truck.NumberOfAxles, true, truck.MaximumWeight, truck.Price + EquipmentPackage.GetPackagePrice(), OwnContribution); Payments = leasingPaymentsCalculator.Calculate(); } }
private double c; // Cash coupon payment public Bond(int numberPeriods, double interest, double Coupon, int paymentPerYear) { nPeriods = numberPeriods; r = interest / (double)paymentPerYear; c = Coupon; eng = new InterestRateCalculator(nPeriods, r); }
public void C7_11_1_PresentValue() { var Pn = 5.0 * Pow(10.0, 6); var interestEngine = new InterestRateCalculator(7, 0.10); Debug.WriteLine(interestEngine.PresentValue(Pn)); }
public Bond(int numberPeriods, double interest, double coupon, int paymentPerYear) { NumberOfPeriods = numberPeriods; Rate = interest / (double)paymentPerYear; Coupon = coupon; eng = new InterestRateCalculator(this.NumberOfPeriods, Rate); }
public Bond(InterestRateCalculator interestRateCalculator, double coupon, int paymentPerYear) { eng = interestRateCalculator; c = coupon; nPeriods = eng.NumberOfPeriods; r = eng.Interest / (double)paymentPerYear; }
// Future value of a sum of money invested today, m periods // per year. r is annual interest rate public double FutureValue(double P0, int m) { double R = r / m; int newPeriods = m * nPeriods; // We create a temporary object to do the job InterestRateCalculator myBond = new InterestRateCalculator(newPeriods, R); return(myBond.FutureValue(P0)); }
public void C7_11_1_FutureValue() { var nPeriods = 6; var P = Pow(10.0, 7); var r = 0.092d; var interestEngine = new InterestRateCalculator(nPeriods, r); var fv = interestEngine.FutureValue(P); Debug.WriteLine(fv); }
public void C7_11_1_PresentValueOfOrdinaryAnnuity() { // Present Value of an ordinary annuity var A = 100.0; var interest = 0.09; var numberOfPeriods = 8; var interestEngine = new InterestRateCalculator(numberOfPeriods, interest); Debug.WriteLine("**PV, ordinary annuity: {0}", interestEngine.PresentValueOrdinaryAnnuity(A)); }
public void LentAmountIsZero() { var loanLenders = new List <LoanLender> { new LoanLender(new Lender("Bob", 0.010M, 0), 0), }; var calculator = new InterestRateCalculator(); var rate = calculator.GetAverageInterestRate(new List <LoanLender>()); Assert.AreEqual(0, rate); }
public void CalculateInterest2() { var loanLenders = new List <LoanLender> { new LoanLender(new Lender("Bob", 0.069M, 480), 200), new LoanLender(new Lender("Mike", 0.071M, 60), 300), new LoanLender(new Lender("Mike", 0.071M, 460), 300) }; var calculator = new InterestRateCalculator(); var rate = calculator.GetAverageInterestRate(loanLenders); Assert.AreEqual(0.070M, rate); }
public void CalculateInterest() { var loanLenders = new List <LoanLender> { new LoanLender(new Lender("Bob", 0.010M, 200), 200), new LoanLender(new Lender("Mike", 0.050M, 300), 300), new LoanLender(new Lender("Maze", 0.150M, 500), 500) }; var calculator = new InterestRateCalculator(); var rate = calculator.GetAverageInterestRate(loanLenders); Assert.AreEqual(0.092M, rate); }
public void C7_11_1_FutureValueContinuous() { // Now test periodic testing with continuous compounding var P0 = Pow(10.0, 8); var r = 0.092; var nPeriods2 = 6; var interestEngine = new InterestRateCalculator(nPeriods2, r); for (var mm = 1; mm <= 100000000; mm *= 12) { Debug.WriteLine("Periodic: {0}\t {1}", mm, interestEngine.FutureValue(P0, mm)); } Debug.WriteLine("Continuous Compounding: {0}", interestEngine.FutureValue(P0)); }
public void C7_11_1_PresentValueOfSeries() { var interestEngine = new InterestRateCalculator(5, 0.0625); var nPeriods2 = interestEngine.Periods; var futureValues = new double[nPeriods2]; // For five years for (long j = 0; j < nPeriods2 - 1; j++) { // The first 4 years futureValues[j] = 100.0; } futureValues[nPeriods2 - 1] = 1100.0; Debug.WriteLine("**Present value, series: {0} ", interestEngine.PresentValue(futureValues)); }
public static void Main() { // Future value of a sum of money invested today int nPeriods = 6; // 6 years double P = Math.Pow(10.0, 7); // Amount invested now, 10 million double r = 0.092; // 9.2% interest per year InterestRateCalculator interestEngine = new InterestRateCalculator(nPeriods, r); double fv = interestEngine.FutureValue(P); Console.WriteLine("Future Value: {0} ", fv.ToString("N", CultureInfo.InvariantCulture)); // Future value of a sum of money invested today, m periods // per year. r is annual interest rate int m = 2; // Compounding per year double fv2 = interestEngine.FutureValue(P, m); Console.WriteLine("Future Value with {0} compoundings per year {1} ", m, fv2); // Future value of an ordinary annuity double A = 2.0 * Math.Pow(10.0, 6); interestEngine.Interest = 0.08; interestEngine.NumberOfPeriods = 15; // 15 years Console.WriteLine("Ordinary Annuity: {0} ", interestEngine.OrdinaryAnnuity(A)); // Present Value double Pn = 5.0 * Math.Pow(10.0, 6); interestEngine.Interest = 0.10; interestEngine.NumberOfPeriods = 7; Console.WriteLine("**Present value: {0} ", interestEngine.PresentValue(Pn)); // Present Value of a series of future values interestEngine.Interest = 0.0625; interestEngine.NumberOfPeriods = 5; int nPeriods2 = interestEngine.NumberOfPeriods; double[] futureValues = new double[nPeriods2]; // For five years for (long j = 0; j < nPeriods2 - 1; j++) { // The first 4 years futureValues[j] = 100.0; } futureValues[nPeriods2 - 1] = 1100.0; Console.WriteLine("**Present value, series: {0} ", interestEngine.PresentValue(futureValues)); // Present Value of an ordinary annuity A = 100.0; interestEngine.Interest = 0.09; interestEngine.NumberOfPeriods = 8; Console.WriteLine("**PV, ordinary annuity: {0}", interestEngine.PresentValueOrdinaryAnnuity(A)); // Now test periodic testing with continuous compounding double P0 = Math.Pow(10.0, 8); r = 0.092; nPeriods2 = 6; for (int mm = 1; mm <= 100000000; mm *= 12) { Console.WriteLine("Periodic: {0}\t {1}", mm, interestEngine.FutureValue(P0, mm)); } Console.WriteLine("Continuous Compounding: {0}", interestEngine.FutureValueContinuous(P0)); // Bond pricing double coupon = 50; // Cash coupon, i.e. 10.0% rate semiannual on parValue int n = 40; // Number of payments double annualInterest = 0.11; // Interest rate annualized int paymentPerYear = 2; // Number of payment per year double parValue = 1000.0; Bond myBond = new Bond(n, annualInterest, coupon, paymentPerYear); double bondPrice = myBond.price(parValue); Console.WriteLine("Bond price: {0}", bondPrice); }
static void Main(string[] args) { int nPeriods = 6; double P = Math.Pow(10.0, 7); double r = 0.092; var interestEngine = new InterestRateCalculator(nPeriods, r); var fv = interestEngine.FutureValue(P); System.Console.WriteLine("Future Value: {0}", fv.ToString("N", CultureInfo.InvariantCulture)); int m = 2; var fv2 = interestEngine.FutureValue(P, m); System.Console.WriteLine("Future Value with {0} compoundings per year {1}", m, fv2); // Future value of an ordinary annuity double A = 2.0 * Math.Pow(10.0, 6); interestEngine.Interest = 0.08; interestEngine.NumberOfPeriods = 15; // 15 years System.Console.WriteLine("Ordinary Annuity: {0} ", interestEngine.OrdinaryAnnuity(A)); // Present Value double Pn = 5.0 * Math.Pow(10.0, 6); interestEngine.Interest = 0.10; interestEngine.NumberOfPeriods = 7; System.Console.WriteLine("**Present value: {0} ", interestEngine.PresentValue(Pn)); // Present Value of a series of future values interestEngine.Interest = 0.0625; interestEngine.NumberOfPeriods = 5; int nPeriods2 = interestEngine.NumberOfPeriods; double[] futureValues = new double[nPeriods2]; // For five years for (long j = 0; j < nPeriods2 - 1; j++) { // The first 4 years futureValues[j] = 100.0; } futureValues[nPeriods2 - 1] = 1100.0; System.Console.WriteLine("**Present value, series: {0} ", interestEngine.PresentValue(futureValues)); // Present Value of an ordinary annuity A = 100.0; interestEngine.Interest = 0.09; interestEngine.NumberOfPeriods = 8; System.Console.WriteLine("**PV, ordinary annuity: {0}", interestEngine.OrdinaryAnnuity(A)); // Now test periodic testing with continuous compounding double P0 = Math.Pow(10.0, 8); r = 0.092; nPeriods2 = 6; for (int mm = 1; mm <= 100000000; mm *= 12) { System.Console.WriteLine("Periodic: {0},, {1}", mm, interestEngine.FutureValue(P0, mm)); } System.Console.WriteLine("Continuous Compounding: {0}", interestEngine.FutureValueContinuous(P0)); // Bond pricing double coupon = 50; // Cash coupon, i.e. 10.0% rate semiannual // on parValue int n = 20 * 2; // Number of payments double annualInterest = 11.0; // Interest rate annualized double parValue = 1000.0; int paymentPerYear = 2; // Number of payments per year Bond myBond = new Bond(n, annualInterest, coupon, paymentPerYear); double bondPrice = myBond.Price(parValue); System.Console.WriteLine("Bond price: {0}", bondPrice); }