private LinearRateModel ReturnModelWithReplacedFwdCurve(CurveTenor tenor, Curve newCurve) { FwdCurveContainer newCollection = FwdCurveCollection.Copy(); newCollection.AddCurve(newCurve, tenor); return(new LinearRateModel(DiscCurve.Copy(), newCollection, Interpolation)); }
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; }
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); }
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()); }
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(); }
public void SetExistingFwdCurves(FwdCurveContainer fwdCurves) { _existingFwdCurveCollection = fwdCurves; }
public LinearRateModel(Curve discCurve, FwdCurveContainer fwdCurveCollection, InterpMethod interpolation) { Interpolation = interpolation; DiscCurve = discCurve; FwdCurveCollection = fwdCurveCollection; }