/
BondFutureOptionTrade.java
559 lines (505 loc) · 17.5 KB
/
BondFutureOptionTrade.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/*
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product.bond;
import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;
import org.joda.beans.Bean;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.ImmutableDefaults;
import org.joda.beans.gen.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.collect.ArgChecker;
import com.opengamma.strata.product.PortfolioItemInfo;
import com.opengamma.strata.product.PortfolioItemSummary;
import com.opengamma.strata.product.ProductType;
import com.opengamma.strata.product.ResolvableTrade;
import com.opengamma.strata.product.SecuritizedProductTrade;
import com.opengamma.strata.product.TradeInfo;
import com.opengamma.strata.product.TradedPrice;
import com.opengamma.strata.product.common.SummarizerUtils;
/**
* A trade representing an option on a futures contract based on bonds.
* <p>
* A trade in an underlying {@link BondFutureOption}.
* The option is American, exercised at any point up to the exercise time.
* Both daily margin and upfront premium styles are handled.
*
* <h4>Price</h4>
* Strata uses <i>decimal prices</i> for bond futures options in the trade model, pricers and market data.
* This is coherent with the pricing of {@link BondFuture}.
*/
@BeanDefinition(constructorScope = "package")
public final class BondFutureOptionTrade
implements
SecuritizedProductTrade<BondFutureOption>, ResolvableTrade<ResolvedBondFutureOptionTrade>, ImmutableBean, Serializable {
/**
* The additional trade information, defaulted to an empty instance.
* <p>
* This allows additional information to be attached to the trade.
* The trade date is required when calling {@link BondFutureOptionTrade#resolve(ReferenceData)}.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final TradeInfo info;
/**
* The option that was traded.
* <p>
* The product captures the contracted financial details of the trade.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final BondFutureOption product;
/**
* The quantity that was traded.
* <p>
* This is the number of contracts that were traded.
* This will be positive if buying and negative if selling.
*/
@PropertyDefinition(overrideGet = true)
private final double quantity;
/**
* The price that was traded, in decimal form.
* <p>
* This is the price agreed when the trade occurred.
*/
@PropertyDefinition(validate = "ArgChecker.notNegative", overrideGet = true)
private final double price;
//-------------------------------------------------------------------------
@ImmutableDefaults
private static void applyDefaults(Builder builder) {
builder.info = TradeInfo.empty();
}
//-------------------------------------------------------------------------
@Override
public BondFutureOptionTrade withInfo(PortfolioItemInfo info) {
return new BondFutureOptionTrade(TradeInfo.from(info), product, quantity, price);
}
@Override
public BondFutureOptionTrade withQuantity(double quantity) {
return new BondFutureOptionTrade(info, product, quantity, price);
}
@Override
public BondFutureOptionTrade withPrice(double price) {
return new BondFutureOptionTrade(info, product, quantity, price);
}
//-------------------------------------------------------------------------
@Override
public PortfolioItemSummary summarize() {
// ID x 200
String description = getSecurityId().getStandardId().getValue() + " x " + SummarizerUtils.value(getQuantity());
return SummarizerUtils.summary(this, ProductType.BOND_FUTURE_OPTION, description, getCurrency());
}
@Override
public ResolvedBondFutureOptionTrade resolve(ReferenceData refData) {
if (!info.getTradeDate().isPresent()) {
throw new IllegalArgumentException("Trade date on TradeInfo must be present");
}
ResolvedBondFutureOption resolved = getProduct().resolve(refData);
TradedPrice tradedPrice = TradedPrice.of(info.getTradeDate().get(), price);
return new ResolvedBondFutureOptionTrade(info, resolved, quantity, tradedPrice);
}
//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code BondFutureOptionTrade}.
* @return the meta-bean, not null
*/
public static BondFutureOptionTrade.Meta meta() {
return BondFutureOptionTrade.Meta.INSTANCE;
}
static {
MetaBean.register(BondFutureOptionTrade.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 BondFutureOptionTrade.Builder builder() {
return new BondFutureOptionTrade.Builder();
}
/**
* Creates an instance.
* @param info the value of the property, not null
* @param product the value of the property, not null
* @param quantity the value of the property
* @param price the value of the property
*/
BondFutureOptionTrade(
TradeInfo info,
BondFutureOption product,
double quantity,
double price) {
JodaBeanUtils.notNull(info, "info");
JodaBeanUtils.notNull(product, "product");
ArgChecker.notNegative(price, "price");
this.info = info;
this.product = product;
this.quantity = quantity;
this.price = price;
}
@Override
public BondFutureOptionTrade.Meta metaBean() {
return BondFutureOptionTrade.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the additional trade information, defaulted to an empty instance.
* <p>
* This allows additional information to be attached to the trade.
* The trade date is required when calling {@link BondFutureOptionTrade#resolve(ReferenceData)}.
* @return the value of the property, not null
*/
@Override
public TradeInfo getInfo() {
return info;
}
//-----------------------------------------------------------------------
/**
* Gets the option that was traded.
* <p>
* The product captures the contracted financial details of the trade.
* @return the value of the property, not null
*/
@Override
public BondFutureOption getProduct() {
return product;
}
//-----------------------------------------------------------------------
/**
* Gets the quantity that was traded.
* <p>
* This is the number of contracts that were traded.
* This will be positive if buying and negative if selling.
* @return the value of the property
*/
@Override
public double getQuantity() {
return quantity;
}
//-----------------------------------------------------------------------
/**
* Gets the price that was traded, in decimal form.
* <p>
* This is the price agreed when the trade occurred.
* @return the value of the property
*/
@Override
public double getPrice() {
return price;
}
//-----------------------------------------------------------------------
/**
* 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()) {
BondFutureOptionTrade other = (BondFutureOptionTrade) obj;
return JodaBeanUtils.equal(info, other.info) &&
JodaBeanUtils.equal(product, other.product) &&
JodaBeanUtils.equal(quantity, other.quantity) &&
JodaBeanUtils.equal(price, other.price);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(info);
hash = hash * 31 + JodaBeanUtils.hashCode(product);
hash = hash * 31 + JodaBeanUtils.hashCode(quantity);
hash = hash * 31 + JodaBeanUtils.hashCode(price);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(160);
buf.append("BondFutureOptionTrade{");
buf.append("info").append('=').append(info).append(',').append(' ');
buf.append("product").append('=').append(product).append(',').append(' ');
buf.append("quantity").append('=').append(quantity).append(',').append(' ');
buf.append("price").append('=').append(JodaBeanUtils.toString(price));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code BondFutureOptionTrade}.
*/
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 info} property.
*/
private final MetaProperty<TradeInfo> info = DirectMetaProperty.ofImmutable(
this, "info", BondFutureOptionTrade.class, TradeInfo.class);
/**
* The meta-property for the {@code product} property.
*/
private final MetaProperty<BondFutureOption> product = DirectMetaProperty.ofImmutable(
this, "product", BondFutureOptionTrade.class, BondFutureOption.class);
/**
* The meta-property for the {@code quantity} property.
*/
private final MetaProperty<Double> quantity = DirectMetaProperty.ofImmutable(
this, "quantity", BondFutureOptionTrade.class, Double.TYPE);
/**
* The meta-property for the {@code price} property.
*/
private final MetaProperty<Double> price = DirectMetaProperty.ofImmutable(
this, "price", BondFutureOptionTrade.class, Double.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"info",
"product",
"quantity",
"price");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
case -309474065: // product
return product;
case -1285004149: // quantity
return quantity;
case 106934601: // price
return price;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BondFutureOptionTrade.Builder builder() {
return new BondFutureOptionTrade.Builder();
}
@Override
public Class<? extends BondFutureOptionTrade> beanType() {
return BondFutureOptionTrade.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code info} property.
* @return the meta-property, not null
*/
public MetaProperty<TradeInfo> info() {
return info;
}
/**
* The meta-property for the {@code product} property.
* @return the meta-property, not null
*/
public MetaProperty<BondFutureOption> product() {
return product;
}
/**
* The meta-property for the {@code quantity} property.
* @return the meta-property, not null
*/
public MetaProperty<Double> quantity() {
return quantity;
}
/**
* The meta-property for the {@code price} property.
* @return the meta-property, not null
*/
public MetaProperty<Double> price() {
return price;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3237038: // info
return ((BondFutureOptionTrade) bean).getInfo();
case -309474065: // product
return ((BondFutureOptionTrade) bean).getProduct();
case -1285004149: // quantity
return ((BondFutureOptionTrade) bean).getQuantity();
case 106934601: // price
return ((BondFutureOptionTrade) bean).getPrice();
}
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 BondFutureOptionTrade}.
*/
public static final class Builder extends DirectFieldsBeanBuilder<BondFutureOptionTrade> {
private TradeInfo info;
private BondFutureOption product;
private double quantity;
private double price;
/**
* Restricted constructor.
*/
private Builder() {
applyDefaults(this);
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(BondFutureOptionTrade beanToCopy) {
this.info = beanToCopy.getInfo();
this.product = beanToCopy.getProduct();
this.quantity = beanToCopy.getQuantity();
this.price = beanToCopy.getPrice();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
case -309474065: // product
return product;
case -1285004149: // quantity
return quantity;
case 106934601: // price
return price;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 3237038: // info
this.info = (TradeInfo) newValue;
break;
case -309474065: // product
this.product = (BondFutureOption) newValue;
break;
case -1285004149: // quantity
this.quantity = (Double) newValue;
break;
case 106934601: // price
this.price = (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 BondFutureOptionTrade build() {
return new BondFutureOptionTrade(
info,
product,
quantity,
price);
}
//-----------------------------------------------------------------------
/**
* Sets the additional trade information, defaulted to an empty instance.
* <p>
* This allows additional information to be attached to the trade.
* The trade date is required when calling {@link BondFutureOptionTrade#resolve(ReferenceData)}.
* @param info the new value, not null
* @return this, for chaining, not null
*/
public Builder info(TradeInfo info) {
JodaBeanUtils.notNull(info, "info");
this.info = info;
return this;
}
/**
* Sets the option that was traded.
* <p>
* The product captures the contracted financial details of the trade.
* @param product the new value, not null
* @return this, for chaining, not null
*/
public Builder product(BondFutureOption product) {
JodaBeanUtils.notNull(product, "product");
this.product = product;
return this;
}
/**
* Sets the quantity that was traded.
* <p>
* This is the number of contracts that were traded.
* This will be positive if buying and negative if selling.
* @param quantity the new value
* @return this, for chaining, not null
*/
public Builder quantity(double quantity) {
this.quantity = quantity;
return this;
}
/**
* Sets the price that was traded, in decimal form.
* <p>
* This is the price agreed when the trade occurred.
* @param price the new value
* @return this, for chaining, not null
*/
public Builder price(double price) {
ArgChecker.notNegative(price, "price");
this.price = price;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(160);
buf.append("BondFutureOptionTrade.Builder{");
buf.append("info").append('=').append(JodaBeanUtils.toString(info)).append(',').append(' ');
buf.append("product").append('=').append(JodaBeanUtils.toString(product)).append(',').append(' ');
buf.append("quantity").append('=').append(JodaBeanUtils.toString(quantity)).append(',').append(' ');
buf.append("price").append('=').append(JodaBeanUtils.toString(price));
buf.append('}');
return buf.toString();
}
}
//-------------------------- AUTOGENERATED END --------------------------
}