// overrides OneFactorModel
//
@Override
public Lattice tree(final TimeGrid grid) {
final TermStructureFittingParameter phi = new TermStructureFittingParameter(termStructureConsistentModelClass.termStructure());
// needed to activate the above constructor
final ShortRateDynamics numericDynamics = (new Dynamics(phi, a(), sigma()));
final TrinomialTree trinomial = new TrinomialTree(numericDynamics.process(), grid, true);
final ShortRateTree numericTree = new OneFactorModel.ShortRateTree(trinomial, numericDynamics, grid);
// typedef TermStructureFittingParameter::NumericalImpl NumericalImpl;
final TermStructureFittingParameter.NumericalImpl impl = (TermStructureFittingParameter.NumericalImpl) phi.implementation();
impl.reset();
for (int /* @Size */i = 0; i < (grid.size() - 1); i++) {
final double /* @Real */discountBond = termStructureConsistentModelClass.termStructure().currentLink().discount(grid.at(i + 1));
final Array statePrices = numericTree.statePrices(i);
final int /* @Size */size = numericTree.size(i);