/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.isda.credit;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
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.google.common.collect.ImmutableSortedMap;
import com.opengamma.core.link.ConventionLink;
import com.opengamma.financial.convention.IsdaCreditCurveConvention;
import com.opengamma.util.time.Tenor;
/**
* An instance containing the market data required to bootstrap an ISDA credit curve.
* Also referenced is the applicable recovery rate and convention to use.
*
* The CDS quotes to use are held in a sorted map indexed by tenor. Quotes are
* specified using subclasses of the interface {@link CdsQuote}. The term structure
* of the curve is implied by the set of tenors present as keys.
*/
@BeanDefinition
public class CreditCurveData implements ImmutableBean {
/**
* The credit curve convention to apply when bootstrapping the curve.
*/
@PropertyDefinition(validate = "notNull")
private final ConventionLink<IsdaCreditCurveConvention> _curveConventionLink;
/**
* The set of cds quotes to use to bootstrap the curve, indexed by tenor.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableSortedMap<Tenor, CdsQuote> _cdsQuotes;
/**
* The recovery rate, expressed as a fractional amount. e.g. 0.4 = 40%.
*/
@PropertyDefinition
private final double _recoveryRate;
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code CreditCurveData}.
* @return the meta-bean, not null
*/
public static CreditCurveData.Meta meta() {
return CreditCurveData.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(CreditCurveData.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static CreditCurveData.Builder builder() {
return new CreditCurveData.Builder();
}
/**
* Restricted constructor.
* @param builder the builder to copy from, not null
*/
protected CreditCurveData(CreditCurveData.Builder builder) {
JodaBeanUtils.notNull(builder._curveConventionLink, "curveConventionLink");
JodaBeanUtils.notNull(builder._cdsQuotes, "cdsQuotes");
this._curveConventionLink = builder._curveConventionLink;
this._cdsQuotes = ImmutableSortedMap.copyOfSorted(builder._cdsQuotes);
this._recoveryRate = builder._recoveryRate;
}
@Override
public CreditCurveData.Meta metaBean() {
return CreditCurveData.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 credit curve convention to apply when bootstrapping the curve.
* @return the value of the property, not null
*/
public ConventionLink<IsdaCreditCurveConvention> getCurveConventionLink() {
return _curveConventionLink;
}
//-----------------------------------------------------------------------
/**
* Gets the set of cds quotes to use to bootstrap the curve, indexed by tenor.
* @return the value of the property, not null
*/
public ImmutableSortedMap<Tenor, CdsQuote> getCdsQuotes() {
return _cdsQuotes;
}
//-----------------------------------------------------------------------
/**
* Gets the recovery rate, expressed as a fractional amount. e.g. 0.4 = 40%.
* @return the value of the property
*/
public double getRecoveryRate() {
return _recoveryRate;
}
//-----------------------------------------------------------------------
/**
* 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()) {
CreditCurveData other = (CreditCurveData) obj;
return JodaBeanUtils.equal(getCurveConventionLink(), other.getCurveConventionLink()) &&
JodaBeanUtils.equal(getCdsQuotes(), other.getCdsQuotes()) &&
JodaBeanUtils.equal(getRecoveryRate(), other.getRecoveryRate());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getCurveConventionLink());
hash = hash * 31 + JodaBeanUtils.hashCode(getCdsQuotes());
hash = hash * 31 + JodaBeanUtils.hashCode(getRecoveryRate());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("CreditCurveData{");
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("curveConventionLink").append('=').append(JodaBeanUtils.toString(getCurveConventionLink())).append(',').append(' ');
buf.append("cdsQuotes").append('=').append(JodaBeanUtils.toString(getCdsQuotes())).append(',').append(' ');
buf.append("recoveryRate").append('=').append(JodaBeanUtils.toString(getRecoveryRate())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CreditCurveData}.
*/
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 curveConventionLink} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<ConventionLink<IsdaCreditCurveConvention>> _curveConventionLink = DirectMetaProperty.ofImmutable(
this, "curveConventionLink", CreditCurveData.class, (Class) ConventionLink.class);
/**
* The meta-property for the {@code cdsQuotes} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<ImmutableSortedMap<Tenor, CdsQuote>> _cdsQuotes = DirectMetaProperty.ofImmutable(
this, "cdsQuotes", CreditCurveData.class, (Class) ImmutableSortedMap.class);
/**
* The meta-property for the {@code recoveryRate} property.
*/
private final MetaProperty<Double> _recoveryRate = DirectMetaProperty.ofImmutable(
this, "recoveryRate", CreditCurveData.class, Double.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"curveConventionLink",
"cdsQuotes",
"recoveryRate");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -837722662: // curveConventionLink
return _curveConventionLink;
case 1052151881: // cdsQuotes
return _cdsQuotes;
case 2002873877: // recoveryRate
return _recoveryRate;
}
return super.metaPropertyGet(propertyName);
}
@Override
public CreditCurveData.Builder builder() {
return new CreditCurveData.Builder();
}
@Override
public Class<? extends CreditCurveData> beanType() {
return CreditCurveData.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code curveConventionLink} property.
* @return the meta-property, not null
*/
public final MetaProperty<ConventionLink<IsdaCreditCurveConvention>> curveConventionLink() {
return _curveConventionLink;
}
/**
* The meta-property for the {@code cdsQuotes} property.
* @return the meta-property, not null
*/
public final MetaProperty<ImmutableSortedMap<Tenor, CdsQuote>> cdsQuotes() {
return _cdsQuotes;
}
/**
* The meta-property for the {@code recoveryRate} property.
* @return the meta-property, not null
*/
public final MetaProperty<Double> recoveryRate() {
return _recoveryRate;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -837722662: // curveConventionLink
return ((CreditCurveData) bean).getCurveConventionLink();
case 1052151881: // cdsQuotes
return ((CreditCurveData) bean).getCdsQuotes();
case 2002873877: // recoveryRate
return ((CreditCurveData) bean).getRecoveryRate();
}
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 CreditCurveData}.
*/
public static class Builder extends DirectFieldsBeanBuilder<CreditCurveData> {
private ConventionLink<IsdaCreditCurveConvention> _curveConventionLink;
private SortedMap<Tenor, CdsQuote> _cdsQuotes = new TreeMap<Tenor, CdsQuote>();
private double _recoveryRate;
/**
* Restricted constructor.
*/
protected Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
protected Builder(CreditCurveData beanToCopy) {
this._curveConventionLink = beanToCopy.getCurveConventionLink();
this._cdsQuotes = new TreeMap<Tenor, CdsQuote>(beanToCopy.getCdsQuotes());
this._recoveryRate = beanToCopy.getRecoveryRate();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -837722662: // curveConventionLink
return _curveConventionLink;
case 1052151881: // cdsQuotes
return _cdsQuotes;
case 2002873877: // recoveryRate
return _recoveryRate;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@SuppressWarnings("unchecked")
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -837722662: // curveConventionLink
this._curveConventionLink = (ConventionLink<IsdaCreditCurveConvention>) newValue;
break;
case 1052151881: // cdsQuotes
this._cdsQuotes = (SortedMap<Tenor, CdsQuote>) newValue;
break;
case 2002873877: // recoveryRate
this._recoveryRate = (Double) 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 CreditCurveData build() {
return new CreditCurveData(this);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code curveConventionLink} property in the builder.
* @param curveConventionLink the new value, not null
* @return this, for chaining, not null
*/
public Builder curveConventionLink(ConventionLink<IsdaCreditCurveConvention> curveConventionLink) {
JodaBeanUtils.notNull(curveConventionLink, "curveConventionLink");
this._curveConventionLink = curveConventionLink;
return this;
}
/**
* Sets the {@code cdsQuotes} property in the builder.
* @param cdsQuotes the new value, not null
* @return this, for chaining, not null
*/
public Builder cdsQuotes(SortedMap<Tenor, CdsQuote> cdsQuotes) {
JodaBeanUtils.notNull(cdsQuotes, "cdsQuotes");
this._cdsQuotes = cdsQuotes;
return this;
}
/**
* Sets the {@code recoveryRate} property in the builder.
* @param recoveryRate the new value
* @return this, for chaining, not null
*/
public Builder recoveryRate(double recoveryRate) {
this._recoveryRate = recoveryRate;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("CreditCurveData.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("curveConventionLink").append('=').append(JodaBeanUtils.toString(_curveConventionLink)).append(',').append(' ');
buf.append("cdsQuotes").append('=').append(JodaBeanUtils.toString(_cdsQuotes)).append(',').append(' ');
buf.append("recoveryRate").append('=').append(JodaBeanUtils.toString(_recoveryRate)).append(',').append(' ');
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}