/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.volatility.cube;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
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.DirectBean;
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.config.Config;
import com.opengamma.core.marketdatasnapshot.VolatilityPoint;
import com.opengamma.id.MutableUniqueIdentifiable;
import com.opengamma.id.UniqueId;
import com.opengamma.id.UniqueIdentifiable;
import com.opengamma.util.time.Tenor;
/**
*
*/
@Config(description = "Volatility cube definition")
@BeanDefinition
public class VolatilityCubeDefinition extends DirectBean implements UniqueIdentifiable, MutableUniqueIdentifiable {
/**
* The swap tenors
*/
@PropertyDefinition
private UniqueId _uniqueId;
/**
* The swap tenors
*/
@PropertyDefinition
private List<Tenor> _swapTenors;
/**
* The option expiries
*/
@PropertyDefinition
private List<Tenor> _optionExpiries;
/**
* The strikes relative to at the money, in Basis points
*/
@PropertyDefinition
private List<Double> _relativeStrikes;
public Iterable<VolatilityPoint> getAllPoints() {
final int size = _swapTenors.size() * _optionExpiries.size() * _relativeStrikes.size();
return new AbstractList<VolatilityPoint>() {
@Override
public VolatilityPoint get(int index) {
int swapI = index % _swapTenors.size();
int remainder = index / _swapTenors.size();
int optionI = remainder % _optionExpiries.size();
remainder = remainder / _optionExpiries.size();
int strikeI = remainder;
return new VolatilityPoint(_swapTenors.get(swapI), _optionExpiries.get(optionI), _relativeStrikes.get(strikeI).doubleValue());
}
@Override
public int size() {
return size;
}
};
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code VolatilityCubeDefinition}.
* @return the meta-bean, not null
*/
public static VolatilityCubeDefinition.Meta meta() {
return VolatilityCubeDefinition.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(VolatilityCubeDefinition.Meta.INSTANCE);
}
@Override
public VolatilityCubeDefinition.Meta metaBean() {
return VolatilityCubeDefinition.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return getUniqueId();
case -1091346138: // swapTenors
return getSwapTenors();
case 146928806: // optionExpiries
return getOptionExpiries();
case -1711425899: // relativeStrikes
return getRelativeStrikes();
}
return super.propertyGet(propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
setUniqueId((UniqueId) newValue);
return;
case -1091346138: // swapTenors
setSwapTenors((List<Tenor>) newValue);
return;
case 146928806: // optionExpiries
setOptionExpiries((List<Tenor>) newValue);
return;
case -1711425899: // relativeStrikes
setRelativeStrikes((List<Double>) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
VolatilityCubeDefinition other = (VolatilityCubeDefinition) obj;
return JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) &&
JodaBeanUtils.equal(getSwapTenors(), other.getSwapTenors()) &&
JodaBeanUtils.equal(getOptionExpiries(), other.getOptionExpiries()) &&
JodaBeanUtils.equal(getRelativeStrikes(), other.getRelativeStrikes());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash += hash * 31 + JodaBeanUtils.hashCode(getUniqueId());
hash += hash * 31 + JodaBeanUtils.hashCode(getSwapTenors());
hash += hash * 31 + JodaBeanUtils.hashCode(getOptionExpiries());
hash += hash * 31 + JodaBeanUtils.hashCode(getRelativeStrikes());
return hash;
}
//-----------------------------------------------------------------------
/**
* Gets the swap tenors
* @return the value of the property
*/
public UniqueId getUniqueId() {
return _uniqueId;
}
/**
* Sets the swap tenors
* @param uniqueId the new value of the property
*/
public void setUniqueId(UniqueId uniqueId) {
this._uniqueId = uniqueId;
}
/**
* Gets the the {@code uniqueId} property.
* @return the property, not null
*/
public final Property<UniqueId> uniqueId() {
return metaBean().uniqueId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the swap tenors
* @return the value of the property
*/
public List<Tenor> getSwapTenors() {
return _swapTenors;
}
/**
* Sets the swap tenors
* @param swapTenors the new value of the property
*/
public void setSwapTenors(List<Tenor> swapTenors) {
this._swapTenors = swapTenors;
}
/**
* Gets the the {@code swapTenors} property.
* @return the property, not null
*/
public final Property<List<Tenor>> swapTenors() {
return metaBean().swapTenors().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the option expiries
* @return the value of the property
*/
public List<Tenor> getOptionExpiries() {
return _optionExpiries;
}
/**
* Sets the option expiries
* @param optionExpiries the new value of the property
*/
public void setOptionExpiries(List<Tenor> optionExpiries) {
this._optionExpiries = optionExpiries;
}
/**
* Gets the the {@code optionExpiries} property.
* @return the property, not null
*/
public final Property<List<Tenor>> optionExpiries() {
return metaBean().optionExpiries().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the strikes relative to at the money, in Basis points
* @return the value of the property
*/
public List<Double> getRelativeStrikes() {
return _relativeStrikes;
}
/**
* Sets the strikes relative to at the money, in Basis points
* @param relativeStrikes the new value of the property
*/
public void setRelativeStrikes(List<Double> relativeStrikes) {
this._relativeStrikes = relativeStrikes;
}
/**
* Gets the the {@code relativeStrikes} property.
* @return the property, not null
*/
public final Property<List<Double>> relativeStrikes() {
return metaBean().relativeStrikes().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code VolatilityCubeDefinition}.
*/
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 uniqueId} property.
*/
private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofReadWrite(
this, "uniqueId", VolatilityCubeDefinition.class, UniqueId.class);
/**
* The meta-property for the {@code swapTenors} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<Tenor>> _swapTenors = DirectMetaProperty.ofReadWrite(
this, "swapTenors", VolatilityCubeDefinition.class, (Class) List.class);
/**
* The meta-property for the {@code optionExpiries} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<Tenor>> _optionExpiries = DirectMetaProperty.ofReadWrite(
this, "optionExpiries", VolatilityCubeDefinition.class, (Class) List.class);
/**
* The meta-property for the {@code relativeStrikes} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<Double>> _relativeStrikes = DirectMetaProperty.ofReadWrite(
this, "relativeStrikes", VolatilityCubeDefinition.class, (Class) List.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"uniqueId",
"swapTenors",
"optionExpiries",
"relativeStrikes");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return _uniqueId;
case -1091346138: // swapTenors
return _swapTenors;
case 146928806: // optionExpiries
return _optionExpiries;
case -1711425899: // relativeStrikes
return _relativeStrikes;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends VolatilityCubeDefinition> builder() {
return new DirectBeanBuilder<VolatilityCubeDefinition>(new VolatilityCubeDefinition());
}
@Override
public Class<? extends VolatilityCubeDefinition> beanType() {
return VolatilityCubeDefinition.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code uniqueId} property.
* @return the meta-property, not null
*/
public final MetaProperty<UniqueId> uniqueId() {
return _uniqueId;
}
/**
* The meta-property for the {@code swapTenors} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<Tenor>> swapTenors() {
return _swapTenors;
}
/**
* The meta-property for the {@code optionExpiries} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<Tenor>> optionExpiries() {
return _optionExpiries;
}
/**
* The meta-property for the {@code relativeStrikes} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<Double>> relativeStrikes() {
return _relativeStrikes;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}