/**
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product.credit;
import java.io.Serializable;
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.strata.basics.currency.CurrencyAmount;
import com.opengamma.strata.basics.date.DayCount;
import com.opengamma.strata.basics.schedule.Frequency;
import com.opengamma.strata.basics.schedule.RollConvention;
import com.opengamma.strata.basics.schedule.StubConvention;
/**
* Specifies a periodic schedule of fixed amounts
* <p>
* The payments are made from the protection buyer to the protection seller.
* Payments occur on a regular schedule of dates, defined here.
* <p>
* The amount to be paid on each payment date is calculated based on a notional, fixed rate
* and day count convention. Payment dates are adjusted by business day convention.
*/
@BeanDefinition
public final class PeriodicPayments
implements ImmutableBean, Serializable {
/**
* The notional amount used in the calculation of fixed amounts where an amount is calculated on a formula basis,
* i.e. fixed amount = fixed rate payer calculation amount x fixed rate x fixed rate day count fraction.
* <p>
* ISDA 2003 Term: Fixed Rate Payer Calculation Amount.
*/
@PropertyDefinition(validate = "notNull")
private final CurrencyAmount notional;
/**
* The coupon.
* <p>
* The fixed rate to be paid relative to the notional. This is a per annum rate, expressed as a decimal.
* A fixed rate of 5% would be represented as 0.05.
*/
@PropertyDefinition(validate = "notNull")
private final double coupon;
/**
* The day count convention.
* <p>
* ISDA 2003 Term: Fixed Rate Day Count Fraction.
*/
@PropertyDefinition(validate = "notNull")
private final DayCount dayCount;
/**
* The periodic frequency defining when payments are made.
* <p>
* This represents the time interval between regular fixed rate payer payment dates.
*/
@PropertyDefinition(validate = "notNull")
private final Frequency paymentFrequency;
/**
* The stub convention to use.
* <p>
* This is needed when the maturity date does not land precisely on a CDS date.
* <p>
* This may be 'ShortInitial', 'LongInitial', 'ShortFinal', or 'LongFinal'.
* The values 'None' and 'Both' are not allowed.
*/
@PropertyDefinition(validate = "notNull")
private final StubConvention stubConvention;
/**
* The roll convention
* <p>
* This is used to calculate payment schedule.
*/
@PropertyDefinition(validate = "notNull")
private final RollConvention rollConvention;
//-------------------------------------------------------------------------
/**
* Creates an instance.
*
* @param notional the notional
* @param coupon the coupon, expressed as a decimal rate
* @param dayCount the day count convention
* @param paymentFrequency the payment frequency
* @param stubConvention the stub convention to use
* @param rollConvention the roll convention to use
* @return the payment instance
*/
public static PeriodicPayments of(
CurrencyAmount notional,
double coupon,
DayCount dayCount,
Frequency paymentFrequency,
StubConvention stubConvention,
RollConvention rollConvention) {
return new PeriodicPayments(
notional,
coupon,
dayCount,
paymentFrequency,
stubConvention,
rollConvention);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code PeriodicPayments}.
* @return the meta-bean, not null
*/
public static PeriodicPayments.Meta meta() {
return PeriodicPayments.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(PeriodicPayments.Meta.INSTANCE);
}
/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static PeriodicPayments.Builder builder() {
return new PeriodicPayments.Builder();
}
private PeriodicPayments(
CurrencyAmount notional,
double coupon,
DayCount dayCount,
Frequency paymentFrequency,
StubConvention stubConvention,
RollConvention rollConvention) {
JodaBeanUtils.notNull(notional, "notional");
JodaBeanUtils.notNull(coupon, "coupon");
JodaBeanUtils.notNull(dayCount, "dayCount");
JodaBeanUtils.notNull(paymentFrequency, "paymentFrequency");
JodaBeanUtils.notNull(stubConvention, "stubConvention");
JodaBeanUtils.notNull(rollConvention, "rollConvention");
this.notional = notional;
this.coupon = coupon;
this.dayCount = dayCount;
this.paymentFrequency = paymentFrequency;
this.stubConvention = stubConvention;
this.rollConvention = rollConvention;
}
@Override
public PeriodicPayments.Meta metaBean() {
return PeriodicPayments.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 notional amount used in the calculation of fixed amounts where an amount is calculated on a formula basis,
* i.e. fixed amount = fixed rate payer calculation amount x fixed rate x fixed rate day count fraction.
* <p>
* ISDA 2003 Term: Fixed Rate Payer Calculation Amount.
* @return the value of the property, not null
*/
public CurrencyAmount getNotional() {
return notional;
}
//-----------------------------------------------------------------------
/**
* Gets the coupon.
* <p>
* The fixed rate to be paid relative to the notional. This is a per annum rate, expressed as a decimal.
* A fixed rate of 5% would be represented as 0.05.
* @return the value of the property, not null
*/
public double getCoupon() {
return coupon;
}
//-----------------------------------------------------------------------
/**
* Gets the day count convention.
* <p>
* ISDA 2003 Term: Fixed Rate Day Count Fraction.
* @return the value of the property, not null
*/
public DayCount getDayCount() {
return dayCount;
}
//-----------------------------------------------------------------------
/**
* Gets the periodic frequency defining when payments are made.
* <p>
* This represents the time interval between regular fixed rate payer payment dates.
* @return the value of the property, not null
*/
public Frequency getPaymentFrequency() {
return paymentFrequency;
}
//-----------------------------------------------------------------------
/**
* Gets the stub convention to use.
* <p>
* This is needed when the maturity date does not land precisely on a CDS date.
* <p>
* This may be 'ShortInitial', 'LongInitial', 'ShortFinal', or 'LongFinal'.
* The values 'None' and 'Both' are not allowed.
* @return the value of the property, not null
*/
public StubConvention getStubConvention() {
return stubConvention;
}
//-----------------------------------------------------------------------
/**
* Gets the roll convention
* <p>
* This is used to calculate payment schedule.
* @return the value of the property, not null
*/
public RollConvention getRollConvention() {
return rollConvention;
}
//-----------------------------------------------------------------------
/**
* 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()) {
PeriodicPayments other = (PeriodicPayments) obj;
return JodaBeanUtils.equal(notional, other.notional) &&
JodaBeanUtils.equal(coupon, other.coupon) &&
JodaBeanUtils.equal(dayCount, other.dayCount) &&
JodaBeanUtils.equal(paymentFrequency, other.paymentFrequency) &&
JodaBeanUtils.equal(stubConvention, other.stubConvention) &&
JodaBeanUtils.equal(rollConvention, other.rollConvention);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(notional);
hash = hash * 31 + JodaBeanUtils.hashCode(coupon);
hash = hash * 31 + JodaBeanUtils.hashCode(dayCount);
hash = hash * 31 + JodaBeanUtils.hashCode(paymentFrequency);
hash = hash * 31 + JodaBeanUtils.hashCode(stubConvention);
hash = hash * 31 + JodaBeanUtils.hashCode(rollConvention);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(224);
buf.append("PeriodicPayments{");
buf.append("notional").append('=').append(notional).append(',').append(' ');
buf.append("coupon").append('=').append(coupon).append(',').append(' ');
buf.append("dayCount").append('=').append(dayCount).append(',').append(' ');
buf.append("paymentFrequency").append('=').append(paymentFrequency).append(',').append(' ');
buf.append("stubConvention").append('=').append(stubConvention).append(',').append(' ');
buf.append("rollConvention").append('=').append(JodaBeanUtils.toString(rollConvention));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code PeriodicPayments}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code notional} property.
*/
private final MetaProperty<CurrencyAmount> notional = DirectMetaProperty.ofImmutable(
this, "notional", PeriodicPayments.class, CurrencyAmount.class);
/**
* The meta-property for the {@code coupon} property.
*/
private final MetaProperty<Double> coupon = DirectMetaProperty.ofImmutable(
this, "coupon", PeriodicPayments.class, Double.TYPE);
/**
* The meta-property for the {@code dayCount} property.
*/
private final MetaProperty<DayCount> dayCount = DirectMetaProperty.ofImmutable(
this, "dayCount", PeriodicPayments.class, DayCount.class);
/**
* The meta-property for the {@code paymentFrequency} property.
*/
private final MetaProperty<Frequency> paymentFrequency = DirectMetaProperty.ofImmutable(
this, "paymentFrequency", PeriodicPayments.class, Frequency.class);
/**
* The meta-property for the {@code stubConvention} property.
*/
private final MetaProperty<StubConvention> stubConvention = DirectMetaProperty.ofImmutable(
this, "stubConvention", PeriodicPayments.class, StubConvention.class);
/**
* The meta-property for the {@code rollConvention} property.
*/
private final MetaProperty<RollConvention> rollConvention = DirectMetaProperty.ofImmutable(
this, "rollConvention", PeriodicPayments.class, RollConvention.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"notional",
"coupon",
"dayCount",
"paymentFrequency",
"stubConvention",
"rollConvention");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 1585636160: // notional
return notional;
case -1354573786: // coupon
return coupon;
case 1905311443: // dayCount
return dayCount;
case 863656438: // paymentFrequency
return paymentFrequency;
case -31408449: // stubConvention
return stubConvention;
case -10223666: // rollConvention
return rollConvention;
}
return super.metaPropertyGet(propertyName);
}
@Override
public PeriodicPayments.Builder builder() {
return new PeriodicPayments.Builder();
}
@Override
public Class<? extends PeriodicPayments> beanType() {
return PeriodicPayments.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code notional} property.
* @return the meta-property, not null
*/
public MetaProperty<CurrencyAmount> notional() {
return notional;
}
/**
* The meta-property for the {@code coupon} property.
* @return the meta-property, not null
*/
public MetaProperty<Double> coupon() {
return coupon;
}
/**
* The meta-property for the {@code dayCount} property.
* @return the meta-property, not null
*/
public MetaProperty<DayCount> dayCount() {
return dayCount;
}
/**
* The meta-property for the {@code paymentFrequency} property.
* @return the meta-property, not null
*/
public MetaProperty<Frequency> paymentFrequency() {
return paymentFrequency;
}
/**
* The meta-property for the {@code stubConvention} property.
* @return the meta-property, not null
*/
public MetaProperty<StubConvention> stubConvention() {
return stubConvention;
}
/**
* The meta-property for the {@code rollConvention} property.
* @return the meta-property, not null
*/
public MetaProperty<RollConvention> rollConvention() {
return rollConvention;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 1585636160: // notional
return ((PeriodicPayments) bean).getNotional();
case -1354573786: // coupon
return ((PeriodicPayments) bean).getCoupon();
case 1905311443: // dayCount
return ((PeriodicPayments) bean).getDayCount();
case 863656438: // paymentFrequency
return ((PeriodicPayments) bean).getPaymentFrequency();
case -31408449: // stubConvention
return ((PeriodicPayments) bean).getStubConvention();
case -10223666: // rollConvention
return ((PeriodicPayments) bean).getRollConvention();
}
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 PeriodicPayments}.
*/
public static final class Builder extends DirectFieldsBeanBuilder<PeriodicPayments> {
private CurrencyAmount notional;
private double coupon;
private DayCount dayCount;
private Frequency paymentFrequency;
private StubConvention stubConvention;
private RollConvention rollConvention;
/**
* Restricted constructor.
*/
private Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(PeriodicPayments beanToCopy) {
this.notional = beanToCopy.getNotional();
this.coupon = beanToCopy.getCoupon();
this.dayCount = beanToCopy.getDayCount();
this.paymentFrequency = beanToCopy.getPaymentFrequency();
this.stubConvention = beanToCopy.getStubConvention();
this.rollConvention = beanToCopy.getRollConvention();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 1585636160: // notional
return notional;
case -1354573786: // coupon
return coupon;
case 1905311443: // dayCount
return dayCount;
case 863656438: // paymentFrequency
return paymentFrequency;
case -31408449: // stubConvention
return stubConvention;
case -10223666: // rollConvention
return rollConvention;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 1585636160: // notional
this.notional = (CurrencyAmount) newValue;
break;
case -1354573786: // coupon
this.coupon = (Double) newValue;
break;
case 1905311443: // dayCount
this.dayCount = (DayCount) newValue;
break;
case 863656438: // paymentFrequency
this.paymentFrequency = (Frequency) newValue;
break;
case -31408449: // stubConvention
this.stubConvention = (StubConvention) newValue;
break;
case -10223666: // rollConvention
this.rollConvention = (RollConvention) 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 PeriodicPayments build() {
return new PeriodicPayments(
notional,
coupon,
dayCount,
paymentFrequency,
stubConvention,
rollConvention);
}
//-----------------------------------------------------------------------
/**
* Sets the notional amount used in the calculation of fixed amounts where an amount is calculated on a formula basis,
* i.e. fixed amount = fixed rate payer calculation amount x fixed rate x fixed rate day count fraction.
* <p>
* ISDA 2003 Term: Fixed Rate Payer Calculation Amount.
* @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 coupon.
* <p>
* The fixed rate to be paid relative to the notional. This is a per annum rate, expressed as a decimal.
* A fixed rate of 5% would be represented as 0.05.
* @param coupon the new value, not null
* @return this, for chaining, not null
*/
public Builder coupon(double coupon) {
JodaBeanUtils.notNull(coupon, "coupon");
this.coupon = coupon;
return this;
}
/**
* Sets the day count convention.
* <p>
* ISDA 2003 Term: Fixed Rate Day Count Fraction.
* @param dayCount the new value, not null
* @return this, for chaining, not null
*/
public Builder dayCount(DayCount dayCount) {
JodaBeanUtils.notNull(dayCount, "dayCount");
this.dayCount = dayCount;
return this;
}
/**
* Sets the periodic frequency defining when payments are made.
* <p>
* This represents the time interval between regular fixed rate payer payment dates.
* @param paymentFrequency the new value, not null
* @return this, for chaining, not null
*/
public Builder paymentFrequency(Frequency paymentFrequency) {
JodaBeanUtils.notNull(paymentFrequency, "paymentFrequency");
this.paymentFrequency = paymentFrequency;
return this;
}
/**
* Sets the stub convention to use.
* <p>
* This is needed when the maturity date does not land precisely on a CDS date.
* <p>
* This may be 'ShortInitial', 'LongInitial', 'ShortFinal', or 'LongFinal'.
* The values 'None' and 'Both' are not allowed.
* @param stubConvention the new value, not null
* @return this, for chaining, not null
*/
public Builder stubConvention(StubConvention stubConvention) {
JodaBeanUtils.notNull(stubConvention, "stubConvention");
this.stubConvention = stubConvention;
return this;
}
/**
* Sets the roll convention
* <p>
* This is used to calculate payment schedule.
* @param rollConvention the new value, not null
* @return this, for chaining, not null
*/
public Builder rollConvention(RollConvention rollConvention) {
JodaBeanUtils.notNull(rollConvention, "rollConvention");
this.rollConvention = rollConvention;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(224);
buf.append("PeriodicPayments.Builder{");
buf.append("notional").append('=').append(JodaBeanUtils.toString(notional)).append(',').append(' ');
buf.append("coupon").append('=').append(JodaBeanUtils.toString(coupon)).append(',').append(' ');
buf.append("dayCount").append('=').append(JodaBeanUtils.toString(dayCount)).append(',').append(' ');
buf.append("paymentFrequency").append('=').append(JodaBeanUtils.toString(paymentFrequency)).append(',').append(' ');
buf.append("stubConvention").append('=').append(JodaBeanUtils.toString(stubConvention)).append(',').append(' ');
buf.append("rollConvention").append('=').append(JodaBeanUtils.toString(rollConvention));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}