/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.analytics.volatility.cube; import java.text.DecimalFormat; import java.text.Format; import java.util.Map; import java.util.Set; import org.joda.beans.Bean; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; 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.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.core.id.ExternalSchemes; import com.opengamma.core.value.MarketDataRequirementNames; import com.opengamma.id.ExternalId; import com.opengamma.util.time.Tenor; /** * Generates {@link ExternalId}s for the swaption vol cube tickers in the simulated market data files. */ @BeanDefinition public class ExampleSwaptionVolatilityCubeInstrumentProvider implements Bean, CubeInstrumentProvider<Tenor, Tenor, Double> { /** The serialization version */ private static final long serialVersionUID = 1L; /** * The instrument name. */ private static final String INSTRUMENT = "SWAPTIONVOL"; /** * The relative strike formatter. */ private static final Format FORMATTER = new DecimalFormat("##0.0"); /** * The positive spread prefix. */ private static final String POSITIVE = "P"; /** * The negative spread prefix. */ private static final String NEGATIVE = "N"; /** * The currency. */ @PropertyDefinition(validate = "notNull") private String _currency; /** * For the builder. */ /* package */ ExampleSwaptionVolatilityCubeInstrumentProvider() { } /** * @param currency The currency string, not null */ public ExampleSwaptionVolatilityCubeInstrumentProvider(final String currency) { setCurrency(currency); } @Override public ExternalId getInstrument(final Tenor expiry, final Tenor maturity, final Double relativeStrike) { final StringBuilder sb = new StringBuilder(_currency); sb.append(INSTRUMENT); sb.append(expiry.getPeriod().toString().substring(1)); sb.append(maturity.getPeriod().toString().substring(1)); if (relativeStrike < 0) { sb.append(NEGATIVE); sb.append(FORMATTER.format(Math.abs(relativeStrike))); } else { sb.append(POSITIVE); sb.append(FORMATTER.format(relativeStrike)); } return ExternalSchemes.syntheticSecurityId(sb.toString()); } @Override public String getDataFieldName() { return MarketDataRequirementNames.MARKET_VALUE; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code ExampleSwaptionVolatilityCubeInstrumentProvider}. * @return the meta-bean, not null */ public static ExampleSwaptionVolatilityCubeInstrumentProvider.Meta meta() { return ExampleSwaptionVolatilityCubeInstrumentProvider.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(ExampleSwaptionVolatilityCubeInstrumentProvider.Meta.INSTANCE); } @Override public ExampleSwaptionVolatilityCubeInstrumentProvider.Meta metaBean() { return ExampleSwaptionVolatilityCubeInstrumentProvider.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 currency. * @return the value of the property, not null */ public String getCurrency() { return _currency; } /** * Sets the currency. * @param currency the new value of the property, not null */ public void setCurrency(String currency) { JodaBeanUtils.notNull(currency, "currency"); this._currency = currency; } /** * Gets the the {@code currency} property. * @return the property, not null */ public final Property<String> currency() { return metaBean().currency().createProperty(this); } //----------------------------------------------------------------------- @Override public ExampleSwaptionVolatilityCubeInstrumentProvider clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { ExampleSwaptionVolatilityCubeInstrumentProvider other = (ExampleSwaptionVolatilityCubeInstrumentProvider) obj; return JodaBeanUtils.equal(getCurrency(), other.getCurrency()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getCurrency()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("ExampleSwaptionVolatilityCubeInstrumentProvider{"); 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("currency").append('=').append(JodaBeanUtils.toString(getCurrency())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code ExampleSwaptionVolatilityCubeInstrumentProvider}. */ 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 currency} property. */ private final MetaProperty<String> _currency = DirectMetaProperty.ofReadWrite( this, "currency", ExampleSwaptionVolatilityCubeInstrumentProvider.class, String.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "currency"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 575402001: // currency return _currency; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends ExampleSwaptionVolatilityCubeInstrumentProvider> builder() { return new DirectBeanBuilder<ExampleSwaptionVolatilityCubeInstrumentProvider>(new ExampleSwaptionVolatilityCubeInstrumentProvider()); } @Override public Class<? extends ExampleSwaptionVolatilityCubeInstrumentProvider> beanType() { return ExampleSwaptionVolatilityCubeInstrumentProvider.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code currency} property. * @return the meta-property, not null */ public final MetaProperty<String> currency() { return _currency; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((ExampleSwaptionVolatilityCubeInstrumentProvider) bean).getCurrency(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency ((ExampleSwaptionVolatilityCubeInstrumentProvider) bean).setCurrency((String) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((ExampleSwaptionVolatilityCubeInstrumentProvider) bean)._currency, "currency"); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }