/** * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.strata.product.deposit; import java.io.Serializable; import java.time.LocalDate; 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.ImmutableValidator; 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.ReferenceData; import com.opengamma.strata.basics.currency.Currency; import com.opengamma.strata.basics.date.DayCount; import com.opengamma.strata.collect.ArgChecker; import com.opengamma.strata.product.ResolvedProduct; import com.opengamma.strata.product.rate.IborRateComputation; /** * An Ibor fixing deposit, resolved for pricing. * <p> * This is the resolved form of {@link IborFixingDeposit} and is an input to the pricers. * Applications will typically create a {@code ResolvedIborFixingDeposit} from a {@code IborFixingDeposit} * using {@link IborFixingDeposit#resolve(ReferenceData)}. * <p> * A {@code ResolvedIborFixingDeposit} is bound to data that changes over time, such as holiday calendars. * If the data changes, such as the addition of a new holiday, the resolved form will not be updated. * Care must be taken when placing the resolved form in a cache or persistence layer. */ @BeanDefinition public final class ResolvedIborFixingDeposit implements ResolvedProduct, ImmutableBean, Serializable { /** * The primary currency. * <p> * This is the currency of the deposit and the currency that payment is made in. * The data model permits this currency to differ from that of the index, * however the two are typically the same. */ @PropertyDefinition(validate = "notNull") private final Currency currency; /** * The notional amount. * <p> * The amount that is deposited. It is a positive signed amount if the deposit is 'Buy', * and a negative signed amount if the deposit is 'Sell'. * <p> * The currency of the notional is specified by {@code currency}. */ @PropertyDefinition private final double notional; /** * The start date of the deposit. * <p> * This is the first date that interest accrues. * <p> * This is an adjusted date, which should be a valid business day */ @PropertyDefinition(validate = "notNull") private final LocalDate startDate; /** * The end date of the deposit. * <p> * This is the last day that interest accrues. * This date must be after the start date. * <p> * This is an adjusted date, which should be a valid business day */ @PropertyDefinition(validate = "notNull") private final LocalDate endDate; /** * The year fraction between the start and end date. * <p> * The value is usually calculated using a {@link DayCount}. * Typically the value will be close to 1 for one year and close to 0.5 for six months. * The fraction may be greater than 1, but not less than 0. */ @PropertyDefinition(validate = "ArgChecker.notNegative") private final double yearFraction; /** * The fixed rate of interest. * A 5% rate will be expressed as 0.05. */ @PropertyDefinition private final double fixedRate; /** * The floating rate of interest. * <p> * The floating rate to be paid is based on this index. * It will be a well known market index such as 'GBP-LIBOR-3M'. */ @PropertyDefinition(validate = "notNull") private final IborRateComputation floatingRate; //------------------------------------------------------------------------- @ImmutableValidator private void validate() { ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate"); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code ResolvedIborFixingDeposit}. * @return the meta-bean, not null */ public static ResolvedIborFixingDeposit.Meta meta() { return ResolvedIborFixingDeposit.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(ResolvedIborFixingDeposit.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 ResolvedIborFixingDeposit.Builder builder() { return new ResolvedIborFixingDeposit.Builder(); } private ResolvedIborFixingDeposit( Currency currency, double notional, LocalDate startDate, LocalDate endDate, double yearFraction, double fixedRate, IborRateComputation floatingRate) { JodaBeanUtils.notNull(currency, "currency"); JodaBeanUtils.notNull(startDate, "startDate"); JodaBeanUtils.notNull(endDate, "endDate"); ArgChecker.notNegative(yearFraction, "yearFraction"); JodaBeanUtils.notNull(floatingRate, "floatingRate"); this.currency = currency; this.notional = notional; this.startDate = startDate; this.endDate = endDate; this.yearFraction = yearFraction; this.fixedRate = fixedRate; this.floatingRate = floatingRate; validate(); } @Override public ResolvedIborFixingDeposit.Meta metaBean() { return ResolvedIborFixingDeposit.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 primary currency. * <p> * This is the currency of the deposit and the currency that payment is made in. * The data model permits this currency to differ from that of the index, * however the two are typically the same. * @return the value of the property, not null */ public Currency getCurrency() { return currency; } //----------------------------------------------------------------------- /** * Gets the notional amount. * <p> * The amount that is deposited. It is a positive signed amount if the deposit is 'Buy', * and a negative signed amount if the deposit is 'Sell'. * <p> * The currency of the notional is specified by {@code currency}. * @return the value of the property */ public double getNotional() { return notional; } //----------------------------------------------------------------------- /** * Gets the start date of the deposit. * <p> * This is the first date that interest accrues. * <p> * This is an adjusted date, which should be a valid business day * @return the value of the property, not null */ public LocalDate getStartDate() { return startDate; } //----------------------------------------------------------------------- /** * Gets the end date of the deposit. * <p> * This is the last day that interest accrues. * This date must be after the start date. * <p> * This is an adjusted date, which should be a valid business day * @return the value of the property, not null */ public LocalDate getEndDate() { return endDate; } //----------------------------------------------------------------------- /** * Gets the year fraction between the start and end date. * <p> * The value is usually calculated using a {@link DayCount}. * Typically the value will be close to 1 for one year and close to 0.5 for six months. * The fraction may be greater than 1, but not less than 0. * @return the value of the property */ public double getYearFraction() { return yearFraction; } //----------------------------------------------------------------------- /** * Gets the fixed rate of interest. * A 5% rate will be expressed as 0.05. * @return the value of the property */ public double getFixedRate() { return fixedRate; } //----------------------------------------------------------------------- /** * Gets the floating rate of interest. * <p> * The floating rate to be paid is based on this index. * It will be a well known market index such as 'GBP-LIBOR-3M'. * @return the value of the property, not null */ public IborRateComputation getFloatingRate() { return floatingRate; } //----------------------------------------------------------------------- /** * 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()) { ResolvedIborFixingDeposit other = (ResolvedIborFixingDeposit) obj; return JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(notional, other.notional) && JodaBeanUtils.equal(startDate, other.startDate) && JodaBeanUtils.equal(endDate, other.endDate) && JodaBeanUtils.equal(yearFraction, other.yearFraction) && JodaBeanUtils.equal(fixedRate, other.fixedRate) && JodaBeanUtils.equal(floatingRate, other.floatingRate); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(currency); hash = hash * 31 + JodaBeanUtils.hashCode(notional); hash = hash * 31 + JodaBeanUtils.hashCode(startDate); hash = hash * 31 + JodaBeanUtils.hashCode(endDate); hash = hash * 31 + JodaBeanUtils.hashCode(yearFraction); hash = hash * 31 + JodaBeanUtils.hashCode(fixedRate); hash = hash * 31 + JodaBeanUtils.hashCode(floatingRate); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(256); buf.append("ResolvedIborFixingDeposit{"); buf.append("currency").append('=').append(currency).append(',').append(' '); buf.append("notional").append('=').append(notional).append(',').append(' '); buf.append("startDate").append('=').append(startDate).append(',').append(' '); buf.append("endDate").append('=').append(endDate).append(',').append(' '); buf.append("yearFraction").append('=').append(yearFraction).append(',').append(' '); buf.append("fixedRate").append('=').append(fixedRate).append(',').append(' '); buf.append("floatingRate").append('=').append(JodaBeanUtils.toString(floatingRate)); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code ResolvedIborFixingDeposit}. */ 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 currency} property. */ private final MetaProperty<Currency> currency = DirectMetaProperty.ofImmutable( this, "currency", ResolvedIborFixingDeposit.class, Currency.class); /** * The meta-property for the {@code notional} property. */ private final MetaProperty<Double> notional = DirectMetaProperty.ofImmutable( this, "notional", ResolvedIborFixingDeposit.class, Double.TYPE); /** * The meta-property for the {@code startDate} property. */ private final MetaProperty<LocalDate> startDate = DirectMetaProperty.ofImmutable( this, "startDate", ResolvedIborFixingDeposit.class, LocalDate.class); /** * The meta-property for the {@code endDate} property. */ private final MetaProperty<LocalDate> endDate = DirectMetaProperty.ofImmutable( this, "endDate", ResolvedIborFixingDeposit.class, LocalDate.class); /** * The meta-property for the {@code yearFraction} property. */ private final MetaProperty<Double> yearFraction = DirectMetaProperty.ofImmutable( this, "yearFraction", ResolvedIborFixingDeposit.class, Double.TYPE); /** * The meta-property for the {@code fixedRate} property. */ private final MetaProperty<Double> fixedRate = DirectMetaProperty.ofImmutable( this, "fixedRate", ResolvedIborFixingDeposit.class, Double.TYPE); /** * The meta-property for the {@code floatingRate} property. */ private final MetaProperty<IborRateComputation> floatingRate = DirectMetaProperty.ofImmutable( this, "floatingRate", ResolvedIborFixingDeposit.class, IborRateComputation.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "currency", "notional", "startDate", "endDate", "yearFraction", "fixedRate", "floatingRate"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 575402001: // currency return currency; case 1585636160: // notional return notional; case -2129778896: // startDate return startDate; case -1607727319: // endDate return endDate; case -1731780257: // yearFraction return yearFraction; case 747425396: // fixedRate return fixedRate; case -2130225658: // floatingRate return floatingRate; } return super.metaPropertyGet(propertyName); } @Override public ResolvedIborFixingDeposit.Builder builder() { return new ResolvedIborFixingDeposit.Builder(); } @Override public Class<? extends ResolvedIborFixingDeposit> beanType() { return ResolvedIborFixingDeposit.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code currency} property. * @return the meta-property, not null */ public MetaProperty<Currency> currency() { return currency; } /** * The meta-property for the {@code notional} property. * @return the meta-property, not null */ public MetaProperty<Double> notional() { return notional; } /** * The meta-property for the {@code startDate} property. * @return the meta-property, not null */ public MetaProperty<LocalDate> startDate() { return startDate; } /** * The meta-property for the {@code endDate} property. * @return the meta-property, not null */ public MetaProperty<LocalDate> endDate() { return endDate; } /** * The meta-property for the {@code yearFraction} property. * @return the meta-property, not null */ public MetaProperty<Double> yearFraction() { return yearFraction; } /** * The meta-property for the {@code fixedRate} property. * @return the meta-property, not null */ public MetaProperty<Double> fixedRate() { return fixedRate; } /** * The meta-property for the {@code floatingRate} property. * @return the meta-property, not null */ public MetaProperty<IborRateComputation> floatingRate() { return floatingRate; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((ResolvedIborFixingDeposit) bean).getCurrency(); case 1585636160: // notional return ((ResolvedIborFixingDeposit) bean).getNotional(); case -2129778896: // startDate return ((ResolvedIborFixingDeposit) bean).getStartDate(); case -1607727319: // endDate return ((ResolvedIborFixingDeposit) bean).getEndDate(); case -1731780257: // yearFraction return ((ResolvedIborFixingDeposit) bean).getYearFraction(); case 747425396: // fixedRate return ((ResolvedIborFixingDeposit) bean).getFixedRate(); case -2130225658: // floatingRate return ((ResolvedIborFixingDeposit) bean).getFloatingRate(); } 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 ResolvedIborFixingDeposit}. */ public static final class Builder extends DirectFieldsBeanBuilder<ResolvedIborFixingDeposit> { private Currency currency; private double notional; private LocalDate startDate; private LocalDate endDate; private double yearFraction; private double fixedRate; private IborRateComputation floatingRate; /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedIborFixingDeposit beanToCopy) { this.currency = beanToCopy.getCurrency(); this.notional = beanToCopy.getNotional(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.yearFraction = beanToCopy.getYearFraction(); this.fixedRate = beanToCopy.getFixedRate(); this.floatingRate = beanToCopy.getFloatingRate(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 575402001: // currency return currency; case 1585636160: // notional return notional; case -2129778896: // startDate return startDate; case -1607727319: // endDate return endDate; case -1731780257: // yearFraction return yearFraction; case 747425396: // fixedRate return fixedRate; case -2130225658: // floatingRate return floatingRate; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case 575402001: // currency this.currency = (Currency) newValue; break; case 1585636160: // notional this.notional = (Double) newValue; break; case -2129778896: // startDate this.startDate = (LocalDate) newValue; break; case -1607727319: // endDate this.endDate = (LocalDate) newValue; break; case -1731780257: // yearFraction this.yearFraction = (Double) newValue; break; case 747425396: // fixedRate this.fixedRate = (Double) newValue; break; case -2130225658: // floatingRate this.floatingRate = (IborRateComputation) 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 ResolvedIborFixingDeposit build() { return new ResolvedIborFixingDeposit( currency, notional, startDate, endDate, yearFraction, fixedRate, floatingRate); } //----------------------------------------------------------------------- /** * Sets the primary currency. * <p> * This is the currency of the deposit and the currency that payment is made in. * The data model permits this currency to differ from that of the index, * however the two are typically the same. * @param currency the new value, not null * @return this, for chaining, not null */ public Builder currency(Currency currency) { JodaBeanUtils.notNull(currency, "currency"); this.currency = currency; return this; } /** * Sets the notional amount. * <p> * The amount that is deposited. It is a positive signed amount if the deposit is 'Buy', * and a negative signed amount if the deposit is 'Sell'. * <p> * The currency of the notional is specified by {@code currency}. * @param notional the new value * @return this, for chaining, not null */ public Builder notional(double notional) { this.notional = notional; return this; } /** * Sets the start date of the deposit. * <p> * This is the first date that interest accrues. * <p> * This is an adjusted date, which should be a valid business day * @param startDate the new value, not null * @return this, for chaining, not null */ public Builder startDate(LocalDate startDate) { JodaBeanUtils.notNull(startDate, "startDate"); this.startDate = startDate; return this; } /** * Sets the end date of the deposit. * <p> * This is the last day that interest accrues. * This date must be after the start date. * <p> * This is an adjusted date, which should be a valid business day * @param endDate the new value, not null * @return this, for chaining, not null */ public Builder endDate(LocalDate endDate) { JodaBeanUtils.notNull(endDate, "endDate"); this.endDate = endDate; return this; } /** * Sets the year fraction between the start and end date. * <p> * The value is usually calculated using a {@link DayCount}. * Typically the value will be close to 1 for one year and close to 0.5 for six months. * The fraction may be greater than 1, but not less than 0. * @param yearFraction the new value * @return this, for chaining, not null */ public Builder yearFraction(double yearFraction) { ArgChecker.notNegative(yearFraction, "yearFraction"); this.yearFraction = yearFraction; return this; } /** * Sets the fixed rate of interest. * A 5% rate will be expressed as 0.05. * @param fixedRate the new value * @return this, for chaining, not null */ public Builder fixedRate(double fixedRate) { this.fixedRate = fixedRate; return this; } /** * Sets the floating rate of interest. * <p> * The floating rate to be paid is based on this index. * It will be a well known market index such as 'GBP-LIBOR-3M'. * @param floatingRate the new value, not null * @return this, for chaining, not null */ public Builder floatingRate(IborRateComputation floatingRate) { JodaBeanUtils.notNull(floatingRate, "floatingRate"); this.floatingRate = floatingRate; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(256); buf.append("ResolvedIborFixingDeposit.Builder{"); buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' '); buf.append("notional").append('=').append(JodaBeanUtils.toString(notional)).append(',').append(' '); buf.append("startDate").append('=').append(JodaBeanUtils.toString(startDate)).append(',').append(' '); buf.append("endDate").append('=').append(JodaBeanUtils.toString(endDate)).append(',').append(' '); buf.append("yearFraction").append('=').append(JodaBeanUtils.toString(yearFraction)).append(',').append(' '); buf.append("fixedRate").append('=').append(JodaBeanUtils.toString(fixedRate)).append(',').append(' '); buf.append("floatingRate").append('=').append(JodaBeanUtils.toString(floatingRate)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }