com.opengamma.strata.pricer.index.IborFutureOptionSensitivity Maven / Gradle / Ivy
/*
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.pricer.index;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.DoubleUnaryOperator;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.joda.beans.impl.direct.DirectPrivateBeanBuilder;
import com.google.common.collect.ComparisonChain;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.basics.currency.FxRateProvider;
import com.opengamma.strata.market.sensitivity.MutablePointSensitivities;
import com.opengamma.strata.market.sensitivity.PointSensitivity;
import com.opengamma.strata.market.sensitivity.PointSensitivityBuilder;
/**
* Point sensitivity to an implied volatility for a Ibor future option model.
*
* Holds the sensitivity to a specific volatility point.
*/
@BeanDefinition(builderScope = "private")
public final class IborFutureOptionSensitivity
implements PointSensitivity, PointSensitivityBuilder, ImmutableBean, Serializable {
/**
* The name of the volatilities.
*/
@PropertyDefinition(validate = "notNull")
private final IborFutureOptionVolatilitiesName volatilitiesName;
/**
* The time to expiry of the option as a year fraction.
*/
@PropertyDefinition(validate = "notNull")
private final double expiry;
/**
* The fixing date of the underlying future.
*/
@PropertyDefinition(validate = "notNull")
private final LocalDate fixingDate;
/**
* The option strike price.
*/
@PropertyDefinition
private final double strikePrice;
/**
* The underlying future price.
*/
@PropertyDefinition
private final double futurePrice;
/**
* The currency of the sensitivity.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final Currency currency;
/**
* The value of the sensitivity.
*/
@PropertyDefinition(overrideGet = true)
private final double sensitivity;
//-------------------------------------------------------------------------
/**
* Obtains an instance.
*
* @param volatilitiesName the name of the volatilities
* @param expiry the expiry date-time of the option as a year fraction
* @param fixingDate the fixing date of the underlying future
* @param strikePrice the strike price of the option
* @param futurePrice the price of the underlying future
* @param sensitivityCurrency the currency of the sensitivity
* @param sensitivity the value of the sensitivity
* @return the point sensitivity object
*/
public static IborFutureOptionSensitivity of(
IborFutureOptionVolatilitiesName volatilitiesName,
double expiry,
LocalDate fixingDate,
double strikePrice,
double futurePrice,
Currency sensitivityCurrency,
double sensitivity) {
return new IborFutureOptionSensitivity(
volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, sensitivityCurrency, sensitivity);
}
//-------------------------------------------------------------------------
@Override
public IborFutureOptionSensitivity withCurrency(Currency currency) {
if (this.currency.equals(currency)) {
return this;
}
return new IborFutureOptionSensitivity(
volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, currency, sensitivity);
}
@Override
public IborFutureOptionSensitivity withSensitivity(double sensitivity) {
return new IborFutureOptionSensitivity(
volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, currency, sensitivity);
}
@Override
public int compareKey(PointSensitivity other) {
if (other instanceof IborFutureOptionSensitivity) {
IborFutureOptionSensitivity otherOption = (IborFutureOptionSensitivity) other;
return ComparisonChain.start()
.compare(volatilitiesName, otherOption.volatilitiesName)
.compare(currency, otherOption.currency)
.compare(expiry, otherOption.expiry)
.compare(fixingDate, otherOption.fixingDate)
.compare(strikePrice, otherOption.strikePrice)
.compare(futurePrice, otherOption.futurePrice)
.result();
}
return getClass().getSimpleName().compareTo(other.getClass().getSimpleName());
}
@Override
public IborFutureOptionSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) {
return (IborFutureOptionSensitivity) PointSensitivity.super.convertedTo(resultCurrency, rateProvider);
}
//-------------------------------------------------------------------------
@Override
public IborFutureOptionSensitivity multipliedBy(double factor) {
return new IborFutureOptionSensitivity(
volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, currency, sensitivity * factor);
}
@Override
public IborFutureOptionSensitivity mapSensitivity(DoubleUnaryOperator operator) {
return new IborFutureOptionSensitivity(
volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, currency, operator.applyAsDouble(sensitivity));
}
@Override
public IborFutureOptionSensitivity normalize() {
return this;
}
@Override
public MutablePointSensitivities buildInto(MutablePointSensitivities combination) {
return combination.add(this);
}
@Override
public IborFutureOptionSensitivity cloned() {
return this;
}
//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code IborFutureOptionSensitivity}.
* @return the meta-bean, not null
*/
public static IborFutureOptionSensitivity.Meta meta() {
return IborFutureOptionSensitivity.Meta.INSTANCE;
}
static {
MetaBean.register(IborFutureOptionSensitivity.Meta.INSTANCE);
}
/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;
private IborFutureOptionSensitivity(
IborFutureOptionVolatilitiesName volatilitiesName,
double expiry,
LocalDate fixingDate,
double strikePrice,
double futurePrice,
Currency currency,
double sensitivity) {
JodaBeanUtils.notNull(volatilitiesName, "volatilitiesName");
JodaBeanUtils.notNull(expiry, "expiry");
JodaBeanUtils.notNull(fixingDate, "fixingDate");
JodaBeanUtils.notNull(currency, "currency");
this.volatilitiesName = volatilitiesName;
this.expiry = expiry;
this.fixingDate = fixingDate;
this.strikePrice = strikePrice;
this.futurePrice = futurePrice;
this.currency = currency;
this.sensitivity = sensitivity;
}
@Override
public IborFutureOptionSensitivity.Meta metaBean() {
return IborFutureOptionSensitivity.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the name of the volatilities.
* @return the value of the property, not null
*/
public IborFutureOptionVolatilitiesName getVolatilitiesName() {
return volatilitiesName;
}
//-----------------------------------------------------------------------
/**
* Gets the time to expiry of the option as a year fraction.
* @return the value of the property, not null
*/
public double getExpiry() {
return expiry;
}
//-----------------------------------------------------------------------
/**
* Gets the fixing date of the underlying future.
* @return the value of the property, not null
*/
public LocalDate getFixingDate() {
return fixingDate;
}
//-----------------------------------------------------------------------
/**
* Gets the option strike price.
* @return the value of the property
*/
public double getStrikePrice() {
return strikePrice;
}
//-----------------------------------------------------------------------
/**
* Gets the underlying future price.
* @return the value of the property
*/
public double getFuturePrice() {
return futurePrice;
}
//-----------------------------------------------------------------------
/**
* Gets the currency of the sensitivity.
* @return the value of the property, not null
*/
@Override
public Currency getCurrency() {
return currency;
}
//-----------------------------------------------------------------------
/**
* Gets the value of the sensitivity.
* @return the value of the property
*/
@Override
public double getSensitivity() {
return sensitivity;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
IborFutureOptionSensitivity other = (IborFutureOptionSensitivity) obj;
return JodaBeanUtils.equal(volatilitiesName, other.volatilitiesName) &&
JodaBeanUtils.equal(expiry, other.expiry) &&
JodaBeanUtils.equal(fixingDate, other.fixingDate) &&
JodaBeanUtils.equal(strikePrice, other.strikePrice) &&
JodaBeanUtils.equal(futurePrice, other.futurePrice) &&
JodaBeanUtils.equal(currency, other.currency) &&
JodaBeanUtils.equal(sensitivity, other.sensitivity);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(volatilitiesName);
hash = hash * 31 + JodaBeanUtils.hashCode(expiry);
hash = hash * 31 + JodaBeanUtils.hashCode(fixingDate);
hash = hash * 31 + JodaBeanUtils.hashCode(strikePrice);
hash = hash * 31 + JodaBeanUtils.hashCode(futurePrice);
hash = hash * 31 + JodaBeanUtils.hashCode(currency);
hash = hash * 31 + JodaBeanUtils.hashCode(sensitivity);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(256);
buf.append("IborFutureOptionSensitivity{");
buf.append("volatilitiesName").append('=').append(JodaBeanUtils.toString(volatilitiesName)).append(',').append(' ');
buf.append("expiry").append('=').append(JodaBeanUtils.toString(expiry)).append(',').append(' ');
buf.append("fixingDate").append('=').append(JodaBeanUtils.toString(fixingDate)).append(',').append(' ');
buf.append("strikePrice").append('=').append(JodaBeanUtils.toString(strikePrice)).append(',').append(' ');
buf.append("futurePrice").append('=').append(JodaBeanUtils.toString(futurePrice)).append(',').append(' ');
buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
buf.append("sensitivity").append('=').append(JodaBeanUtils.toString(sensitivity));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code IborFutureOptionSensitivity}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code volatilitiesName} property.
*/
private final MetaProperty volatilitiesName = DirectMetaProperty.ofImmutable(
this, "volatilitiesName", IborFutureOptionSensitivity.class, IborFutureOptionVolatilitiesName.class);
/**
* The meta-property for the {@code expiry} property.
*/
private final MetaProperty expiry = DirectMetaProperty.ofImmutable(
this, "expiry", IborFutureOptionSensitivity.class, Double.TYPE);
/**
* The meta-property for the {@code fixingDate} property.
*/
private final MetaProperty fixingDate = DirectMetaProperty.ofImmutable(
this, "fixingDate", IborFutureOptionSensitivity.class, LocalDate.class);
/**
* The meta-property for the {@code strikePrice} property.
*/
private final MetaProperty strikePrice = DirectMetaProperty.ofImmutable(
this, "strikePrice", IborFutureOptionSensitivity.class, Double.TYPE);
/**
* The meta-property for the {@code futurePrice} property.
*/
private final MetaProperty futurePrice = DirectMetaProperty.ofImmutable(
this, "futurePrice", IborFutureOptionSensitivity.class, Double.TYPE);
/**
* The meta-property for the {@code currency} property.
*/
private final MetaProperty currency = DirectMetaProperty.ofImmutable(
this, "currency", IborFutureOptionSensitivity.class, Currency.class);
/**
* The meta-property for the {@code sensitivity} property.
*/
private final MetaProperty sensitivity = DirectMetaProperty.ofImmutable(
this, "sensitivity", IborFutureOptionSensitivity.class, Double.TYPE);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"volatilitiesName",
"expiry",
"fixingDate",
"strikePrice",
"futurePrice",
"currency",
"sensitivity");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 2100884654: // volatilitiesName
return volatilitiesName;
case -1289159373: // expiry
return expiry;
case 1255202043: // fixingDate
return fixingDate;
case 50946231: // strikePrice
return strikePrice;
case -518499002: // futurePrice
return futurePrice;
case 575402001: // currency
return currency;
case 564403871: // sensitivity
return sensitivity;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder extends IborFutureOptionSensitivity> builder() {
return new IborFutureOptionSensitivity.Builder();
}
@Override
public Class extends IborFutureOptionSensitivity> beanType() {
return IborFutureOptionSensitivity.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code volatilitiesName} property.
* @return the meta-property, not null
*/
public MetaProperty volatilitiesName() {
return volatilitiesName;
}
/**
* The meta-property for the {@code expiry} property.
* @return the meta-property, not null
*/
public MetaProperty expiry() {
return expiry;
}
/**
* The meta-property for the {@code fixingDate} property.
* @return the meta-property, not null
*/
public MetaProperty fixingDate() {
return fixingDate;
}
/**
* The meta-property for the {@code strikePrice} property.
* @return the meta-property, not null
*/
public MetaProperty strikePrice() {
return strikePrice;
}
/**
* The meta-property for the {@code futurePrice} property.
* @return the meta-property, not null
*/
public MetaProperty futurePrice() {
return futurePrice;
}
/**
* The meta-property for the {@code currency} property.
* @return the meta-property, not null
*/
public MetaProperty currency() {
return currency;
}
/**
* The meta-property for the {@code sensitivity} property.
* @return the meta-property, not null
*/
public MetaProperty sensitivity() {
return sensitivity;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 2100884654: // volatilitiesName
return ((IborFutureOptionSensitivity) bean).getVolatilitiesName();
case -1289159373: // expiry
return ((IborFutureOptionSensitivity) bean).getExpiry();
case 1255202043: // fixingDate
return ((IborFutureOptionSensitivity) bean).getFixingDate();
case 50946231: // strikePrice
return ((IborFutureOptionSensitivity) bean).getStrikePrice();
case -518499002: // futurePrice
return ((IborFutureOptionSensitivity) bean).getFuturePrice();
case 575402001: // currency
return ((IborFutureOptionSensitivity) bean).getCurrency();
case 564403871: // sensitivity
return ((IborFutureOptionSensitivity) bean).getSensitivity();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code IborFutureOptionSensitivity}.
*/
private static final class Builder extends DirectPrivateBeanBuilder {
private IborFutureOptionVolatilitiesName volatilitiesName;
private double expiry;
private LocalDate fixingDate;
private double strikePrice;
private double futurePrice;
private Currency currency;
private double sensitivity;
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 2100884654: // volatilitiesName
return volatilitiesName;
case -1289159373: // expiry
return expiry;
case 1255202043: // fixingDate
return fixingDate;
case 50946231: // strikePrice
return strikePrice;
case -518499002: // futurePrice
return futurePrice;
case 575402001: // currency
return currency;
case 564403871: // sensitivity
return sensitivity;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 2100884654: // volatilitiesName
this.volatilitiesName = (IborFutureOptionVolatilitiesName) newValue;
break;
case -1289159373: // expiry
this.expiry = (Double) newValue;
break;
case 1255202043: // fixingDate
this.fixingDate = (LocalDate) newValue;
break;
case 50946231: // strikePrice
this.strikePrice = (Double) newValue;
break;
case -518499002: // futurePrice
this.futurePrice = (Double) newValue;
break;
case 575402001: // currency
this.currency = (Currency) newValue;
break;
case 564403871: // sensitivity
this.sensitivity = (Double) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public IborFutureOptionSensitivity build() {
return new IborFutureOptionSensitivity(
volatilitiesName,
expiry,
fixingDate,
strikePrice,
futurePrice,
currency,
sensitivity);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(256);
buf.append("IborFutureOptionSensitivity.Builder{");
buf.append("volatilitiesName").append('=').append(JodaBeanUtils.toString(volatilitiesName)).append(',').append(' ');
buf.append("expiry").append('=').append(JodaBeanUtils.toString(expiry)).append(',').append(' ');
buf.append("fixingDate").append('=').append(JodaBeanUtils.toString(fixingDate)).append(',').append(' ');
buf.append("strikePrice").append('=').append(JodaBeanUtils.toString(strikePrice)).append(',').append(' ');
buf.append("futurePrice").append('=').append(JodaBeanUtils.toString(futurePrice)).append(',').append(' ');
buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
buf.append("sensitivity").append('=').append(JodaBeanUtils.toString(sensitivity));
buf.append('}');
return buf.toString();
}
}
//-------------------------- AUTOGENERATED END --------------------------
}