private static void populateVolatilitySurfaceDefinitions( final ConfigMaster configMaster, final UniqueIdentifiable target) { final Tenor[] expiryTenors = new Tenor[] { Tenor.ofDays(7), Tenor.ofDays(14), Tenor.ofDays(21), Tenor.ofMonths(1), Tenor.ofMonths(3), Tenor.ofMonths(6), Tenor.ofMonths(9), Tenor.ofYears(1), Tenor.ofYears(5), Tenor.ofYears(10) }; @SuppressWarnings("unchecked") final Pair<Number, FXVolQuoteType>[] deltaAndTypes = new Pair[] { Pair.of(25, FXVolQuoteType.BUTTERFLY), Pair.of(25, FXVolQuoteType.RISK_REVERSAL), Pair.of(15, FXVolQuoteType.BUTTERFLY), Pair.of(15, FXVolQuoteType.RISK_REVERSAL), Pair.of(0, FXVolQuoteType.ATM) }; final VolatilitySurfaceDefinition<Tenor, Pair<Number, FXVolQuoteType>> volSurfaceDefinition = new VolatilitySurfaceDefinition<Tenor, Pair<Number, FXVolQuoteType>>( "SECONDARY_EURUSD_" + InstrumentTypeProperties.FOREX, target, expiryTenors, deltaAndTypes); ConfigMasterUtils.storeByName(configMaster, makeConfigDocument(volSurfaceDefinition)); }
private static void populateVolatilitySurfaceDefinitions( final ConfigMaster configMaster, final Currency target, final String name) { final Tenor[] swaptionExpiries = new Tenor[] { Tenor.THREE_MONTHS, Tenor.SIX_MONTHS, Tenor.ONE_YEAR, Tenor.TWO_YEARS, Tenor.THREE_YEARS, Tenor.FIVE_YEARS, Tenor.TEN_YEARS }; final Tenor[] swapMaturities = new Tenor[] { Tenor.ONE_YEAR, Tenor.TWO_YEARS, Tenor.THREE_YEARS, Tenor.FIVE_YEARS, Tenor.SEVEN_YEARS, Tenor.TEN_YEARS, Tenor.ofYears(12), Tenor.ofYears(15), Tenor.ofYears(20), Tenor.ofYears(30) }; final String fullName = name + SEPARATOR + target.toString() + SEPARATOR + InstrumentTypeProperties.SWAPTION_ATM; final VolatilitySurfaceDefinition<Tenor, Tenor> definition = new VolatilitySurfaceDefinition<>(fullName, target, swapMaturities, swaptionExpiries); ConfigMasterUtils.storeByName(configMaster, makeConfigDocument(definition)); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(_atmType); result = prime * result + ((_atmTypeCutoff == null) ? 0 : _atmTypeCutoff.hashCode()); result = prime * result + _ccy1.hashCode(); result = prime * result + _ccy2.hashCode(); result = prime * result + Arrays.hashCode(_deltaType); result = prime * result + ((_deltaTypeCutoff == null) ? 0 : _deltaTypeCutoff.hashCode()); result = prime * result + (_isPremiumAdjusted ? 1231 : 1237); result = prime * result + _premiumCurrency.hashCode(); return result; }
public DeltaType getDeltaType(final Tenor tenor) { if (_deltaTypeCutoff == null) { return _deltaType[0]; } ArgumentChecker.notNull(tenor, "tenor"); return _deltaTypeCutoff.compareTo(tenor) < 0 ? _deltaType[0] : _deltaType[1]; }
public ATMType getATMQuoteType(final Tenor tenor) { if (_atmTypeCutoff == null) { return _atmType[0]; } ArgumentChecker.notNull(tenor, "tenor"); return _atmTypeCutoff.compareTo(tenor) < 0 ? _atmType[0] : _atmType[1]; }
@Override public Tenor getResolvedMaturity() { return Tenor.of(_startTenor.getPeriod().plus(_maturityTenor.getPeriod())); }
@Override public Set<ComputedValue> execute( final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) throws AsynchronousExecution { final Object originalCurveObject = inputs.getValue(YIELD_CURVE); if (originalCurveObject == null) { throw new OpenGammaRuntimeException("Could not get original curve"); } ValueProperties resultCurveProperties = null; String absoluteToleranceName = null; String relativeToleranceName = null; String iterationsName = null; String decompositionName = null; String useFiniteDifferenceName = null; for (final ValueRequirement desiredValue : desiredValues) { if (desiredValue.getValueName().equals(YIELD_CURVE)) { absoluteToleranceName = desiredValue.getConstraint( MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE); relativeToleranceName = desiredValue.getConstraint( MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE); iterationsName = desiredValue.getConstraint( MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_MAX_ITERATIONS); decompositionName = desiredValue.getConstraint( MultiYieldCurvePropertiesAndDefaults.PROPERTY_DECOMPOSITION); useFiniteDifferenceName = desiredValue.getConstraint( MultiYieldCurvePropertiesAndDefaults.PROPERTY_USE_FINITE_DIFFERENCE); resultCurveProperties = desiredValue.getConstraints().copy().get(); break; } } if (resultCurveProperties == null) { throw new OpenGammaRuntimeException("Could not get result curve properties"); } final ValueProperties resultJacobianProperties = resultCurveProperties.withoutAny(CURVE); ZonedDateTime valuationDateTime = executionContext .getValuationTime() .atZone(executionContext.getValuationClock().getZone()); final HolidaySource holidaySource = OpenGammaExecutionContext.getHolidaySource(executionContext); final ConventionSource conventionSource = OpenGammaExecutionContext.getConventionSource(executionContext); final Calendar calendar = CalendarUtils.getCalendar(holidaySource, _currency); final DepositConvention convention = conventionSource.getSingle( ExternalId.of(SCHEME_NAME, getConventionName(_currency, DEPOSIT)), DepositConvention.class); final int spotLag = convention.getSettlementDays(); final ExternalId conventionSettlementRegion = convention.getRegionCalendar(); ZonedDateTime spotDate; if (spotLag == 0 && conventionSettlementRegion == null) { spotDate = valuationDateTime; } else { spotDate = ScheduleCalculator.getAdjustedDate(valuationDateTime, spotLag, calendar); ; } final YieldCurveBundle curves = new YieldCurveBundle(); final String fullYieldCurveName = _originalCurveName + "_" + _currency; curves.setCurve(fullYieldCurveName, (YieldAndDiscountCurve) originalCurveObject); final int n = _impliedDefinition.getStrips().size(); final double[] t = new double[n]; final double[] r = new double[n]; int i = 0; final DayCount dayCount = DayCountFactory.INSTANCE.getDayCount( "Act/360"); // TODO: Get the convention from the curve. final String impliedDepositCurveName = _curveCalculationConfig + "_" + _currency.getCode(); final List<InstrumentDerivative> derivatives = new ArrayList<>(); for (final FixedIncomeStrip strip : _impliedDefinition.getStrips()) { final Tenor tenor = strip.getCurveNodePointTime(); final ZonedDateTime paymentDate = ScheduleCalculator.getAdjustedDate( spotDate, tenor.getPeriod(), MOD_FOL, calendar, true); final double startTime = TimeCalculator.getTimeBetween(valuationDateTime, spotDate); final double endTime = TimeCalculator.getTimeBetween(valuationDateTime, paymentDate); final double accrualFactor = dayCount.getDayCountFraction(spotDate, paymentDate, calendar); final Cash cashFXCurve = new Cash(_currency, startTime, endTime, 1, 0, accrualFactor, fullYieldCurveName); final double parRate = METHOD_CASH.parRate(cashFXCurve, curves); final Cash cashDepositCurve = new Cash(_currency, startTime, endTime, 1, 0, accrualFactor, impliedDepositCurveName); derivatives.add(cashDepositCurve); t[i] = endTime; r[i++] = parRate; } final CombinedInterpolatorExtrapolator interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator( _interpolatorName, _leftExtrapolatorName, _rightExtrapolatorName); final double absoluteTolerance = Double.parseDouble(absoluteToleranceName); final double relativeTolerance = Double.parseDouble(relativeToleranceName); final int iterations = Integer.parseInt(iterationsName); final Decomposition<?> decomposition = DecompositionFactory.getDecomposition(decompositionName); final boolean useFiniteDifference = Boolean.parseBoolean(useFiniteDifferenceName); final LinkedHashMap<String, double[]> curveNodes = new LinkedHashMap<>(); final LinkedHashMap<String, Interpolator1D> interpolators = new LinkedHashMap<>(); curveNodes.put(impliedDepositCurveName, t); interpolators.put(impliedDepositCurveName, interpolator); final FXMatrix fxMatrix = new FXMatrix(); final YieldCurveBundle knownCurve = new YieldCurveBundle(); final MultipleYieldCurveFinderDataBundle data = new MultipleYieldCurveFinderDataBundle( derivatives, r, knownCurve, curveNodes, interpolators, useFiniteDifference, fxMatrix); final NewtonVectorRootFinder rootFinder = new BroydenVectorRootFinder( absoluteTolerance, relativeTolerance, iterations, decomposition); final Function1D<DoubleMatrix1D, DoubleMatrix1D> curveCalculator = new MultipleYieldCurveFinderFunction(data, PAR_RATE_CALCULATOR); final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianCalculator = new MultipleYieldCurveFinderJacobian(data, PAR_RATE_SENSITIVITY_CALCULATOR); final double[] fittedYields = rootFinder.getRoot(curveCalculator, jacobianCalculator, new DoubleMatrix1D(r)).getData(); final DoubleMatrix2D jacobianMatrix = jacobianCalculator.evaluate(new DoubleMatrix1D(fittedYields)); final YieldCurve impliedDepositCurve = new YieldCurve( impliedDepositCurveName, InterpolatedDoublesCurve.from(t, fittedYields, interpolator)); final ValueSpecification curveSpec = new ValueSpecification(YIELD_CURVE, target.toSpecification(), resultCurveProperties); final ValueSpecification jacobianSpec = new ValueSpecification( YIELD_CURVE_JACOBIAN, target.toSpecification(), resultJacobianProperties); return Sets.newHashSet( new ComputedValue(curveSpec, impliedDepositCurve), new ComputedValue(jacobianSpec, jacobianMatrix)); }
@Test public void testFXOptionVolatilitySurfaceInstrumentProvider() { final ICAPFXOptionVolatilitySurfaceInstrumentProvider provider = new ICAPFXOptionVolatilitySurfaceInstrumentProvider("I", "EURUSD", "Market_Value"); assertEquals( provider, cycleObject(ICAPFXOptionVolatilitySurfaceInstrumentProvider.class, provider)); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1WK"), provider.getInstrument(Tenor.ofDays(7), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1M"), provider.getInstrument(Tenor.ofMonths(1), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1YR"), provider.getInstrument(Tenor.ofYears(1), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1WK"), provider.getInstrument(Tenor.ofDays(7), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1M"), provider.getInstrument(Tenor.ofMonths(1), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSD_1YR"), provider.getInstrument(Tenor.ofYears(1), Pairs.of((Number) 0, FXVolQuoteType.ATM))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF25_1WK"), provider.getInstrument(Tenor.ofDays(7), Pairs.of((Number) 25, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF25_1M"), provider.getInstrument(Tenor.ofMonths(1), Pairs.of((Number) 25, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF25_1YR"), provider.getInstrument(Tenor.ofYears(1), Pairs.of((Number) 25, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF10_1WK"), provider.getInstrument(Tenor.ofDays(7), Pairs.of((Number) 10, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF10_1M"), provider.getInstrument(Tenor.ofMonths(1), Pairs.of((Number) 10, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDBF10_1YR"), provider.getInstrument(Tenor.ofYears(1), Pairs.of((Number) 10, FXVolQuoteType.BUTTERFLY))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR25_1WK"), provider.getInstrument( Tenor.ofDays(7), Pairs.of((Number) 25, FXVolQuoteType.RISK_REVERSAL))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR25_1M"), provider.getInstrument( Tenor.ofMonths(1), Pairs.of((Number) 25, FXVolQuoteType.RISK_REVERSAL))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR25_1YR"), provider.getInstrument( Tenor.ofYears(1), Pairs.of((Number) 25, FXVolQuoteType.RISK_REVERSAL))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR10_1WK"), provider.getInstrument( Tenor.ofDays(7), Pairs.of((Number) 10, FXVolQuoteType.RISK_REVERSAL))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR10_1M"), provider.getInstrument( Tenor.ofMonths(1), Pairs.of((Number) 10, FXVolQuoteType.RISK_REVERSAL))); assertEquals( ExternalId.of(ExternalSchemes.ICAP, "IEURUSDRR10_1YR"), provider.getInstrument( Tenor.ofYears(1), Pairs.of((Number) 10, FXVolQuoteType.RISK_REVERSAL))); }