Esempio n. 1
0
        private LinearRateModel ReturnModelWithReplacedFwdCurve(CurveTenor tenor, Curve newCurve)
        {
            FwdCurveContainer newCollection = FwdCurveCollection.Copy();

            newCollection.AddCurve(newCurve, tenor);
            return(new LinearRateModel(DiscCurve.Copy(), newCollection, Interpolation));
        }
Esempio n. 2
0
        public void SetEverything(Curve discCurve, CurveCalibrationProblem[] problems, CurveTenor[] tenors, CalibrationSpec settings, int[] OrderOfCalibration = null)
        {
            if (problems.Length != tenors.Length)
            {
                throw new InvalidOperationException("Number of problems and number of tenors have to match. ");
            }

            _problemMap         = new Dictionary <CurveTenor, CurveCalibrationProblem>();
            _hasBeenCalibrated  = new Dictionary <CurveTenor, bool>();
            _discCurve          = discCurve;
            _tenors             = tenors;
            _settings           = settings;
            _fwdCurveCollection = new FwdCurveContainer();


            List <int> curvePoints = new List <int>();

            for (int i = 0; i < problems.Length; i++)
            {
                _problemMap[tenors[i]] = problems[i];
                _fwdCurveCollection.AddCurve(problems[i].CurveToBeCalibrated, tenors[i]);
                curvePoints.Add(_fwdCurveCollection.GetCurve(tenors[i]).Dimension);
            }

            _curvePoints   = curvePoints.ToArray();
            _internalState = 0;
        }
Esempio n. 3
0
        private void OptimizationFunction(double[] x, ref double func, object obj)
        {
            Curve tempDiscCurve = new Curve(_problem.CurvePoints, x.ToList());

            FwdCurveContainer tempFwdCurves = new FwdCurveContainer();
            LinearRateModel   tempModel     = new LinearRateModel(tempDiscCurve, new FwdCurveContainer(), _settings.Interpolation);

            _internalState += 1;

            if (_internalState > _internalStateMax)
            {
                return;
            }

            func = _problem.GoalFunction(tempModel, _settings.Scaling);
        }
Esempio n. 4
0
        public double[] ConstructStartingValuesFromCurves_AD_Current(FwdCurveContainer fwdCurves)
        {
            // This method constructs starting values based on existing forward curves.
            // Intended to be used for fast calibration for "live" calibration

            List <double> output = new List <double>();

            for (int i = 0; i < _currentTenors.Length; i++)
            {
                for (int j = 0; j < _currentCurvePoints[i]; j++)
                {
                    output.Add(fwdCurves.GetCurve(_currentTenors[i]).Values[j]);
                }
            }

            return(output.ToArray());
        }
Esempio n. 5
0
        public void OptimizationFunction_AD_grad(double[] x, ref double func, double[] grad, object obj)
        {
            Curve tempDiscCurve = new Curve(_problem.CurvePoints, x.ToList());

            FwdCurveContainer tempFwdCurves = new FwdCurveContainer();
            LinearRateModel   tempModel     = new LinearRateModel(tempDiscCurve, new FwdCurveContainer(), _settings.Interpolation);

            _internalState += 1;

            if (_internalState > _internalStateMax)
            {
                return;
            }


            // Initialize AADTape with curve values
            AADTape.ResetTape();
            List <ADouble> adCurveValues = new List <ADouble>();

            for (int i = 0; i < tempDiscCurve.Dimension; i++)
            {
                adCurveValues.Add(new ADouble(x[i]));
            }

            // Initialize the tape with curve values defined above
            AADTape.Initialize(adCurveValues.ToArray());
            Curve_AD adCurve = new Curve_AD(tempDiscCurve.Dates, adCurveValues);

            tempModel.ADDiscCurve = adCurve;

            func = _problem.GoalFunction_AD(tempModel, _settings.Scaling);
            AADTape.InterpretTape();
            double[] gradient = AADTape.GetGradient();
            for (int i = 0; i < gradient.Length; i++)
            {
                grad[i] = gradient[i];
            }

            AADTape.ResetTape();
        }
Esempio n. 6
0
 public void SetExistingFwdCurves(FwdCurveContainer fwdCurves)
 {
     _existingFwdCurveCollection = fwdCurves;
 }
Esempio n. 7
0
 public LinearRateModel(Curve discCurve, FwdCurveContainer fwdCurveCollection, InterpMethod interpolation)
 {
     Interpolation      = interpolation;
     DiscCurve          = discCurve;
     FwdCurveCollection = fwdCurveCollection;
 }