com.opengamma.strata.finance.rate.bond.FixedCouponBond.java Source code

Java tutorial

Introduction

Here is the source code for com.opengamma.strata.finance.rate.bond.FixedCouponBond.java

Source

/**
 * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.finance.rate.bond;

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.ImmutablePreBuild;
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.google.common.collect.ImmutableList;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.basics.currency.CurrencyAmount;
import com.opengamma.strata.basics.currency.Payment;
import com.opengamma.strata.basics.date.DayCount;
import com.opengamma.strata.basics.date.DaysAdjustment;
import com.opengamma.strata.basics.schedule.PeriodicSchedule;
import com.opengamma.strata.basics.schedule.Schedule;
import com.opengamma.strata.basics.schedule.SchedulePeriod;
import com.opengamma.strata.collect.ArgChecker;
import com.opengamma.strata.collect.id.StandardId;

/**
 * A fixed coupon bond.
 * <p>
 * A fixed coupon bond is a financial instrument that represents a stream of fixed payments. 
 * The payments consist two types: periodic coupon payments and nominal payment.
 * The periodic payments are made {@code n} times a year with a fixed coupon rate at individual coupon dates.   
 * The nominal payment is the unique payment at the final coupon date.
 * <p>
 * The periodic coupon payment schedule is defined using {@link PeriodicSchedule}. 
 * The payment amount is computed with {@code fixedRate} and {@code notionalAmount}. 
 * The nominal payment is defined from the last period of the periodic coupon payment schedule and {@code notionalAmount}. 
 * <p>
 * The accrual factor between two dates is computed {@code dayCount}. 
 * The legal entity of this fixed coupon bond is identified by {@link StandardId}.
 * The enum, {@link YieldConvention}, specifies the yield computation convention.
 */
@BeanDefinition
public final class FixedCouponBond implements FixedCouponBondProduct, ImmutableBean, Serializable {

    /**
     * The primary currency of the product.
     * <p>
     * The amounts of the notional are usually expressed in terms of this currency,
     * however they can be converted from amounts in a different currency.
     */
    @PropertyDefinition(validate = "notNull")
    private final Currency currency;
    /**
     * The notional amount, must be positive. 
     * <p>
     * The notional expressed here must be positive.
     * The currency of the notional is specified by {@code currency}.
     */
    @PropertyDefinition(validate = "ArgChecker.notNegative")
    private final double notional;
    /**
     * The accrual schedule.
     * <p>
     * This is used to define the accrual periods.
     * These are used directly or indirectly to determine other dates in the product.
     */
    @PropertyDefinition(validate = "notNull")
    private final PeriodicSchedule periodicSchedule;
    /**
     * The fixed coupon rate. 
     * <p>
     * The periodic payments are based on this fixed coupon rate.
     */
    @PropertyDefinition
    private final double fixedRate;
    /**
     * The day count convention applicable. 
     * <p>
     * The conversion from dates to a numerical value is made based on this day count. 
     * For the fixed bond, the day count convention is used to compute accrued interest.
     * <p>
     * Note that the year fraction of a coupon payment is computed based on the unadjusted
     * dates in the schedule.
     */
    @PropertyDefinition(validate = "notNull")
    private final DayCount dayCount;
    /**
     * Yield convention.
     * <p>
     * The convention defines how to convert from yield to price and inversely.  
     */
    @PropertyDefinition(validate = "notNull")
    private final YieldConvention yieldConvention;
    /**
     * The legal entity identifier.
     * <p>
     * This identifier is used for the legal entity which issues the fixed coupon bond product. 
     */
    @PropertyDefinition(validate = "notNull")
    private final StandardId legalEntityId;
    /**
     * The number of days between valuation date and settlement date. 
     * <p>
     * This is used to compute clean price. 
     * The clean price is the relative price to be paid at the standard settlement date in exchange for the bond.
     * <p>
     * It is usually one business day for US treasuries and UK Gilts and three days for Euroland government bonds. 
     */
    @PropertyDefinition(validate = "notNull")
    private final DaysAdjustment settlementDateOffset;
    /**
     * Ex-coupon period. 
     * <p>
     * Some bonds trade ex-coupons before the coupon payment. The coupon is paid not to the
     * owner of the bond on the payment date but to the owner of the bond on the detachment date.
     * The difference between the two is the ex-coupon period (measured in days).
     * <p>
     * Because the detachment date is not after the coupon date, the number of days
     * stored in this field should be zero or negative. 
     */
    @PropertyDefinition(validate = "notNull")
    private final DaysAdjustment exCouponPeriod;

    //-------------------------------------------------------------------------
    @ImmutablePreBuild
    private static void preBuild(Builder builder) {
        if (builder.exCouponPeriod == null) {
            builder.exCouponPeriod = DaysAdjustment.NONE;
        }
    }

    @ImmutableValidator
    private void validate() {
        ArgChecker.isTrue(settlementDateOffset.getDays() >= 0d, "The settlement date offset must be non-negative");
        ArgChecker.isTrue(exCouponPeriod.getDays() <= 0d,
                "The ex-coupon period is measured from the payment date, thus the days must be non-positive");
    }

    //-------------------------------------------------------------------------
    @Override
    public ExpandedFixedCouponBond expand() {
        Schedule adjustedSchedule = periodicSchedule.createSchedule();
        Schedule unadjustedSchedule = adjustedSchedule.toUnadjusted();
        ImmutableList.Builder<FixedCouponBondPaymentPeriod> accrualPeriods = ImmutableList.builder();
        for (int i = 0; i < adjustedSchedule.size(); i++) {
            SchedulePeriod period = adjustedSchedule.getPeriod(i);
            SchedulePeriod unadjustedPeriod = SchedulePeriod.of(period.getUnadjustedStartDate(),
                    period.getUnadjustedEndDate());
            accrualPeriods
                    .add(FixedCouponBondPaymentPeriod.builder().unadjustedStartDate(period.getUnadjustedStartDate())
                            .unadjustedEndDate(period.getUnadjustedEndDate()).startDate(period.getStartDate())
                            .endDate(period.getEndDate()).detachmentDate(exCouponPeriod.adjust(period.getEndDate()))
                            .notional(notional).currency(currency).fixedRate(fixedRate)
                            .yearFraction(unadjustedPeriod.yearFraction(dayCount, unadjustedSchedule)).build());
        }
        ImmutableList<FixedCouponBondPaymentPeriod> periodicPayments = accrualPeriods.build();
        FixedCouponBondPaymentPeriod lastPeriod = periodicPayments.get(periodicPayments.size() - 1);
        Payment nominalPayment = Payment.of(CurrencyAmount.of(currency, notional), lastPeriod.getPaymentDate());
        return ExpandedFixedCouponBond.builder().legalEntityId(legalEntityId).nominalPayment(nominalPayment)
                .periodicPayments(ImmutableList.copyOf(periodicPayments)).dayCount(dayCount)
                .yieldConvention(yieldConvention).settlementDateOffset(settlementDateOffset).build();
    }

    //------------------------- AUTOGENERATED START -------------------------
    ///CLOVER:OFF
    /**
     * The meta-bean for {@code FixedCouponBond}.
     * @return the meta-bean, not null
     */
    public static FixedCouponBond.Meta meta() {
        return FixedCouponBond.Meta.INSTANCE;
    }

    static {
        JodaBeanUtils.registerMetaBean(FixedCouponBond.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 FixedCouponBond.Builder builder() {
        return new FixedCouponBond.Builder();
    }

    private FixedCouponBond(Currency currency, double notional, PeriodicSchedule periodicSchedule, double fixedRate,
            DayCount dayCount, YieldConvention yieldConvention, StandardId legalEntityId,
            DaysAdjustment settlementDateOffset, DaysAdjustment exCouponPeriod) {
        JodaBeanUtils.notNull(currency, "currency");
        ArgChecker.notNegative(notional, "notional");
        JodaBeanUtils.notNull(periodicSchedule, "periodicSchedule");
        JodaBeanUtils.notNull(dayCount, "dayCount");
        JodaBeanUtils.notNull(yieldConvention, "yieldConvention");
        JodaBeanUtils.notNull(legalEntityId, "legalEntityId");
        JodaBeanUtils.notNull(settlementDateOffset, "settlementDateOffset");
        JodaBeanUtils.notNull(exCouponPeriod, "exCouponPeriod");
        this.currency = currency;
        this.notional = notional;
        this.periodicSchedule = periodicSchedule;
        this.fixedRate = fixedRate;
        this.dayCount = dayCount;
        this.yieldConvention = yieldConvention;
        this.legalEntityId = legalEntityId;
        this.settlementDateOffset = settlementDateOffset;
        this.exCouponPeriod = exCouponPeriod;
        validate();
    }

    @Override
    public FixedCouponBond.Meta metaBean() {
        return FixedCouponBond.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 of the product.
     * <p>
     * The amounts of the notional are usually expressed in terms of this currency,
     * however they can be converted from amounts in a different currency.
     * @return the value of the property, not null
     */
    public Currency getCurrency() {
        return currency;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the notional amount, must be positive.
     * <p>
     * The notional expressed here must be positive.
     * The currency of the notional is specified by {@code currency}.
     * @return the value of the property
     */
    public double getNotional() {
        return notional;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the accrual schedule.
     * <p>
     * This is used to define the accrual periods.
     * These are used directly or indirectly to determine other dates in the product.
     * @return the value of the property, not null
     */
    public PeriodicSchedule getPeriodicSchedule() {
        return periodicSchedule;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the fixed coupon rate.
     * <p>
     * The periodic payments are based on this fixed coupon rate.
     * @return the value of the property
     */
    public double getFixedRate() {
        return fixedRate;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the day count convention applicable.
     * <p>
     * The conversion from dates to a numerical value is made based on this day count.
     * For the fixed bond, the day count convention is used to compute accrued interest.
     * <p>
     * Note that the year fraction of a coupon payment is computed based on the unadjusted
     * dates in the schedule.
     * @return the value of the property, not null
     */
    public DayCount getDayCount() {
        return dayCount;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets yield convention.
     * <p>
     * The convention defines how to convert from yield to price and inversely.
     * @return the value of the property, not null
     */
    public YieldConvention getYieldConvention() {
        return yieldConvention;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the legal entity identifier.
     * <p>
     * This identifier is used for the legal entity which issues the fixed coupon bond product.
     * @return the value of the property, not null
     */
    public StandardId getLegalEntityId() {
        return legalEntityId;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the number of days between valuation date and settlement date.
     * <p>
     * This is used to compute clean price.
     * The clean price is the relative price to be paid at the standard settlement date in exchange for the bond.
     * <p>
     * It is usually one business day for US treasuries and UK Gilts and three days for Euroland government bonds.
     * @return the value of the property, not null
     */
    public DaysAdjustment getSettlementDateOffset() {
        return settlementDateOffset;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets ex-coupon period.
     * <p>
     * Some bonds trade ex-coupons before the coupon payment. The coupon is paid not to the
     * owner of the bond on the payment date but to the owner of the bond on the detachment date.
     * The difference between the two is the ex-coupon period (measured in days).
     * <p>
     * Because the detachment date is not after the coupon date, the number of days
     * stored in this field should be zero or negative.
     * @return the value of the property, not null
     */
    public DaysAdjustment getExCouponPeriod() {
        return exCouponPeriod;
    }

    //-----------------------------------------------------------------------
    /**
     * 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()) {
            FixedCouponBond other = (FixedCouponBond) obj;
            return JodaBeanUtils.equal(getCurrency(), other.getCurrency())
                    && JodaBeanUtils.equal(getNotional(), other.getNotional())
                    && JodaBeanUtils.equal(getPeriodicSchedule(), other.getPeriodicSchedule())
                    && JodaBeanUtils.equal(getFixedRate(), other.getFixedRate())
                    && JodaBeanUtils.equal(getDayCount(), other.getDayCount())
                    && JodaBeanUtils.equal(getYieldConvention(), other.getYieldConvention())
                    && JodaBeanUtils.equal(getLegalEntityId(), other.getLegalEntityId())
                    && JodaBeanUtils.equal(getSettlementDateOffset(), other.getSettlementDateOffset())
                    && JodaBeanUtils.equal(getExCouponPeriod(), other.getExCouponPeriod());
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = getClass().hashCode();
        hash = hash * 31 + JodaBeanUtils.hashCode(getCurrency());
        hash = hash * 31 + JodaBeanUtils.hashCode(getNotional());
        hash = hash * 31 + JodaBeanUtils.hashCode(getPeriodicSchedule());
        hash = hash * 31 + JodaBeanUtils.hashCode(getFixedRate());
        hash = hash * 31 + JodaBeanUtils.hashCode(getDayCount());
        hash = hash * 31 + JodaBeanUtils.hashCode(getYieldConvention());
        hash = hash * 31 + JodaBeanUtils.hashCode(getLegalEntityId());
        hash = hash * 31 + JodaBeanUtils.hashCode(getSettlementDateOffset());
        hash = hash * 31 + JodaBeanUtils.hashCode(getExCouponPeriod());
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder(320);
        buf.append("FixedCouponBond{");
        buf.append("currency").append('=').append(getCurrency()).append(',').append(' ');
        buf.append("notional").append('=').append(getNotional()).append(',').append(' ');
        buf.append("periodicSchedule").append('=').append(getPeriodicSchedule()).append(',').append(' ');
        buf.append("fixedRate").append('=').append(getFixedRate()).append(',').append(' ');
        buf.append("dayCount").append('=').append(getDayCount()).append(',').append(' ');
        buf.append("yieldConvention").append('=').append(getYieldConvention()).append(',').append(' ');
        buf.append("legalEntityId").append('=').append(getLegalEntityId()).append(',').append(' ');
        buf.append("settlementDateOffset").append('=').append(getSettlementDateOffset()).append(',').append(' ');
        buf.append("exCouponPeriod").append('=').append(JodaBeanUtils.toString(getExCouponPeriod()));
        buf.append('}');
        return buf.toString();
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-bean for {@code FixedCouponBond}.
     */
    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",
                FixedCouponBond.class, Currency.class);
        /**
         * The meta-property for the {@code notional} property.
         */
        private final MetaProperty<Double> notional = DirectMetaProperty.ofImmutable(this, "notional",
                FixedCouponBond.class, Double.TYPE);
        /**
         * The meta-property for the {@code periodicSchedule} property.
         */
        private final MetaProperty<PeriodicSchedule> periodicSchedule = DirectMetaProperty.ofImmutable(this,
                "periodicSchedule", FixedCouponBond.class, PeriodicSchedule.class);
        /**
         * The meta-property for the {@code fixedRate} property.
         */
        private final MetaProperty<Double> fixedRate = DirectMetaProperty.ofImmutable(this, "fixedRate",
                FixedCouponBond.class, Double.TYPE);
        /**
         * The meta-property for the {@code dayCount} property.
         */
        private final MetaProperty<DayCount> dayCount = DirectMetaProperty.ofImmutable(this, "dayCount",
                FixedCouponBond.class, DayCount.class);
        /**
         * The meta-property for the {@code yieldConvention} property.
         */
        private final MetaProperty<YieldConvention> yieldConvention = DirectMetaProperty.ofImmutable(this,
                "yieldConvention", FixedCouponBond.class, YieldConvention.class);
        /**
         * The meta-property for the {@code legalEntityId} property.
         */
        private final MetaProperty<StandardId> legalEntityId = DirectMetaProperty.ofImmutable(this, "legalEntityId",
                FixedCouponBond.class, StandardId.class);
        /**
         * The meta-property for the {@code settlementDateOffset} property.
         */
        private final MetaProperty<DaysAdjustment> settlementDateOffset = DirectMetaProperty.ofImmutable(this,
                "settlementDateOffset", FixedCouponBond.class, DaysAdjustment.class);
        /**
         * The meta-property for the {@code exCouponPeriod} property.
         */
        private final MetaProperty<DaysAdjustment> exCouponPeriod = DirectMetaProperty.ofImmutable(this,
                "exCouponPeriod", FixedCouponBond.class, DaysAdjustment.class);
        /**
         * The meta-properties.
         */
        private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(this, null,
                "currency", "notional", "periodicSchedule", "fixedRate", "dayCount", "yieldConvention",
                "legalEntityId", "settlementDateOffset", "exCouponPeriod");

        /**
         * Restricted constructor.
         */
        private Meta() {
        }

        @Override
        protected MetaProperty<?> metaPropertyGet(String propertyName) {
            switch (propertyName.hashCode()) {
            case 575402001: // currency
                return currency;
            case 1585636160: // notional
                return notional;
            case 1847018066: // periodicSchedule
                return periodicSchedule;
            case 747425396: // fixedRate
                return fixedRate;
            case 1905311443: // dayCount
                return dayCount;
            case -1895216418: // yieldConvention
                return yieldConvention;
            case 866287159: // legalEntityId
                return legalEntityId;
            case 135924714: // settlementDateOffset
                return settlementDateOffset;
            case 1408037338: // exCouponPeriod
                return exCouponPeriod;
            }
            return super.metaPropertyGet(propertyName);
        }

        @Override
        public FixedCouponBond.Builder builder() {
            return new FixedCouponBond.Builder();
        }

        @Override
        public Class<? extends FixedCouponBond> beanType() {
            return FixedCouponBond.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 periodicSchedule} property.
         * @return the meta-property, not null
         */
        public MetaProperty<PeriodicSchedule> periodicSchedule() {
            return periodicSchedule;
        }

        /**
         * 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 dayCount} property.
         * @return the meta-property, not null
         */
        public MetaProperty<DayCount> dayCount() {
            return dayCount;
        }

        /**
         * The meta-property for the {@code yieldConvention} property.
         * @return the meta-property, not null
         */
        public MetaProperty<YieldConvention> yieldConvention() {
            return yieldConvention;
        }

        /**
         * The meta-property for the {@code legalEntityId} property.
         * @return the meta-property, not null
         */
        public MetaProperty<StandardId> legalEntityId() {
            return legalEntityId;
        }

        /**
         * The meta-property for the {@code settlementDateOffset} property.
         * @return the meta-property, not null
         */
        public MetaProperty<DaysAdjustment> settlementDateOffset() {
            return settlementDateOffset;
        }

        /**
         * The meta-property for the {@code exCouponPeriod} property.
         * @return the meta-property, not null
         */
        public MetaProperty<DaysAdjustment> exCouponPeriod() {
            return exCouponPeriod;
        }

        //-----------------------------------------------------------------------
        @Override
        protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
            switch (propertyName.hashCode()) {
            case 575402001: // currency
                return ((FixedCouponBond) bean).getCurrency();
            case 1585636160: // notional
                return ((FixedCouponBond) bean).getNotional();
            case 1847018066: // periodicSchedule
                return ((FixedCouponBond) bean).getPeriodicSchedule();
            case 747425396: // fixedRate
                return ((FixedCouponBond) bean).getFixedRate();
            case 1905311443: // dayCount
                return ((FixedCouponBond) bean).getDayCount();
            case -1895216418: // yieldConvention
                return ((FixedCouponBond) bean).getYieldConvention();
            case 866287159: // legalEntityId
                return ((FixedCouponBond) bean).getLegalEntityId();
            case 135924714: // settlementDateOffset
                return ((FixedCouponBond) bean).getSettlementDateOffset();
            case 1408037338: // exCouponPeriod
                return ((FixedCouponBond) bean).getExCouponPeriod();
            }
            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 FixedCouponBond}.
     */
    public static final class Builder extends DirectFieldsBeanBuilder<FixedCouponBond> {

        private Currency currency;
        private double notional;
        private PeriodicSchedule periodicSchedule;
        private double fixedRate;
        private DayCount dayCount;
        private YieldConvention yieldConvention;
        private StandardId legalEntityId;
        private DaysAdjustment settlementDateOffset;
        private DaysAdjustment exCouponPeriod;

        /**
         * Restricted constructor.
         */
        private Builder() {
        }

        /**
         * Restricted copy constructor.
         * @param beanToCopy  the bean to copy from, not null
         */
        private Builder(FixedCouponBond beanToCopy) {
            this.currency = beanToCopy.getCurrency();
            this.notional = beanToCopy.getNotional();
            this.periodicSchedule = beanToCopy.getPeriodicSchedule();
            this.fixedRate = beanToCopy.getFixedRate();
            this.dayCount = beanToCopy.getDayCount();
            this.yieldConvention = beanToCopy.getYieldConvention();
            this.legalEntityId = beanToCopy.getLegalEntityId();
            this.settlementDateOffset = beanToCopy.getSettlementDateOffset();
            this.exCouponPeriod = beanToCopy.getExCouponPeriod();
        }

        //-----------------------------------------------------------------------
        @Override
        public Object get(String propertyName) {
            switch (propertyName.hashCode()) {
            case 575402001: // currency
                return currency;
            case 1585636160: // notional
                return notional;
            case 1847018066: // periodicSchedule
                return periodicSchedule;
            case 747425396: // fixedRate
                return fixedRate;
            case 1905311443: // dayCount
                return dayCount;
            case -1895216418: // yieldConvention
                return yieldConvention;
            case 866287159: // legalEntityId
                return legalEntityId;
            case 135924714: // settlementDateOffset
                return settlementDateOffset;
            case 1408037338: // exCouponPeriod
                return exCouponPeriod;
            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 1847018066: // periodicSchedule
                this.periodicSchedule = (PeriodicSchedule) newValue;
                break;
            case 747425396: // fixedRate
                this.fixedRate = (Double) newValue;
                break;
            case 1905311443: // dayCount
                this.dayCount = (DayCount) newValue;
                break;
            case -1895216418: // yieldConvention
                this.yieldConvention = (YieldConvention) newValue;
                break;
            case 866287159: // legalEntityId
                this.legalEntityId = (StandardId) newValue;
                break;
            case 135924714: // settlementDateOffset
                this.settlementDateOffset = (DaysAdjustment) newValue;
                break;
            case 1408037338: // exCouponPeriod
                this.exCouponPeriod = (DaysAdjustment) 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 FixedCouponBond build() {
            preBuild(this);
            return new FixedCouponBond(currency, notional, periodicSchedule, fixedRate, dayCount, yieldConvention,
                    legalEntityId, settlementDateOffset, exCouponPeriod);
        }

        //-----------------------------------------------------------------------
        /**
         * Sets the primary currency of the product.
         * <p>
         * The amounts of the notional are usually expressed in terms of this currency,
         * however they can be converted from amounts in a different currency.
         * @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, must be positive.
         * <p>
         * The notional expressed here must be positive.
         * 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) {
            ArgChecker.notNegative(notional, "notional");
            this.notional = notional;
            return this;
        }

        /**
         * Sets the accrual schedule.
         * <p>
         * This is used to define the accrual periods.
         * These are used directly or indirectly to determine other dates in the product.
         * @param periodicSchedule  the new value, not null
         * @return this, for chaining, not null
         */
        public Builder periodicSchedule(PeriodicSchedule periodicSchedule) {
            JodaBeanUtils.notNull(periodicSchedule, "periodicSchedule");
            this.periodicSchedule = periodicSchedule;
            return this;
        }

        /**
         * Sets the fixed coupon rate.
         * <p>
         * The periodic payments are based on this fixed coupon rate.
         * @param fixedRate  the new value
         * @return this, for chaining, not null
         */
        public Builder fixedRate(double fixedRate) {
            this.fixedRate = fixedRate;
            return this;
        }

        /**
         * Sets the day count convention applicable.
         * <p>
         * The conversion from dates to a numerical value is made based on this day count.
         * For the fixed bond, the day count convention is used to compute accrued interest.
         * <p>
         * Note that the year fraction of a coupon payment is computed based on the unadjusted
         * dates in the schedule.
         * @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 yield convention.
         * <p>
         * The convention defines how to convert from yield to price and inversely.
         * @param yieldConvention  the new value, not null
         * @return this, for chaining, not null
         */
        public Builder yieldConvention(YieldConvention yieldConvention) {
            JodaBeanUtils.notNull(yieldConvention, "yieldConvention");
            this.yieldConvention = yieldConvention;
            return this;
        }

        /**
         * Sets the legal entity identifier.
         * <p>
         * This identifier is used for the legal entity which issues the fixed coupon bond product.
         * @param legalEntityId  the new value, not null
         * @return this, for chaining, not null
         */
        public Builder legalEntityId(StandardId legalEntityId) {
            JodaBeanUtils.notNull(legalEntityId, "legalEntityId");
            this.legalEntityId = legalEntityId;
            return this;
        }

        /**
         * Sets the number of days between valuation date and settlement date.
         * <p>
         * This is used to compute clean price.
         * The clean price is the relative price to be paid at the standard settlement date in exchange for the bond.
         * <p>
         * It is usually one business day for US treasuries and UK Gilts and three days for Euroland government bonds.
         * @param settlementDateOffset  the new value, not null
         * @return this, for chaining, not null
         */
        public Builder settlementDateOffset(DaysAdjustment settlementDateOffset) {
            JodaBeanUtils.notNull(settlementDateOffset, "settlementDateOffset");
            this.settlementDateOffset = settlementDateOffset;
            return this;
        }

        /**
         * Sets ex-coupon period.
         * <p>
         * Some bonds trade ex-coupons before the coupon payment. The coupon is paid not to the
         * owner of the bond on the payment date but to the owner of the bond on the detachment date.
         * The difference between the two is the ex-coupon period (measured in days).
         * <p>
         * Because the detachment date is not after the coupon date, the number of days
         * stored in this field should be zero or negative.
         * @param exCouponPeriod  the new value, not null
         * @return this, for chaining, not null
         */
        public Builder exCouponPeriod(DaysAdjustment exCouponPeriod) {
            JodaBeanUtils.notNull(exCouponPeriod, "exCouponPeriod");
            this.exCouponPeriod = exCouponPeriod;
            return this;
        }

        //-----------------------------------------------------------------------
        @Override
        public String toString() {
            StringBuilder buf = new StringBuilder(320);
            buf.append("FixedCouponBond.Builder{");
            buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
            buf.append("notional").append('=').append(JodaBeanUtils.toString(notional)).append(',').append(' ');
            buf.append("periodicSchedule").append('=').append(JodaBeanUtils.toString(periodicSchedule)).append(',')
                    .append(' ');
            buf.append("fixedRate").append('=').append(JodaBeanUtils.toString(fixedRate)).append(',').append(' ');
            buf.append("dayCount").append('=').append(JodaBeanUtils.toString(dayCount)).append(',').append(' ');
            buf.append("yieldConvention").append('=').append(JodaBeanUtils.toString(yieldConvention)).append(',')
                    .append(' ');
            buf.append("legalEntityId").append('=').append(JodaBeanUtils.toString(legalEntityId)).append(',')
                    .append(' ');
            buf.append("settlementDateOffset").append('=').append(JodaBeanUtils.toString(settlementDateOffset))
                    .append(',').append(' ');
            buf.append("exCouponPeriod").append('=').append(JodaBeanUtils.toString(exCouponPeriod));
            buf.append('}');
            return buf.toString();
        }

    }

    ///CLOVER:ON
    //-------------------------- AUTOGENERATED END --------------------------
}