/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.model.fixedincome;
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 org.threeten.bp.LocalDate;
import com.opengamma.analytics.financial.instrument.payment.PaymentDefinition;
import com.opengamma.analytics.financial.interestrate.CouponAccrualDatesVisitor;
import com.opengamma.analytics.financial.interestrate.CouponPaymentYearFractionVisitor;
import com.opengamma.analytics.financial.interestrate.payments.derivative.Payment;
import com.opengamma.analytics.financial.interestrate.swap.provider.CouponPaymentDiscountFactorVisitor;
import com.opengamma.analytics.financial.provider.description.interestrate.MulticurveProviderInterface;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.money.CurrencyAmount;
import com.opengamma.util.tuple.Pair;
/**
* Base class for a flattened view of cash flow parameters.
*/
@BeanDefinition
public abstract class AbstractCashFlowDetails implements CashFlowDetails, ImmutableBean {
/**
* The visitor used to calculate the accrual start and end dates of the cash flow.
*/
private static final CouponAccrualDatesVisitor ACCRUAL_DATES_VISITOR = new CouponAccrualDatesVisitor();
/**
* The visitor used to calculate the accrual factor of the cash flow.
*/
private static final CouponPaymentYearFractionVisitor ACCRUAL_FACTOR_VISITOR = new CouponPaymentYearFractionVisitor();
/**
* The visitor used to calculate the discount factor of the cash flow.
*/
private static final CouponPaymentDiscountFactorVisitor DISCOUNT_FACTOR_VISITOR = new CouponPaymentDiscountFactorVisitor();
/**
* The payment date of the cash flow.
*/
@PropertyDefinition(validate = "notNull")
private final LocalDate _paymentDate;
/**
* The accrual start date of the cash flow.
*/
@PropertyDefinition(validate = "notNull")
private final LocalDate _accrualStartDate;
/**
* The accrual end date of the cash flow.
*/
@PropertyDefinition(validate = "notNull")
private final LocalDate _accrualEndDate;
/**
* The accrual factor of the cash flow.
*/
@PropertyDefinition
private final Double _accrualFactor;
/**
* The currency and notional amount of the cash flow.
*/
@PropertyDefinition(validate = "notNull")
private final CurrencyAmount _notional;
/**
* The discount factor used to discount the cash flow.
*/
@PropertyDefinition
private final Double _df;
/**
* Constructs a cash flow details instance from the OG-Analytics definition and derivative forms of a cash flow, using
* the provided curves to calculate the discount factor used to discount the cash flow.
* @param definition the definition form of the cash flow.
* @param derivative the derivative form of the cash flow.
* @param curves the curves used to discount the cash flow.
*/
public AbstractCashFlowDetails(PaymentDefinition definition, Payment derivative, MulticurveProviderInterface curves) {
ArgumentChecker.notNull(definition, "definition");
ArgumentChecker.notNull(derivative, "derivative");
ArgumentChecker.notNull(curves, "curves");
_paymentDate = definition.getPaymentDate().toLocalDate();
Pair<LocalDate, LocalDate> accrualDates = definition.accept(ACCRUAL_DATES_VISITOR);
_accrualStartDate = accrualDates.getFirst();
_accrualEndDate = accrualDates.getSecond();
_accrualFactor = derivative.accept(ACCRUAL_FACTOR_VISITOR);
_notional = CurrencyAmount.of(definition.getCurrency(), definition.getReferenceAmount());
_df = derivative.accept(DISCOUNT_FACTOR_VISITOR, curves);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code AbstractCashFlowDetails}.
* @return the meta-bean, not null
*/
public static AbstractCashFlowDetails.Meta meta() {
return AbstractCashFlowDetails.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(AbstractCashFlowDetails.Meta.INSTANCE);
}
/**
* Restricted constructor.
* @param builder the builder to copy from, not null
*/
protected AbstractCashFlowDetails(AbstractCashFlowDetails.Builder builder) {
JodaBeanUtils.notNull(builder._paymentDate, "paymentDate");
JodaBeanUtils.notNull(builder._accrualStartDate, "accrualStartDate");
JodaBeanUtils.notNull(builder._accrualEndDate, "accrualEndDate");
JodaBeanUtils.notNull(builder._notional, "notional");
this._paymentDate = builder._paymentDate;
this._accrualStartDate = builder._accrualStartDate;
this._accrualEndDate = builder._accrualEndDate;
this._accrualFactor = builder._accrualFactor;
this._notional = builder._notional;
this._df = builder._df;
}
@Override
public AbstractCashFlowDetails.Meta metaBean() {
return AbstractCashFlowDetails.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 payment date of the cash flow.
* @return the value of the property, not null
*/
public LocalDate getPaymentDate() {
return _paymentDate;
}
//-----------------------------------------------------------------------
/**
* Gets the accrual start date of the cash flow.
* @return the value of the property, not null
*/
public LocalDate getAccrualStartDate() {
return _accrualStartDate;
}
//-----------------------------------------------------------------------
/**
* Gets the accrual end date of the cash flow.
* @return the value of the property, not null
*/
public LocalDate getAccrualEndDate() {
return _accrualEndDate;
}
//-----------------------------------------------------------------------
/**
* Gets the accrual factor of the cash flow.
* @return the value of the property
*/
public Double getAccrualFactor() {
return _accrualFactor;
}
//-----------------------------------------------------------------------
/**
* Gets the currency and notional amount of the cash flow.
* @return the value of the property, not null
*/
public CurrencyAmount getNotional() {
return _notional;
}
//-----------------------------------------------------------------------
/**
* Gets the discount factor used to discount the cash flow.
* @return the value of the property
*/
public Double getDf() {
return _df;
}
//-----------------------------------------------------------------------
/**
* Returns a builder that allows this bean to be mutated.
* @return the mutable builder, not null
*/
public abstract Builder toBuilder();
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
AbstractCashFlowDetails other = (AbstractCashFlowDetails) obj;
return JodaBeanUtils.equal(getPaymentDate(), other.getPaymentDate()) &&
JodaBeanUtils.equal(getAccrualStartDate(), other.getAccrualStartDate()) &&
JodaBeanUtils.equal(getAccrualEndDate(), other.getAccrualEndDate()) &&
JodaBeanUtils.equal(getAccrualFactor(), other.getAccrualFactor()) &&
JodaBeanUtils.equal(getNotional(), other.getNotional()) &&
JodaBeanUtils.equal(getDf(), other.getDf());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getPaymentDate());
hash = hash * 31 + JodaBeanUtils.hashCode(getAccrualStartDate());
hash = hash * 31 + JodaBeanUtils.hashCode(getAccrualEndDate());
hash = hash * 31 + JodaBeanUtils.hashCode(getAccrualFactor());
hash = hash * 31 + JodaBeanUtils.hashCode(getNotional());
hash = hash * 31 + JodaBeanUtils.hashCode(getDf());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(224);
buf.append("AbstractCashFlowDetails{");
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("paymentDate").append('=').append(JodaBeanUtils.toString(getPaymentDate())).append(',').append(' ');
buf.append("accrualStartDate").append('=').append(JodaBeanUtils.toString(getAccrualStartDate())).append(',').append(' ');
buf.append("accrualEndDate").append('=').append(JodaBeanUtils.toString(getAccrualEndDate())).append(',').append(' ');
buf.append("accrualFactor").append('=').append(JodaBeanUtils.toString(getAccrualFactor())).append(',').append(' ');
buf.append("notional").append('=').append(JodaBeanUtils.toString(getNotional())).append(',').append(' ');
buf.append("df").append('=').append(JodaBeanUtils.toString(getDf())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code AbstractCashFlowDetails}.
*/
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 paymentDate} property.
*/
private final MetaProperty<LocalDate> _paymentDate = DirectMetaProperty.ofImmutable(
this, "paymentDate", AbstractCashFlowDetails.class, LocalDate.class);
/**
* The meta-property for the {@code accrualStartDate} property.
*/
private final MetaProperty<LocalDate> _accrualStartDate = DirectMetaProperty.ofImmutable(
this, "accrualStartDate", AbstractCashFlowDetails.class, LocalDate.class);
/**
* The meta-property for the {@code accrualEndDate} property.
*/
private final MetaProperty<LocalDate> _accrualEndDate = DirectMetaProperty.ofImmutable(
this, "accrualEndDate", AbstractCashFlowDetails.class, LocalDate.class);
/**
* The meta-property for the {@code accrualFactor} property.
*/
private final MetaProperty<Double> _accrualFactor = DirectMetaProperty.ofImmutable(
this, "accrualFactor", AbstractCashFlowDetails.class, Double.class);
/**
* The meta-property for the {@code notional} property.
*/
private final MetaProperty<CurrencyAmount> _notional = DirectMetaProperty.ofImmutable(
this, "notional", AbstractCashFlowDetails.class, CurrencyAmount.class);
/**
* The meta-property for the {@code df} property.
*/
private final MetaProperty<Double> _df = DirectMetaProperty.ofImmutable(
this, "df", AbstractCashFlowDetails.class, Double.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"paymentDate",
"accrualStartDate",
"accrualEndDate",
"accrualFactor",
"notional",
"df");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1540873516: // paymentDate
return _paymentDate;
case -1114548671: // accrualStartDate
return _accrualStartDate;
case -1021196678: // accrualEndDate
return _accrualEndDate;
case -1540322338: // accrualFactor
return _accrualFactor;
case 1585636160: // notional
return _notional;
case 3202: // df
return _df;
}
return super.metaPropertyGet(propertyName);
}
@Override
public AbstractCashFlowDetails.Builder builder() {
throw new UnsupportedOperationException("AbstractCashFlowDetails is an abstract class");
}
@Override
public Class<? extends AbstractCashFlowDetails> beanType() {
return AbstractCashFlowDetails.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code paymentDate} property.
* @return the meta-property, not null
*/
public final MetaProperty<LocalDate> paymentDate() {
return _paymentDate;
}
/**
* The meta-property for the {@code accrualStartDate} property.
* @return the meta-property, not null
*/
public final MetaProperty<LocalDate> accrualStartDate() {
return _accrualStartDate;
}
/**
* The meta-property for the {@code accrualEndDate} property.
* @return the meta-property, not null
*/
public final MetaProperty<LocalDate> accrualEndDate() {
return _accrualEndDate;
}
/**
* The meta-property for the {@code accrualFactor} property.
* @return the meta-property, not null
*/
public final MetaProperty<Double> accrualFactor() {
return _accrualFactor;
}
/**
* The meta-property for the {@code notional} property.
* @return the meta-property, not null
*/
public final MetaProperty<CurrencyAmount> notional() {
return _notional;
}
/**
* The meta-property for the {@code df} property.
* @return the meta-property, not null
*/
public final MetaProperty<Double> df() {
return _df;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1540873516: // paymentDate
return ((AbstractCashFlowDetails) bean).getPaymentDate();
case -1114548671: // accrualStartDate
return ((AbstractCashFlowDetails) bean).getAccrualStartDate();
case -1021196678: // accrualEndDate
return ((AbstractCashFlowDetails) bean).getAccrualEndDate();
case -1540322338: // accrualFactor
return ((AbstractCashFlowDetails) bean).getAccrualFactor();
case 1585636160: // notional
return ((AbstractCashFlowDetails) bean).getNotional();
case 3202: // df
return ((AbstractCashFlowDetails) bean).getDf();
}
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 AbstractCashFlowDetails}.
*/
public abstract static class Builder extends DirectFieldsBeanBuilder<AbstractCashFlowDetails> {
private LocalDate _paymentDate;
private LocalDate _accrualStartDate;
private LocalDate _accrualEndDate;
private Double _accrualFactor;
private CurrencyAmount _notional;
private Double _df;
/**
* Restricted constructor.
*/
protected Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
protected Builder(AbstractCashFlowDetails beanToCopy) {
this._paymentDate = beanToCopy.getPaymentDate();
this._accrualStartDate = beanToCopy.getAccrualStartDate();
this._accrualEndDate = beanToCopy.getAccrualEndDate();
this._accrualFactor = beanToCopy.getAccrualFactor();
this._notional = beanToCopy.getNotional();
this._df = beanToCopy.getDf();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -1540873516: // paymentDate
return _paymentDate;
case -1114548671: // accrualStartDate
return _accrualStartDate;
case -1021196678: // accrualEndDate
return _accrualEndDate;
case -1540322338: // accrualFactor
return _accrualFactor;
case 1585636160: // notional
return _notional;
case 3202: // df
return _df;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -1540873516: // paymentDate
this._paymentDate = (LocalDate) newValue;
break;
case -1114548671: // accrualStartDate
this._accrualStartDate = (LocalDate) newValue;
break;
case -1021196678: // accrualEndDate
this._accrualEndDate = (LocalDate) newValue;
break;
case -1540322338: // accrualFactor
this._accrualFactor = (Double) newValue;
break;
case 1585636160: // notional
this._notional = (CurrencyAmount) newValue;
break;
case 3202: // df
this._df = (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;
}
//-----------------------------------------------------------------------
/**
* Sets the {@code paymentDate} property in the builder.
* @param paymentDate the new value, not null
* @return this, for chaining, not null
*/
public Builder paymentDate(LocalDate paymentDate) {
JodaBeanUtils.notNull(paymentDate, "paymentDate");
this._paymentDate = paymentDate;
return this;
}
/**
* Sets the {@code accrualStartDate} property in the builder.
* @param accrualStartDate the new value, not null
* @return this, for chaining, not null
*/
public Builder accrualStartDate(LocalDate accrualStartDate) {
JodaBeanUtils.notNull(accrualStartDate, "accrualStartDate");
this._accrualStartDate = accrualStartDate;
return this;
}
/**
* Sets the {@code accrualEndDate} property in the builder.
* @param accrualEndDate the new value, not null
* @return this, for chaining, not null
*/
public Builder accrualEndDate(LocalDate accrualEndDate) {
JodaBeanUtils.notNull(accrualEndDate, "accrualEndDate");
this._accrualEndDate = accrualEndDate;
return this;
}
/**
* Sets the {@code accrualFactor} property in the builder.
* @param accrualFactor the new value
* @return this, for chaining, not null
*/
public Builder accrualFactor(Double accrualFactor) {
this._accrualFactor = accrualFactor;
return this;
}
/**
* Sets the {@code notional} property in the builder.
* @param notional the new value, not null
* @return this, for chaining, not null
*/
public Builder notional(CurrencyAmount notional) {
JodaBeanUtils.notNull(notional, "notional");
this._notional = notional;
return this;
}
/**
* Sets the {@code df} property in the builder.
* @param df the new value
* @return this, for chaining, not null
*/
public Builder df(Double df) {
this._df = df;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(224);
buf.append("AbstractCashFlowDetails.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("paymentDate").append('=').append(JodaBeanUtils.toString(_paymentDate)).append(',').append(' ');
buf.append("accrualStartDate").append('=').append(JodaBeanUtils.toString(_accrualStartDate)).append(',').append(' ');
buf.append("accrualEndDate").append('=').append(JodaBeanUtils.toString(_accrualEndDate)).append(',').append(' ');
buf.append("accrualFactor").append('=').append(JodaBeanUtils.toString(_accrualFactor)).append(',').append(' ');
buf.append("notional").append('=').append(JodaBeanUtils.toString(_notional)).append(',').append(' ');
buf.append("df").append('=').append(JodaBeanUtils.toString(_df)).append(',').append(' ');
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}