private void InitializeTestValue() { NetPresentationValueModel netPresentationValue = new NetPresentationValueModel(); this.LowerBoundRate = 3.65m; this.UpperBoundRate = 3.70m; this.Increment = 0.010m; this.InitialValue = 100000; this.CashFlow1 = 10000; this.CashFlow2 = 10000; this.CashFlow3 = 10000; }
private void OnClear() { NetPresentationValueModel netPresentationValue = new NetPresentationValueModel(); this.LowerBoundRate = 0; this.UpperBoundRate = 0; this.Increment = 0; this.InitialValue = 0; this.CashFlow1 = 0; this.CashFlow2 = 0; this.CashFlow3 = 0; }
public void OnCalculate() { try { dynamic initTemp = InitialValue; this.InitialValue = Convert.ToDecimal(Regex.Replace(InitialValue.ToString(), "-", "")); var initialValue = Convert.ToDouble(InitialValue.ToString().Contains("-") ? InitialValue : Convert.ToDecimal("-" + InitialValue)); var diff = UpperBoundRate - LowerBoundRate; int numberOfIncrement = Convert.ToInt32(diff / Increment); decimal lbr = LowerBoundRate; decimal ValueRate = Increment; for (int i = 1; i <= numberOfIncrement; i++) { //CashFlow 1 var discountFactor1 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 1); var presentValue1 = discountFactor1 * Convert.ToDouble(CashFlow1); //CashFlow 2 var discountFactor2 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 2); var presentValue2 = discountFactor2 * Convert.ToDouble(CashFlow2); //CashFlow 2 var discountFactor3 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 3); var presentValue3 = discountFactor3 * Convert.ToDouble(CashFlow3); var totalPresentValue = initialValue + presentValue1 + presentValue2 + presentValue3; NetPresentationValueModel netPV = new NetPresentationValueModel(); lbr += Increment; ValueRate += Increment; netPV.InitialValue = initTemp; netPV.DiscountRate = lbr; netPV.NPV = Convert.ToDecimal(totalPresentValue); netPV.CashFlowAmount = InitialValue + Convert.ToDecimal(totalPresentValue); netPV.DateCreated = DateTime.Now; NPVModelList.Add(netPV); this.SaveNPV(netPV.InitialValue, netPV.CashFlowAmount, netPV.DiscountRate, netPV.NPV); } InitialValue = initTemp; } catch (Exception ex) { MessageBox.Show(ex.Message + " Fill all filelds with correct values.", "Net Presentation Value"); } }