Пример #1
0
        public bool SetInputOutputCalculations(
            CalculatorHelpers.CALCULATOR_TYPES calculatorType,
            CalculatorParameters calcParameters, XElement currentCalculationsElement,
            XElement currentElement, IDictionary <string, string> updates)
        {
            bool bHasCalculations = false;

            switch (calculatorType)
            {
            case CalculatorHelpers.CALCULATOR_TYPES.input:
                InputDiscounted inputDiscounted = new InputDiscounted();
                //deserialize xml to object
                inputDiscounted.SetInputDiscountedProperties(
                    calcParameters, currentCalculationsElement, currentElement);
                //set up and run and the calculations
                bHasCalculations = RunInputCalculations(inputDiscounted,
                                                        calcParameters);
                //serialize object back to xml
                inputDiscounted.SetInputDiscountedAttributes(
                    calcParameters, currentCalculationsElement,
                    currentElement, updates);
                break;

            case CalculatorHelpers.CALCULATOR_TYPES.output:
                OutputDiscounted outputDiscounted = new OutputDiscounted();
                //deserialize xml to object
                outputDiscounted.SetOutputDiscountedProperties(
                    calcParameters, currentCalculationsElement, currentElement);
                //set up and run and the calculations
                bHasCalculations = RunOutputCalculations(outputDiscounted,
                                                         calcParameters);
                //serialize object back to xml
                outputDiscounted.SetOutputDiscountedAttributes(
                    calcParameters, currentCalculationsElement,
                    currentElement, updates);
                break;

            default:
                break;
            }
            return(bHasCalculations);
        }
Пример #2
0
        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);
        }
Пример #3
0
        //conversion method
        public static Input ConvertDiscountedInput(CalculatorParameters calcParameters, InputDiscounted inputDiscounted)
        {
            Input input = new Input();

            input.SetInputProperties(calcParameters, inputDiscounted);
            //only the calcs in the base input.total1 ... are needed in inputDiscounted
            return(input);
        }
Пример #4
0
 //copy constructor
 public void SetInputDiscountedProperties(CalculatorParameters calcParameters, InputDiscounted inputDiscounted)
 {
     //set the base input properties
     this.SetInputProperties(calcParameters, inputDiscounted);
     this.IsDiscounted    = inputDiscounted.IsDiscounted;
     this.EndOfPeriodDate = inputDiscounted.EndOfPeriodDate;
     this.EffectiveLife   = inputDiscounted.EffectiveLife;
     this.SalvageValue    = inputDiscounted.SalvageValue;
     this.Times           = inputDiscounted.Times;
 }