private bool RunOutputCalculations(OutputDiscounted outputDiscounted, CalculatorParameters calcParameters) { //this calculator does not do cumulative totals bool bHasCalculations = false; //outputs are discounted using the BudgetsandInvestments calculator //that calculator relies on 'ancestor' objects (ancestor xml nodes) //for some calculation parameters calcParameters.ParentBudgetInvestment = new BudgetInvestment(); calcParameters.ParentBudgetInvestment.Local = new Local(); calcParameters.ParentBudgetInvestment.Local.NominalRate = outputDiscounted.Local.NominalRate; calcParameters.ParentBudgetInvestment.Local.InflationRate = outputDiscounted.Local.InflationRate; calcParameters.ParentBudgetInvestment.Local.RealRate = outputDiscounted.Local.RealRate; calcParameters.ParentBudgetInvestment.InitEOPDate = outputDiscounted.EndOfPeriodDate; calcParameters.ParentBudgetInvestment.PreProdPeriods = 0; calcParameters.ParentBudgetInvestment.ProdPeriods = 1; calcParameters.ParentTimePeriod = new TimePeriod(); calcParameters.ParentTimePeriod.IsDiscounted = outputDiscounted.IsDiscounted; calcParameters.ParentTimePeriod.Date = outputDiscounted.EndOfPeriodDate; //convert discountedoutput to an Output object that can be used to run calcs Output output = OutputDiscounted.ConvertDiscountedOutput(calcParameters, outputDiscounted); XElement oCurrentCalculationElement = null; BICalculator biCalculator = new BICalculator(); bHasCalculations = biCalculator.SetOutputCalculations( calcParameters, output, oCurrentCalculationElement); //transfer the new calculations back to outputDiscounted (via its base output object) outputDiscounted.SetOutputProperties(calcParameters, output); return(bHasCalculations); }
private bool RunBudgetInvestmentCalculation(ref XElement currentElement, ref XElement currentCalculationsElement) { bool bHasCalculations = false; CalculatorHelpers.CALCULATOR_TYPES eCalculatorType = CalculatorHelpers.GetCalculatorType(this.GCCalculatorParams.CalculatorType); BICalculator biCalculator = new BICalculator(); switch (eCalculatorType) { case CalculatorHelpers.CALCULATOR_TYPES.budget: bHasCalculations = biCalculator.SetBudgetAndInvestmentCalculations( eCalculatorType, this.GCCalculatorParams, ref currentCalculationsElement, ref currentElement, this.GCCalculatorParams.Updates); break; case CalculatorHelpers.CALCULATOR_TYPES.investment: bHasCalculations = biCalculator.SetBudgetAndInvestmentCalculations( eCalculatorType, this.GCCalculatorParams, ref currentCalculationsElement, ref currentElement, this.GCCalculatorParams.Updates); break; default: break; } return(bHasCalculations); }
private bool RunInputCalculations(InputDiscounted inputDiscounted, CalculatorParameters calcParameters) { //this calculator does not do cumulative totals bool bHasCalculations = false; //inputs are discounted using the BudgetsandInvestments calculator //that calculator relies on 'ancestor' objects (ancestor xml nodes) //for some calculation parameters calcParameters.ParentBudgetInvestment = new BudgetInvestment(); calcParameters.ParentBudgetInvestment.Local = new Local(); calcParameters.ParentBudgetInvestment.Local.NominalRate = inputDiscounted.Local.NominalRate; calcParameters.ParentBudgetInvestment.Local.InflationRate = inputDiscounted.Local.InflationRate; calcParameters.ParentBudgetInvestment.Local.RealRate = inputDiscounted.Local.RealRate; calcParameters.ParentBudgetInvestment.InitEOPDate = inputDiscounted.EndOfPeriodDate; calcParameters.ParentBudgetInvestment.PreProdPeriods = 0; calcParameters.ParentBudgetInvestment.ProdPeriods = 1; calcParameters.ParentTimePeriod = new TimePeriod(); calcParameters.ParentTimePeriod.IsDiscounted = inputDiscounted.IsDiscounted; calcParameters.ParentTimePeriod.Date = inputDiscounted.EndOfPeriodDate; calcParameters.ParentOperationComponent = new OperationComponent(); calcParameters.ParentOperationComponent.Local = new Local(); calcParameters.ParentOperationComponent.Local.NominalRate = inputDiscounted.Local.NominalRate; calcParameters.ParentOperationComponent.Local.InflationRate = inputDiscounted.Local.InflationRate; calcParameters.ParentOperationComponent.Local.RealRate = inputDiscounted.Local.RealRate; calcParameters.ParentOperationComponent.Amount = 1; calcParameters.ParentOperationComponent.Date = inputDiscounted.EndOfPeriodDate; calcParameters.ParentOperationComponent.EffectiveLife = inputDiscounted.EffectiveLife; calcParameters.ParentOperationComponent.SalvageValue = inputDiscounted.SalvageValue; //convert inputDiscounted to an Input object that can be used to run calcs Input input = InputDiscounted.ConvertDiscountedInput(calcParameters, inputDiscounted); //adjust base input totals (necessary when aliases aren't used to set them) if (input.AOHAmount == 0) { input.AOHAmount = input.OCAmount; } if (input.CAPAmount == 0) { input.CAPAmount = 1; } //run calcs XElement oCurrentCalculationElement = null; BICalculator biCalculator = new BICalculator(); bHasCalculations = biCalculator.SetInputCalculations( calcParameters, input, oCurrentCalculationElement); //transfer the new calculations back to inputdiscounted inputDiscounted.SetInputProperties(calcParameters, input); //see if any amortized totals are needed if (inputDiscounted.EffectiveLife != 0 && inputDiscounted.EffectiveLife != 1) { //uses calcParams.ParentOperation for calculations calcParameters.ParentOperationComponent.TotalOC = input.TotalOC + input.TotalOC_INT; calcParameters.ParentOperationComponent.TotalAOH = input.TotalAOH + input.TotalAOH_INT; calcParameters.ParentOperationComponent.TotalCAP = input.TotalCAP + input.TotalCAP_INT; calcParameters.ParentOperationComponent.TotalINCENT = input.TotalINCENT; bHasCalculations = biCalculator.SetOperationComponentCalculations( calcParameters, calcParameters.ParentOperationComponent); inputDiscounted.TotalAMOC = calcParameters.ParentOperationComponent.TotalAMOC; inputDiscounted.TotalAMOC_INT = calcParameters.ParentOperationComponent.TotalAMOC_INT; inputDiscounted.TotalAMAOH = calcParameters.ParentOperationComponent.TotalAMAOH; inputDiscounted.TotalAMAOH_INT = calcParameters.ParentOperationComponent.TotalAMAOH_INT; inputDiscounted.TotalAMCAP = calcParameters.ParentOperationComponent.TotalAMCAP; inputDiscounted.TotalAMCAP_INT = calcParameters.ParentOperationComponent.TotalAMCAP_INT; inputDiscounted.TotalAMINCENT = calcParameters.ParentOperationComponent.TotalAMINCENT; } return(bHasCalculations); }
//descendants need properties from ancestor objects (i.e. realrate) //to run their calculations; the ancestors are kept statefully in this.GCCalculatorParams private void AddAncestorObjects(XElement currentElement) { XElement currentCalculationsElement = null; currentCalculationsElement = CalculatorHelpers.GetCalculator(this.GCCalculatorParams, currentElement); if (currentElement.Name.LocalName == BudgetInvestment.BUDGET_TYPES.budgetgroup.ToString() || currentElement.Name.LocalName == BudgetInvestment.INVESTMENT_TYPES.investmentgroup.ToString()) { //set the stateful ancestor object this.GCCalculatorParams.ParentBudgetInvestmentGroup = new BudgetInvestmentGroup(); //deserialize xml to object this.GCCalculatorParams.ParentBudgetInvestmentGroup.SetBudgetInvestmentGroupProperties( this.GCCalculatorParams, currentCalculationsElement, currentElement); //init the total costs to zero this.GCCalculatorParams.ParentBudgetInvestmentGroup.InitTotalBenefitsProperties(); this.GCCalculatorParams.ParentBudgetInvestmentGroup.InitTotalCostsProperties(); } else if (currentElement.Name.LocalName == BudgetInvestment.BUDGET_TYPES.budget.ToString() || currentElement.Name.LocalName == BudgetInvestment.INVESTMENT_TYPES.investment.ToString()) { //set the stateful ancestor object this.GCCalculatorParams.ParentBudgetInvestment = new BudgetInvestment(); //deserialize xml to object this.GCCalculatorParams.ParentBudgetInvestment.SetBudgetInvestmentProperties( this.GCCalculatorParams, currentCalculationsElement, currentElement); //init the total costs to zero this.GCCalculatorParams.ParentBudgetInvestment.InitTotalBenefitsProperties(); this.GCCalculatorParams.ParentBudgetInvestment.InitTotalCostsProperties(); //anyway to setpreprod annuities later rather than running here? SetAncestorBudgetInvestment(currentCalculationsElement, currentElement); //run preproduction and other annuity calculations BICalculator biCalculator = new BICalculator(); biCalculator.SetPreProductionCalculations( this.GCCalculatorParams, currentElement); //reset annuities collection this.GCCalculatorParams.ParentBudgetInvestment.AnnEquivalents = null; } else if (currentElement.Name.LocalName == BudgetInvestment.BUDGET_TYPES.budgettimeperiod.ToString() || currentElement.Name.LocalName == BudgetInvestment.INVESTMENT_TYPES.investmenttimeperiod.ToString()) { //set the stateful ancestor object //last time period date's are used in some calculations DateTime dtLastTimePeriodDate = new DateTime(1000, 12, 1); bool bHasLastDate = false; if (this.GCCalculatorParams.ParentTimePeriod != null) { bHasLastDate = true; dtLastTimePeriodDate = this.GCCalculatorParams.ParentTimePeriod.Date; } this.GCCalculatorParams.ParentTimePeriod = new TimePeriod(); //deserialize xml to object this.GCCalculatorParams.ParentTimePeriod.SetTimePeriodProperties( this.GCCalculatorParams, currentCalculationsElement, currentElement); //init the total costs to zero this.GCCalculatorParams.ParentTimePeriod.InitTotalBenefitsProperties(); this.GCCalculatorParams.ParentTimePeriod.InitTotalCostsProperties(); if (this.GCCalculatorParams.ParentBudgetInvestment.PreProdPeriods == 0 && this.GCCalculatorParams.ParentBudgetInvestment.ProdPeriods <= 1) { //no preproduction annuities this.GCCalculatorParams.ParentBudgetInvestment.InitEOPDate = this.GCCalculatorParams.ParentTimePeriod.Date; } //copy some of the last tps properties to current tp if (!bHasLastDate) { dtLastTimePeriodDate = this.GCCalculatorParams.ParentTimePeriod.Date; } this.GCCalculatorParams.ParentTimePeriod.LastPeriodDate = dtLastTimePeriodDate; } else if (currentElement.Name.LocalName .EndsWith(Outcome.OUTCOME_PRICE_TYPES.outcome.ToString())) { this.GCCalculatorParams.ParentOutcome = new Outcome(); this.GCCalculatorParams.ParentOutcome.SetOutcomeProperties( this.GCCalculatorParams, currentCalculationsElement, currentElement); //init the total costs to zero this.GCCalculatorParams.ParentOutcome.InitTotalBenefitsProperties(); SetAncestorOutcome(currentCalculationsElement, currentElement); //run joint output calculations //these will be copied to descendant output nodes as calculations //are run on those nodes NPVOutcomeCalculator outcomeCalculator = new NPVOutcomeCalculator(); outcomeCalculator.SetJointOutputCalculations( this.GCCalculatorParams); } else if (currentElement.Name.LocalName .EndsWith(OperationComponent.OPERATION_PRICE_TYPES.operation.ToString()) || currentElement.Name.LocalName .EndsWith(OperationComponent.COMPONENT_PRICE_TYPES.component.ToString())) { this.GCCalculatorParams.ParentOperationComponent = new OperationComponent(); this.GCCalculatorParams.ParentOperationComponent.SetOperationComponentProperties( this.GCCalculatorParams, currentCalculationsElement, currentElement); //init the total costs to zero this.GCCalculatorParams.ParentOperationComponent.InitTotalCostsProperties(); SetAncestorOperationComponent(currentCalculationsElement, currentElement); //run joint input calculations (i.e. fuel amount, fuel cost) //these will be copied to descendant input nodes as calculations //are run on those nodes OCCalculator ocCalculator = new OCCalculator(); ocCalculator.SetJointInputCalculations( this.GCCalculatorParams); } }
private bool AddNPVCalculationsToCurrentElement( CalculatorParameters calcParameters, ref XElement currentCalculationsElement, ref XElement currentElement, IDictionary <string, string> updates) { bool bHasCalculations = false; if (currentElement.Name.LocalName == Outcome.OUTCOME_PRICE_TYPES.outcomegroup.ToString()) { OutcomeGroup outcomeGroup = new OutcomeGroup(); //deserialize xml to object outcomeGroup.SetOutcomeGroupProperties( calcParameters, currentCalculationsElement, currentElement); bHasCalculations = SetOutcomeGroupCalculations( calcParameters, outcomeGroup); //serialize object back to xml outcomeGroup.SetOutcomeGroupAttributes( calcParameters, ref currentElement, updates); if (outcomeGroup != null) { //locals only for calculator outcomeGroup.Local.SetLocalAttributesForCalculator(calcParameters, ref currentCalculationsElement); } } else if (currentElement.Name.LocalName .EndsWith(Outcome.OUTCOME_PRICE_TYPES.outcome.ToString())) { BICalculator biCalculator = new BICalculator(); bHasCalculations = biCalculator.SetOutcomeCalculations( calcParameters, calcParameters.ParentOutcome); //serialize object back to xml calcParameters.ParentOutcome.SetOutcomeAttributes( calcParameters, ref currentElement, updates); if (calcParameters.ParentOutcome.Local != null) { //locals only for calculator calcParameters.ParentOutcome.Local.SetLocalAttributesForCalculator(calcParameters, ref currentCalculationsElement); } } else if (currentElement.Name.LocalName.EndsWith(Output.OUTPUT_PRICE_TYPES.output.ToString())) { Output output = new Output(); //deserialize xml to object output.SetOutputProperties( calcParameters, currentCalculationsElement, currentElement); BICalculator biCalculator = new BICalculator(); bHasCalculations = biCalculator.SetOutputCalculations( calcParameters, output, ref currentCalculationsElement); //serialize object back to xml output.SetOutputAttributes( calcParameters, ref currentElement, updates); //and set the totals output.SetTotalBenefitsAttributes(string.Empty, ref currentElement); if (output.Local != null) { //locals only for calculator output.Local.SetLocalAttributesForCalculator(calcParameters, ref currentCalculationsElement); } } return(bHasCalculations); }