/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.sesame.sabr; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import org.joda.beans.Bean; import org.joda.beans.BeanDefinition; import org.joda.beans.ImmutableBean; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.Property; import org.joda.beans.PropertyDefinition; import org.joda.beans.impl.direct.DirectFieldsBeanBuilder; import org.joda.beans.impl.direct.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.analytics.math.interpolation.CombinedInterpolatorExtrapolator; import com.opengamma.analytics.math.interpolation.Interpolator1D; import com.opengamma.analytics.math.interpolation.Interpolator1DFactory; import com.opengamma.core.config.Config; /** * Joda bean config object that defines the interpolation * to be used with SABR surfaces when pricing a swaption. */ @BeanDefinition @Config(description = "SABR Swaption Interpolation", group = "SABR Params") public class SabrSwaptionInterpolationConfig implements ImmutableBean { /** * The name of the interpolator for tenor. */ @PropertyDefinition(validate = "notNull") private final String _tenorInterpolatorName; /** * The name of the left extrapolator for tenor. */ @PropertyDefinition(validate = "notNull") private final String _leftTenorExtrapolatorName; /** * The name of the right extrapolator for tenor. */ @PropertyDefinition(validate = "notNull") private final String _rightTenorExtrapolatorName; /** * The name of the interpolator for expiry. */ @PropertyDefinition(validate = "notNull") private final String _expiryInterpolatorName; /** * The name of the left extrapolator for expiry. */ @PropertyDefinition(validate = "notNull") private final String _leftExpiryExtrapolatorName; /** * The name of the right extrapolator for expiry. */ @PropertyDefinition(validate = "notNull") private final String _rightExpiryExtrapolatorName; /** * Creates a combined interpolator combining the requested interpolators * and extrapolators for Expiry. * * @return a combined interpolator, not null */ public Interpolator1D createCombinedExpiryInterpolator() { return new CombinedInterpolatorExtrapolator( Interpolator1DFactory.getInterpolator(_expiryInterpolatorName), Interpolator1DFactory.getInterpolator(_leftExpiryExtrapolatorName), Interpolator1DFactory.getInterpolator(_rightExpiryExtrapolatorName)); } /** * Creates a combined interpolator combining the requested interpolators * and extrapolators for Tenor. * * @return a combined interpolator, not null */ public Interpolator1D createCombinedTenorInterpolator() { return new CombinedInterpolatorExtrapolator( Interpolator1DFactory.getInterpolator(_tenorInterpolatorName), Interpolator1DFactory.getInterpolator(_leftTenorExtrapolatorName), Interpolator1DFactory.getInterpolator(_rightTenorExtrapolatorName)); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code SabrSwaptionInterpolationConfig}. * @return the meta-bean, not null */ public static SabrSwaptionInterpolationConfig.Meta meta() { return SabrSwaptionInterpolationConfig.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(SabrSwaptionInterpolationConfig.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static SabrSwaptionInterpolationConfig.Builder builder() { return new SabrSwaptionInterpolationConfig.Builder(); } /** * Restricted constructor. * @param builder the builder to copy from, not null */ protected SabrSwaptionInterpolationConfig(SabrSwaptionInterpolationConfig.Builder builder) { JodaBeanUtils.notNull(builder._tenorInterpolatorName, "tenorInterpolatorName"); JodaBeanUtils.notNull(builder._leftTenorExtrapolatorName, "leftTenorExtrapolatorName"); JodaBeanUtils.notNull(builder._rightTenorExtrapolatorName, "rightTenorExtrapolatorName"); JodaBeanUtils.notNull(builder._expiryInterpolatorName, "expiryInterpolatorName"); JodaBeanUtils.notNull(builder._leftExpiryExtrapolatorName, "leftExpiryExtrapolatorName"); JodaBeanUtils.notNull(builder._rightExpiryExtrapolatorName, "rightExpiryExtrapolatorName"); this._tenorInterpolatorName = builder._tenorInterpolatorName; this._leftTenorExtrapolatorName = builder._leftTenorExtrapolatorName; this._rightTenorExtrapolatorName = builder._rightTenorExtrapolatorName; this._expiryInterpolatorName = builder._expiryInterpolatorName; this._leftExpiryExtrapolatorName = builder._leftExpiryExtrapolatorName; this._rightExpiryExtrapolatorName = builder._rightExpiryExtrapolatorName; } @Override public SabrSwaptionInterpolationConfig.Meta metaBean() { return SabrSwaptionInterpolationConfig.Meta.INSTANCE; } @Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); } @Override public Set<String> propertyNames() { return metaBean().metaPropertyMap().keySet(); } //----------------------------------------------------------------------- /** * Gets the name of the interpolator for tenor. * @return the value of the property, not null */ public String getTenorInterpolatorName() { return _tenorInterpolatorName; } //----------------------------------------------------------------------- /** * Gets the name of the left extrapolator for tenor. * @return the value of the property, not null */ public String getLeftTenorExtrapolatorName() { return _leftTenorExtrapolatorName; } //----------------------------------------------------------------------- /** * Gets the name of the right extrapolator for tenor. * @return the value of the property, not null */ public String getRightTenorExtrapolatorName() { return _rightTenorExtrapolatorName; } //----------------------------------------------------------------------- /** * Gets the name of the interpolator for expiry. * @return the value of the property, not null */ public String getExpiryInterpolatorName() { return _expiryInterpolatorName; } //----------------------------------------------------------------------- /** * Gets the name of the left extrapolator for expiry. * @return the value of the property, not null */ public String getLeftExpiryExtrapolatorName() { return _leftExpiryExtrapolatorName; } //----------------------------------------------------------------------- /** * Gets the name of the right extrapolator for expiry. * @return the value of the property, not null */ public String getRightExpiryExtrapolatorName() { return _rightExpiryExtrapolatorName; } //----------------------------------------------------------------------- /** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { SabrSwaptionInterpolationConfig other = (SabrSwaptionInterpolationConfig) obj; return JodaBeanUtils.equal(getTenorInterpolatorName(), other.getTenorInterpolatorName()) && JodaBeanUtils.equal(getLeftTenorExtrapolatorName(), other.getLeftTenorExtrapolatorName()) && JodaBeanUtils.equal(getRightTenorExtrapolatorName(), other.getRightTenorExtrapolatorName()) && JodaBeanUtils.equal(getExpiryInterpolatorName(), other.getExpiryInterpolatorName()) && JodaBeanUtils.equal(getLeftExpiryExtrapolatorName(), other.getLeftExpiryExtrapolatorName()) && JodaBeanUtils.equal(getRightExpiryExtrapolatorName(), other.getRightExpiryExtrapolatorName()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getTenorInterpolatorName()); hash = hash * 31 + JodaBeanUtils.hashCode(getLeftTenorExtrapolatorName()); hash = hash * 31 + JodaBeanUtils.hashCode(getRightTenorExtrapolatorName()); hash = hash * 31 + JodaBeanUtils.hashCode(getExpiryInterpolatorName()); hash = hash * 31 + JodaBeanUtils.hashCode(getLeftExpiryExtrapolatorName()); hash = hash * 31 + JodaBeanUtils.hashCode(getRightExpiryExtrapolatorName()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(224); buf.append("SabrSwaptionInterpolationConfig{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("tenorInterpolatorName").append('=').append(JodaBeanUtils.toString(getTenorInterpolatorName())).append(',').append(' '); buf.append("leftTenorExtrapolatorName").append('=').append(JodaBeanUtils.toString(getLeftTenorExtrapolatorName())).append(',').append(' '); buf.append("rightTenorExtrapolatorName").append('=').append(JodaBeanUtils.toString(getRightTenorExtrapolatorName())).append(',').append(' '); buf.append("expiryInterpolatorName").append('=').append(JodaBeanUtils.toString(getExpiryInterpolatorName())).append(',').append(' '); buf.append("leftExpiryExtrapolatorName").append('=').append(JodaBeanUtils.toString(getLeftExpiryExtrapolatorName())).append(',').append(' '); buf.append("rightExpiryExtrapolatorName").append('=').append(JodaBeanUtils.toString(getRightExpiryExtrapolatorName())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code SabrSwaptionInterpolationConfig}. */ public static class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code tenorInterpolatorName} property. */ private final MetaProperty<String> _tenorInterpolatorName = DirectMetaProperty.ofImmutable( this, "tenorInterpolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-property for the {@code leftTenorExtrapolatorName} property. */ private final MetaProperty<String> _leftTenorExtrapolatorName = DirectMetaProperty.ofImmutable( this, "leftTenorExtrapolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-property for the {@code rightTenorExtrapolatorName} property. */ private final MetaProperty<String> _rightTenorExtrapolatorName = DirectMetaProperty.ofImmutable( this, "rightTenorExtrapolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-property for the {@code expiryInterpolatorName} property. */ private final MetaProperty<String> _expiryInterpolatorName = DirectMetaProperty.ofImmutable( this, "expiryInterpolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-property for the {@code leftExpiryExtrapolatorName} property. */ private final MetaProperty<String> _leftExpiryExtrapolatorName = DirectMetaProperty.ofImmutable( this, "leftExpiryExtrapolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-property for the {@code rightExpiryExtrapolatorName} property. */ private final MetaProperty<String> _rightExpiryExtrapolatorName = DirectMetaProperty.ofImmutable( this, "rightExpiryExtrapolatorName", SabrSwaptionInterpolationConfig.class, String.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "tenorInterpolatorName", "leftTenorExtrapolatorName", "rightTenorExtrapolatorName", "expiryInterpolatorName", "leftExpiryExtrapolatorName", "rightExpiryExtrapolatorName"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 565213906: // tenorInterpolatorName return _tenorInterpolatorName; case -636400297: // leftTenorExtrapolatorName return _leftTenorExtrapolatorName; case -1397900702: // rightTenorExtrapolatorName return _rightTenorExtrapolatorName; case -657328315: // expiryInterpolatorName return _expiryInterpolatorName; case -1810465672: // leftExpiryExtrapolatorName return _leftExpiryExtrapolatorName; case 352825549: // rightExpiryExtrapolatorName return _rightExpiryExtrapolatorName; } return super.metaPropertyGet(propertyName); } @Override public SabrSwaptionInterpolationConfig.Builder builder() { return new SabrSwaptionInterpolationConfig.Builder(); } @Override public Class<? extends SabrSwaptionInterpolationConfig> beanType() { return SabrSwaptionInterpolationConfig.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code tenorInterpolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> tenorInterpolatorName() { return _tenorInterpolatorName; } /** * The meta-property for the {@code leftTenorExtrapolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> leftTenorExtrapolatorName() { return _leftTenorExtrapolatorName; } /** * The meta-property for the {@code rightTenorExtrapolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> rightTenorExtrapolatorName() { return _rightTenorExtrapolatorName; } /** * The meta-property for the {@code expiryInterpolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> expiryInterpolatorName() { return _expiryInterpolatorName; } /** * The meta-property for the {@code leftExpiryExtrapolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> leftExpiryExtrapolatorName() { return _leftExpiryExtrapolatorName; } /** * The meta-property for the {@code rightExpiryExtrapolatorName} property. * @return the meta-property, not null */ public final MetaProperty<String> rightExpiryExtrapolatorName() { return _rightExpiryExtrapolatorName; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 565213906: // tenorInterpolatorName return ((SabrSwaptionInterpolationConfig) bean).getTenorInterpolatorName(); case -636400297: // leftTenorExtrapolatorName return ((SabrSwaptionInterpolationConfig) bean).getLeftTenorExtrapolatorName(); case -1397900702: // rightTenorExtrapolatorName return ((SabrSwaptionInterpolationConfig) bean).getRightTenorExtrapolatorName(); case -657328315: // expiryInterpolatorName return ((SabrSwaptionInterpolationConfig) bean).getExpiryInterpolatorName(); case -1810465672: // leftExpiryExtrapolatorName return ((SabrSwaptionInterpolationConfig) bean).getLeftExpiryExtrapolatorName(); case 352825549: // rightExpiryExtrapolatorName return ((SabrSwaptionInterpolationConfig) bean).getRightExpiryExtrapolatorName(); } 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 SabrSwaptionInterpolationConfig}. */ public static class Builder extends DirectFieldsBeanBuilder<SabrSwaptionInterpolationConfig> { private String _tenorInterpolatorName; private String _leftTenorExtrapolatorName; private String _rightTenorExtrapolatorName; private String _expiryInterpolatorName; private String _leftExpiryExtrapolatorName; private String _rightExpiryExtrapolatorName; /** * Restricted constructor. */ protected Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ protected Builder(SabrSwaptionInterpolationConfig beanToCopy) { this._tenorInterpolatorName = beanToCopy.getTenorInterpolatorName(); this._leftTenorExtrapolatorName = beanToCopy.getLeftTenorExtrapolatorName(); this._rightTenorExtrapolatorName = beanToCopy.getRightTenorExtrapolatorName(); this._expiryInterpolatorName = beanToCopy.getExpiryInterpolatorName(); this._leftExpiryExtrapolatorName = beanToCopy.getLeftExpiryExtrapolatorName(); this._rightExpiryExtrapolatorName = beanToCopy.getRightExpiryExtrapolatorName(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 565213906: // tenorInterpolatorName return _tenorInterpolatorName; case -636400297: // leftTenorExtrapolatorName return _leftTenorExtrapolatorName; case -1397900702: // rightTenorExtrapolatorName return _rightTenorExtrapolatorName; case -657328315: // expiryInterpolatorName return _expiryInterpolatorName; case -1810465672: // leftExpiryExtrapolatorName return _leftExpiryExtrapolatorName; case 352825549: // rightExpiryExtrapolatorName return _rightExpiryExtrapolatorName; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case 565213906: // tenorInterpolatorName this._tenorInterpolatorName = (String) newValue; break; case -636400297: // leftTenorExtrapolatorName this._leftTenorExtrapolatorName = (String) newValue; break; case -1397900702: // rightTenorExtrapolatorName this._rightTenorExtrapolatorName = (String) newValue; break; case -657328315: // expiryInterpolatorName this._expiryInterpolatorName = (String) newValue; break; case -1810465672: // leftExpiryExtrapolatorName this._leftExpiryExtrapolatorName = (String) newValue; break; case 352825549: // rightExpiryExtrapolatorName this._rightExpiryExtrapolatorName = (String) newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return this; } @Override public Builder set(MetaProperty<?> property, Object value) { super.set(property, value); return this; } @Override public Builder setString(String propertyName, String value) { setString(meta().metaProperty(propertyName), value); return this; } @Override public Builder setString(MetaProperty<?> property, String value) { super.setString(property, value); return this; } @Override public Builder setAll(Map<String, ? extends Object> propertyValueMap) { super.setAll(propertyValueMap); return this; } @Override public SabrSwaptionInterpolationConfig build() { return new SabrSwaptionInterpolationConfig(this); } //----------------------------------------------------------------------- /** * Sets the {@code tenorInterpolatorName} property in the builder. * @param tenorInterpolatorName the new value, not null * @return this, for chaining, not null */ public Builder tenorInterpolatorName(String tenorInterpolatorName) { JodaBeanUtils.notNull(tenorInterpolatorName, "tenorInterpolatorName"); this._tenorInterpolatorName = tenorInterpolatorName; return this; } /** * Sets the {@code leftTenorExtrapolatorName} property in the builder. * @param leftTenorExtrapolatorName the new value, not null * @return this, for chaining, not null */ public Builder leftTenorExtrapolatorName(String leftTenorExtrapolatorName) { JodaBeanUtils.notNull(leftTenorExtrapolatorName, "leftTenorExtrapolatorName"); this._leftTenorExtrapolatorName = leftTenorExtrapolatorName; return this; } /** * Sets the {@code rightTenorExtrapolatorName} property in the builder. * @param rightTenorExtrapolatorName the new value, not null * @return this, for chaining, not null */ public Builder rightTenorExtrapolatorName(String rightTenorExtrapolatorName) { JodaBeanUtils.notNull(rightTenorExtrapolatorName, "rightTenorExtrapolatorName"); this._rightTenorExtrapolatorName = rightTenorExtrapolatorName; return this; } /** * Sets the {@code expiryInterpolatorName} property in the builder. * @param expiryInterpolatorName the new value, not null * @return this, for chaining, not null */ public Builder expiryInterpolatorName(String expiryInterpolatorName) { JodaBeanUtils.notNull(expiryInterpolatorName, "expiryInterpolatorName"); this._expiryInterpolatorName = expiryInterpolatorName; return this; } /** * Sets the {@code leftExpiryExtrapolatorName} property in the builder. * @param leftExpiryExtrapolatorName the new value, not null * @return this, for chaining, not null */ public Builder leftExpiryExtrapolatorName(String leftExpiryExtrapolatorName) { JodaBeanUtils.notNull(leftExpiryExtrapolatorName, "leftExpiryExtrapolatorName"); this._leftExpiryExtrapolatorName = leftExpiryExtrapolatorName; return this; } /** * Sets the {@code rightExpiryExtrapolatorName} property in the builder. * @param rightExpiryExtrapolatorName the new value, not null * @return this, for chaining, not null */ public Builder rightExpiryExtrapolatorName(String rightExpiryExtrapolatorName) { JodaBeanUtils.notNull(rightExpiryExtrapolatorName, "rightExpiryExtrapolatorName"); this._rightExpiryExtrapolatorName = rightExpiryExtrapolatorName; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(224); buf.append("SabrSwaptionInterpolationConfig.Builder{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("tenorInterpolatorName").append('=').append(JodaBeanUtils.toString(_tenorInterpolatorName)).append(',').append(' '); buf.append("leftTenorExtrapolatorName").append('=').append(JodaBeanUtils.toString(_leftTenorExtrapolatorName)).append(',').append(' '); buf.append("rightTenorExtrapolatorName").append('=').append(JodaBeanUtils.toString(_rightTenorExtrapolatorName)).append(',').append(' '); buf.append("expiryInterpolatorName").append('=').append(JodaBeanUtils.toString(_expiryInterpolatorName)).append(',').append(' '); buf.append("leftExpiryExtrapolatorName").append('=').append(JodaBeanUtils.toString(_leftExpiryExtrapolatorName)).append(',').append(' '); buf.append("rightExpiryExtrapolatorName").append('=').append(JodaBeanUtils.toString(_rightExpiryExtrapolatorName)).append(',').append(' '); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }