/**
* Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.analytics.financial.provider.calculator.discounting;
import com.opengamma.analytics.financial.forex.derivative.Forex;
import com.opengamma.analytics.financial.forex.provider.ForexDiscountingMethod;
import com.opengamma.analytics.financial.interestrate.InstrumentDerivativeVisitorAdapter;
import com.opengamma.analytics.financial.interestrate.cash.derivative.Cash;
import com.opengamma.analytics.financial.interestrate.cash.derivative.DepositIbor;
import com.opengamma.analytics.financial.interestrate.cash.provider.CashDiscountingMethod;
import com.opengamma.analytics.financial.interestrate.cash.provider.DepositIborDiscountingMethod;
import com.opengamma.analytics.financial.interestrate.fra.derivative.ForwardRateAgreement;
import com.opengamma.analytics.financial.interestrate.fra.provider.ForwardRateAgreementDiscountingMethod;
import com.opengamma.analytics.financial.interestrate.future.derivative.InterestRateFutureSecurity;
import com.opengamma.analytics.financial.interestrate.future.derivative.InterestRateFutureTransaction;
import com.opengamma.analytics.financial.interestrate.future.provider.InterestRateFutureSecurityDiscountingMethod;
import com.opengamma.analytics.financial.interestrate.swap.derivative.SwapFixedCoupon;
import com.opengamma.analytics.financial.interestrate.swap.provider.SwapFixedCouponDiscountingMethod;
import com.opengamma.analytics.financial.provider.description.interestrate.ParameterProviderInterface;
/**
* Calculate the market quote of instruments in models using a multi-curve provider.
*/
public final class MarketQuoteDiscountingCalculator
extends InstrumentDerivativeVisitorAdapter<ParameterProviderInterface, Double> {
/**
* The unique instance of the calculator.
*/
private static final MarketQuoteDiscountingCalculator INSTANCE = new MarketQuoteDiscountingCalculator();
/**
* Constructor.
*/
private MarketQuoteDiscountingCalculator() {
}
/**
* Gets the calculator instance.
* @return The calculator.
*/
public static MarketQuoteDiscountingCalculator getInstance() {
return INSTANCE;
}
/** Pricing methods and calculators. */
private static final PresentValueDiscountingCalculator PVC = PresentValueDiscountingCalculator.getInstance();
private static final CashDiscountingMethod METHOD_DEPO = CashDiscountingMethod.getInstance();
private static final DepositIborDiscountingMethod METHOD_IBOR = DepositIborDiscountingMethod.getInstance();
private static final ForwardRateAgreementDiscountingMethod METHOD_FRA = ForwardRateAgreementDiscountingMethod.getInstance();
private static final SwapFixedCouponDiscountingMethod METHOD_SWAP = SwapFixedCouponDiscountingMethod.getInstance();
private static final InterestRateFutureSecurityDiscountingMethod METHOD_IR_FUT = InterestRateFutureSecurityDiscountingMethod.getInstance();
private static final ForexDiscountingMethod METHOD_FOREX = ForexDiscountingMethod.getInstance();
// ----- Deposit ------
@Override
public Double visitCash(final Cash deposit, final ParameterProviderInterface multicurves) {
return METHOD_DEPO.parRate(deposit, multicurves.getMulticurveProvider());
}
@Override
public Double visitDepositIbor(final DepositIbor deposit, final ParameterProviderInterface multicurves) {
return METHOD_IBOR.parRate(deposit, multicurves.getMulticurveProvider());
}
// ----- Payment/Coupon ------
@Override
public Double visitForwardRateAgreement(final ForwardRateAgreement fra, final ParameterProviderInterface multicurves) {
return METHOD_FRA.parRate(fra, multicurves.getMulticurveProvider());
}
/**
* Computes the par rate of a swap with one fixed leg.
* @param swap The Fixed coupon swap. The second leg can be of any type.
* @param multicurves The multi-curves provider.
* @return The par swap rate. If the fixed leg has been set up with some fixed payments these are ignored for the purposes of finding the swap rate
*/
@Override
public Double visitFixedCouponSwap(final SwapFixedCoupon<?> swap, final ParameterProviderInterface multicurves) {
//TODO: check currency
final double pvSecond = swap.getSecondLeg().accept(PVC, multicurves).getAmount(swap.getSecondLeg().getCurrency())
* Math.signum(swap.getSecondLeg().getNthPayment(0).getNotional());
final double pvbp = METHOD_SWAP.presentValueBasisPoint(swap, multicurves.getMulticurveProvider());
return pvSecond / pvbp;
}
// TODO: add generic swap? margin on first leg to get a pv=0
// ----- Futures -----
@Override
public Double visitInterestRateFutureSecurity(final InterestRateFutureSecurity futures, final ParameterProviderInterface multicurves) {
return METHOD_IR_FUT.price(futures, multicurves);
}
@Override
public Double visitInterestRateFutureTransaction(final InterestRateFutureTransaction futures, final ParameterProviderInterface multicurves) {
return METHOD_IR_FUT.price(futures.getUnderlyingSecurity(), multicurves);
}
// ----- Forex ------
/**
* Computes the forward forex rate.
* @param forex The forex instrument.
* @param multicurves The multicurves provider.
* @return The forward forex rate.
*/
@Override
public Double visitForex(final Forex forex, final ParameterProviderInterface multicurves) {
return METHOD_FOREX.forwardForexRate(forex, multicurves.getMulticurveProvider());
}
}