public ActionResult <string> Get(int id) { double initialInvst = 200000; double discountRate = .04; List <double> yearlyCashFlows = new List <double>(); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); FinancialReturnInputs finROIInputs = new FinancialReturnInputs(); finROIInputs.InitialInvestment = initialInvst; finROIInputs.CashInFlows = yearlyCashFlows; finROIInputs.DiscountRate = discountRate; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed = calcuationNPV.Execute(); return(calcuationNPV.Result.ToString()); }
public ICalcuation GetCalculation(CalculationTypeEnum typeEnum, FinancialReturnInputs finROIInputs) { switch (typeEnum) { case CalculationTypeEnum.NPV: _calculation = new NPVCalculation(finROIInputs); break; case CalculationTypeEnum.IRR: _calculation = new IRRCalculation(finROIInputs); break; case CalculationTypeEnum.Other: break; default: break; } return(_calculation); }
void addCalculatedColumn(DataTable pivotedDataTable, DataTable fieldIdAndNameTable, ICalcuation calculationStrategy) { List <int> values = new List <int>(); List <int> maxValues = new List <int>(); DataColumn calculatedMarks = new DataColumn("calculated marks"); pivotedDataTable.Columns.Add(calculatedMarks); List <string> fieldNames = new List <string>(); List <int> fieldIDs = new List <int>(); // Get subjectTable for maxMarks SqlDataAdapter adapter = new SqlDataAdapter("SELECT maxMarks FROM subjectFields WHERE subjectid = " + getCurrentSubjectId(), conn); DataTable maxMarksTable = new DataTable(); adapter.Fill(maxMarksTable); foreach (DataRow row in fieldIdAndNameTable.Rows) { fieldIDs.Add(Convert.ToInt32(row["fieldid"])); fieldNames.Add(row["fieldname"].ToString()); } foreach (DataRow row in pivotedDataTable.Rows) { values.Clear(); maxValues.Clear(); // Get marks of the student from pivotedDataTable foreach (DataColumn column in pivotedDataTable.Columns) { // if the column is a field if (fieldNames.Contains(column.ColumnName)) { values.Add(Convert.ToInt32(row[column])); } } // Get max marks foreach (DataRow marksRow in maxMarksTable.Rows) { maxValues.Add(Convert.ToInt32(marksRow["maxMarks"])); } row[calculatedMarks] = calculationStrategy.getResults(values, maxValues); } return; }
static void Main(string[] args) { Console.WriteLine("Hello World Calculation Engine!"); Console.WriteLine("-------------------------------"); double initialInvst = 10000; double discountRate = .1; double yearlycashIn = 3000; double noofYears = 5; FinancialReturnInputs finROIInputs = new FinancialReturnInputs(); finROIInputs.IsCashinFlowFixed = true; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.NumberofYears = noofYears; finROIInputs.FixedCashinFlow = yearlycashIn; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed = calcuationNPV.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : NPV={4}", initialInvst, discountRate, yearlycashIn, noofYears, calcuationNPV.Result)); initialInvst = 200000; discountRate = .04; List <double> yearlyCashFlows = new List <double>(); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(50000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); yearlyCashFlows.Add(45000); finROIInputs.IsCashinFlowFixed = false; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.CashInFlows = yearlyCashFlows; ; ///Initailizing NPVCalculation class with the parameters of Initail investment, discountrate, yearly cash flow, number of years ///then the Execute method is called and result is found in Result property of the class. ICalcuation calcuationNPV2 = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.NPV, finROIInputs); bool executed2 = calcuationNPV2.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : IRR={4}", initialInvst, discountRate, yearlycashIn, noofYears, calcuationNPV2.Result)); finROIInputs.IsCashinFlowFixed = true; finROIInputs.DiscountRate = discountRate; finROIInputs.InitialInvestment = initialInvst; finROIInputs.NumberofYears = noofYears; finROIInputs.FixedCashinFlow = yearlycashIn; finROIInputs.MaxDiscountRate = .9; ICalcuation calculationIRR = CalculationFactory.Instance().GetCalculation(CalculationTypeEnum.IRR, finROIInputs); bool executedIRR = calculationIRR.Execute(); Console.WriteLine(String.Format("With Initial Investment {0} and Discount Rate {1} and cashInFlow {2} , noof years{3} : IRR={4}", initialInvst, discountRate, yearlycashIn, noofYears, calculationIRR.Result)); Console.ReadLine(); }