/** * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.analytics.financial.curve.interestrate.generator; import com.opengamma.analytics.financial.interestrate.InstrumentDerivative; import com.opengamma.analytics.financial.interestrate.InstrumentDerivativeVisitorAdapter; import com.opengamma.analytics.financial.interestrate.YieldCurveBundle; import com.opengamma.analytics.financial.model.interestrate.curve.YieldAndDiscountCurve; import com.opengamma.analytics.financial.provider.description.interestrate.MulticurveProviderInterface; import com.opengamma.analytics.math.interpolation.Interpolator1D; import com.opengamma.util.ArgumentChecker; /** * Store the details and generate the required curve. The curve is interpolated on the rate (continuously compounded). * One extra node with value zero is added at the mid point between the first and second point. This extra anchor is required when two translation invariant curves descriptions * are added in a spread curve (two translations would create a singular system). * Only the lastTimeCalculator is stored. The node are computed from the instruments. */ @SuppressWarnings("deprecation") public class GeneratorCurveYieldInterpolatedAnchor extends GeneratorYDCurve { // TODO Change to have the anchor point flexible. /** * Calculator of the node associated to instruments. */ private final InstrumentDerivativeVisitorAdapter<Object, Double> _nodeTimeCalculator; /** * The interpolator used for the curve. */ private final Interpolator1D _interpolator; /** * Constructor. * @param nodeTimeCalculator Calculator of the node associated to instruments. * @param interpolator The interpolator used for the curve. */ public GeneratorCurveYieldInterpolatedAnchor(final InstrumentDerivativeVisitorAdapter<Object, Double> nodeTimeCalculator, final Interpolator1D interpolator) { _nodeTimeCalculator = nodeTimeCalculator; _interpolator = interpolator; } @Override public int getNumberOfParameter() { throw new UnsupportedOperationException("Cannot return the number of parameter for a GeneratorCurveYieldInterpolated"); } @Override public YieldAndDiscountCurve generateCurve(final String name, final double[] parameters) { throw new UnsupportedOperationException("Cannot generate curves for a GeneratorCurveYieldInterpolatedAnchor"); } /** * {@inheritDoc} * @deprecated Curve builders that use and populate {@link YieldCurveBundle}s are deprecated. */ @Deprecated @Override public YieldAndDiscountCurve generateCurve(final String name, final YieldCurveBundle bundle, final double[] parameters) { throw new UnsupportedOperationException("Cannot generate curves for a GeneratorCurveYieldInterpolatedAnchor"); } @Override public YieldAndDiscountCurve generateCurve(final String name, final MulticurveProviderInterface multicurve, final double[] parameters) { throw new UnsupportedOperationException("Cannot generate curves for a GeneratorCurveYieldInterpolatedAnchor"); } /** * The data passed should be one instrument for the anchor then one instrument for each of the nodes. * @param data The array of instruments. * @return The final generator. */ @Override public GeneratorYDCurve finalGenerator(final Object data) { ArgumentChecker.isTrue(data instanceof InstrumentDerivative[], "data should be an array of InstrumentDerivative"); final InstrumentDerivative[] instruments = (InstrumentDerivative[]) data; final double[] node = new double[instruments.length - 1]; for (int loopins = 0; loopins < instruments.length - 1; loopins++) { node[loopins] = instruments[loopins + 1].accept(_nodeTimeCalculator); } final double anchor = instruments[0].accept(_nodeTimeCalculator); return new GeneratorCurveYieldInterpolatedAnchorNode(node, anchor, _interpolator); } }