Skip to content

Commit 77ed931

Browse files
JEAN-PROST Frédéricritonglue
authored andcommitted
Pricer-2592 add boolean isRegular to FixedCouponBondPaymentPeriod
1 parent aaf7e06 commit 77ed931

1 file changed

Lines changed: 76 additions & 8 deletions

File tree

modules/product/src/main/java/com/opengamma/strata/product/bond/FixedCouponBondPaymentPeriod.java

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ public final class FixedCouponBondPaymentPeriod
122122
*/
123123
@PropertyDefinition(validate = "ArgChecker.notNegative")
124124
private final double yearFraction;
125+
/**
126+
* Indicates if the is period is regular
127+
* <p>
128+
* The regular status of the period
129+
* <p>
130+
* It true the a full coupon is paid. Otherwise the period is shorter/longer
131+
*/
132+
@PropertyDefinition
133+
private final boolean isRegular;
125134

126135
//-------------------------------------------------------------------------
127136
// could use @ImmutablePreBuild and @ImmutableValidate but faster inline
@@ -135,7 +144,8 @@ private FixedCouponBondPaymentPeriod(
135144
LocalDate unadjustedEndDate,
136145
LocalDate detachmentDate,
137146
double fixedRate,
138-
double yearFraction) {
147+
double yearFraction,
148+
boolean isRegular) {
139149
this.currency = ArgChecker.notNull(currency, "currency");
140150
this.notional = notional;
141151
this.startDate = ArgChecker.notNull(startDate, "startDate");
@@ -145,6 +155,7 @@ private FixedCouponBondPaymentPeriod(
145155
this.detachmentDate = firstNonNull(detachmentDate, endDate);
146156
this.fixedRate = fixedRate;
147157
this.yearFraction = yearFraction;
158+
this.isRegular = isRegular;
148159
// check for unadjusted must be after firstNonNull
149160
ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate");
150161
ArgChecker.inOrderNotEqual(
@@ -339,6 +350,19 @@ public double getYearFraction() {
339350
return yearFraction;
340351
}
341352

353+
//-----------------------------------------------------------------------
354+
/**
355+
* Gets indicates if the is period is regular
356+
* <p>
357+
* The regular status of the period
358+
* <p>
359+
* It true the a full coupon is paid. Otherwise the period is shorter/longer
360+
* @return the value of the property
361+
*/
362+
public boolean isIsRegular() {
363+
return isRegular;
364+
}
365+
342366
//-----------------------------------------------------------------------
343367
/**
344368
* Returns a builder that allows this bean to be mutated.
@@ -363,7 +387,8 @@ public boolean equals(Object obj) {
363387
JodaBeanUtils.equal(unadjustedEndDate, other.unadjustedEndDate) &&
364388
JodaBeanUtils.equal(detachmentDate, other.detachmentDate) &&
365389
JodaBeanUtils.equal(fixedRate, other.fixedRate) &&
366-
JodaBeanUtils.equal(yearFraction, other.yearFraction);
390+
JodaBeanUtils.equal(yearFraction, other.yearFraction) &&
391+
(isRegular == other.isRegular);
367392
}
368393
return false;
369394
}
@@ -380,12 +405,13 @@ public int hashCode() {
380405
hash = hash * 31 + JodaBeanUtils.hashCode(detachmentDate);
381406
hash = hash * 31 + JodaBeanUtils.hashCode(fixedRate);
382407
hash = hash * 31 + JodaBeanUtils.hashCode(yearFraction);
408+
hash = hash * 31 + JodaBeanUtils.hashCode(isRegular);
383409
return hash;
384410
}
385411

386412
@Override
387413
public String toString() {
388-
StringBuilder buf = new StringBuilder(320);
414+
StringBuilder buf = new StringBuilder(352);
389415
buf.append("FixedCouponBondPaymentPeriod{");
390416
buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
391417
buf.append("notional").append('=').append(JodaBeanUtils.toString(notional)).append(',').append(' ');
@@ -395,7 +421,8 @@ public String toString() {
395421
buf.append("unadjustedEndDate").append('=').append(JodaBeanUtils.toString(unadjustedEndDate)).append(',').append(' ');
396422
buf.append("detachmentDate").append('=').append(JodaBeanUtils.toString(detachmentDate)).append(',').append(' ');
397423
buf.append("fixedRate").append('=').append(JodaBeanUtils.toString(fixedRate)).append(',').append(' ');
398-
buf.append("yearFraction").append('=').append(JodaBeanUtils.toString(yearFraction));
424+
buf.append("yearFraction").append('=').append(JodaBeanUtils.toString(yearFraction)).append(',').append(' ');
425+
buf.append("isRegular").append('=').append(JodaBeanUtils.toString(isRegular));
399426
buf.append('}');
400427
return buf.toString();
401428
}
@@ -455,6 +482,11 @@ public static final class Meta extends DirectMetaBean {
455482
*/
456483
private final MetaProperty<Double> yearFraction = DirectMetaProperty.ofImmutable(
457484
this, "yearFraction", FixedCouponBondPaymentPeriod.class, Double.TYPE);
485+
/**
486+
* The meta-property for the {@code isRegular} property.
487+
*/
488+
private final MetaProperty<Boolean> isRegular = DirectMetaProperty.ofImmutable(
489+
this, "isRegular", FixedCouponBondPaymentPeriod.class, Boolean.TYPE);
458490
/**
459491
* The meta-properties.
460492
*/
@@ -468,7 +500,8 @@ public static final class Meta extends DirectMetaBean {
468500
"unadjustedEndDate",
469501
"detachmentDate",
470502
"fixedRate",
471-
"yearFraction");
503+
"yearFraction",
504+
"isRegular");
472505

473506
/**
474507
* Restricted constructor.
@@ -497,6 +530,8 @@ protected MetaProperty<?> metaPropertyGet(String propertyName) {
497530
return fixedRate;
498531
case -1731780257: // yearFraction
499532
return yearFraction;
533+
case 506685202: // isRegular
534+
return isRegular;
500535
}
501536
return super.metaPropertyGet(propertyName);
502537
}
@@ -589,6 +624,14 @@ public MetaProperty<Double> yearFraction() {
589624
return yearFraction;
590625
}
591626

627+
/**
628+
* The meta-property for the {@code isRegular} property.
629+
* @return the meta-property, not null
630+
*/
631+
public MetaProperty<Boolean> isRegular() {
632+
return isRegular;
633+
}
634+
592635
//-----------------------------------------------------------------------
593636
@Override
594637
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
@@ -611,6 +654,8 @@ protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
611654
return ((FixedCouponBondPaymentPeriod) bean).getFixedRate();
612655
case -1731780257: // yearFraction
613656
return ((FixedCouponBondPaymentPeriod) bean).getYearFraction();
657+
case 506685202: // isRegular
658+
return ((FixedCouponBondPaymentPeriod) bean).isIsRegular();
614659
}
615660
return super.propertyGet(bean, propertyName, quiet);
616661
}
@@ -641,6 +686,7 @@ public static final class Builder extends DirectFieldsBeanBuilder<FixedCouponBon
641686
private LocalDate detachmentDate;
642687
private double fixedRate;
643688
private double yearFraction;
689+
private boolean isRegular;
644690

645691
/**
646692
* Restricted constructor.
@@ -662,6 +708,7 @@ private Builder(FixedCouponBondPaymentPeriod beanToCopy) {
662708
this.detachmentDate = beanToCopy.getDetachmentDate();
663709
this.fixedRate = beanToCopy.getFixedRate();
664710
this.yearFraction = beanToCopy.getYearFraction();
711+
this.isRegular = beanToCopy.isIsRegular();
665712
}
666713

667714
//-----------------------------------------------------------------------
@@ -686,6 +733,8 @@ public Object get(String propertyName) {
686733
return fixedRate;
687734
case -1731780257: // yearFraction
688735
return yearFraction;
736+
case 506685202: // isRegular
737+
return isRegular;
689738
default:
690739
throw new NoSuchElementException("Unknown property: " + propertyName);
691740
}
@@ -721,6 +770,9 @@ public Builder set(String propertyName, Object newValue) {
721770
case -1731780257: // yearFraction
722771
this.yearFraction = (Double) newValue;
723772
break;
773+
case 506685202: // isRegular
774+
this.isRegular = (Boolean) newValue;
775+
break;
724776
default:
725777
throw new NoSuchElementException("Unknown property: " + propertyName);
726778
}
@@ -744,7 +796,8 @@ public FixedCouponBondPaymentPeriod build() {
744796
unadjustedEndDate,
745797
detachmentDate,
746798
fixedRate,
747-
yearFraction);
799+
yearFraction,
800+
isRegular);
748801
}
749802

750803
//-----------------------------------------------------------------------
@@ -880,10 +933,24 @@ public Builder yearFraction(double yearFraction) {
880933
return this;
881934
}
882935

936+
/**
937+
* Sets indicates if the is period is regular
938+
* <p>
939+
* The regular status of the period
940+
* <p>
941+
* It true the a full coupon is paid. Otherwise the period is shorter/longer
942+
* @param isRegular the new value
943+
* @return this, for chaining, not null
944+
*/
945+
public Builder isRegular(boolean isRegular) {
946+
this.isRegular = isRegular;
947+
return this;
948+
}
949+
883950
//-----------------------------------------------------------------------
884951
@Override
885952
public String toString() {
886-
StringBuilder buf = new StringBuilder(320);
953+
StringBuilder buf = new StringBuilder(352);
887954
buf.append("FixedCouponBondPaymentPeriod.Builder{");
888955
buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
889956
buf.append("notional").append('=').append(JodaBeanUtils.toString(notional)).append(',').append(' ');
@@ -893,7 +960,8 @@ public String toString() {
893960
buf.append("unadjustedEndDate").append('=').append(JodaBeanUtils.toString(unadjustedEndDate)).append(',').append(' ');
894961
buf.append("detachmentDate").append('=').append(JodaBeanUtils.toString(detachmentDate)).append(',').append(' ');
895962
buf.append("fixedRate").append('=').append(JodaBeanUtils.toString(fixedRate)).append(',').append(' ');
896-
buf.append("yearFraction").append('=').append(JodaBeanUtils.toString(yearFraction));
963+
buf.append("yearFraction").append('=').append(JodaBeanUtils.toString(yearFraction)).append(',').append(' ');
964+
buf.append("isRegular").append('=').append(JodaBeanUtils.toString(isRegular));
897965
buf.append('}');
898966
return buf.toString();
899967
}

0 commit comments

Comments
 (0)