if (! validCurve) {
data[i+1] = data[i];
}
}
final LevenbergMarquardt solver = new LevenbergMarquardt (ts.accuracy(), ts.accuracy(), ts.accuracy());
final EndCriteria endCriteria = new EndCriteria (100, 10, 0.00, ts.accuracy(), 0.00);
final Constraint solverConstraint = (forcePositive ? new PositiveConstraint() : new NoConstraint());
int i = localisation -1;
//FIXME, convexmonotone interpolation?
final int dataAdjust = 1;
for (; i < nInsts; ++ i) {
final int initialDataPoint = i + 1 - localisation + dataAdjust;
final double startArray[] = new double[localisation+1-dataAdjust];
for (int j=0; j < startArray.length-1; ++j) {
startArray[j] = data[initialDataPoint+j];
// here we are extending the interpolation a point at a
// time... but the local interpolator can make an
// approximation for the final localisation period.
// e.g. if the localisation is 2, then the first section
// of the curve will be solved using the first 2
// instruments... with the local interpolator making
// suitable boundary conditions.
/*
ts_->interpolation_ =
ts_->interpolator_.localInterpolate(
ts_->times_.begin(),
ts_->times_.begin()+(iInst + 2),
ts_->data_.begin(),
localisation_,
ts_->interpolation_,
nInsts+1);
*/
//bootstrapable.getInterpolation ().update ();
ts.setInterpolation(interpolator.interpolate(new Array(times, i+2), new Array(data)));
if (i >= localisation) {
startArray[localisation-dataAdjust] = traits.guess(ts, dates[i]);
} else {
startArray[localisation-dataAdjust] = data[0];
}
final PenaltyFunction currentCost = new PenaltyFunction(initialDataPoint, (i - localisation + 1), (i + 1));
final Problem toSolve = new Problem(currentCost, solverConstraint, new Array(startArray));
final EndCriteria.Type endType = solver.minimize (toSolve, endCriteria);
QL.require (endType == EndCriteria.Type.StationaryFunctionAccuracy ||
endType == EndCriteria.Type.StationaryFunctionValue,
"Unable to strip yieldcurve to required accuracy");
}