protected SwapSecurity createUnderlying(
     final ZonedDateTime earliestMaturity, final ZonedDateTime swaptionExpiry) {
   SwapSecurity security;
   do {
     do {
       getUnderlyingGenerator().setSwationExpiry(swaptionExpiry.toLocalDate());
       security = getUnderlyingGenerator().createSecurity();
     } while (security == null);
   } while ((FinancialSecurityUtils.getCurrency(security) == null)
       || security.getMaturityDate().isBefore(earliestMaturity));
   return security;
 }
Beispiel #2
0
 @Override
 public boolean equals(Object obj) {
   if (obj == this) {
     return true;
   }
   if (obj != null && obj.getClass() == this.getClass()) {
     SwapSecurity other = (SwapSecurity) obj;
     return JodaBeanUtils.equal(getTradeDate(), other.getTradeDate())
         && JodaBeanUtils.equal(getEffectiveDate(), other.getEffectiveDate())
         && JodaBeanUtils.equal(getMaturityDate(), other.getMaturityDate())
         && JodaBeanUtils.equal(getCounterparty(), other.getCounterparty())
         && JodaBeanUtils.equal(getPayLeg(), other.getPayLeg())
         && JodaBeanUtils.equal(getReceiveLeg(), other.getReceiveLeg())
         && super.equals(obj);
   }
   return false;
 }
  @Override
  public SwaptionSecurity createSecurity() {
    final int optionLength = getRandom(OPTION_LENGTH);
    ZonedDateTime expiry = ZonedDateTime.now().plusMonths(optionLength);
    final SwapSecurity underlying = createUnderlying(expiry.plusMonths(2), expiry);
    final Currency currency = FinancialSecurityUtils.getCurrency(underlying);
    expiry = nextWorkingDay(expiry, currency);
    final boolean isPayer = getRandom().nextBoolean();
    final boolean isLong = getRandom().nextBoolean();
    final boolean isCashSettled = getRandom().nextBoolean();
    final ZonedDateTime settlementDate = nextWorkingDay(expiry.plusDays(2), currency);
    final Double notional =
        underlying
            .getPayLeg()
            .getNotional()
            .accept(
                new NotionalVisitor<Double>() {

                  @Override
                  public Double visitCommodityNotional(final CommodityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitInterestRateNotional(final InterestRateNotional notional) {
                    return notional.getAmount();
                  }

                  @Override
                  public Double visitSecurityNotional(final SecurityNotional notional) {
                    return null;
                  }

                  @Override
                  public Double visitVarianceSwapNotional(final VarianceSwapNotional notional) {
                    return notional.getAmount();
                  }
                });
    if (notional == null) {
      return null;
    }
    Double rate = getRate(underlying.getPayLeg());
    if (rate == null) {
      rate = getRate(underlying.getReceiveLeg());
      if (rate == null) {
        return null;
      }
    }
    final SwaptionSecurity security =
        new SwaptionSecurity(
            isPayer,
            getSecurityPersister().storeSecurity(underlying).iterator().next(),
            isLong,
            new Expiry(expiry),
            isCashSettled,
            currency,
            notional,
            new EuropeanExerciseType(),
            settlementDate);
    security.setName(
        createName(
            currency,
            optionLength,
            (int) MONTHS.between(underlying.getEffectiveDate(), underlying.getMaturityDate()),
            notional,
            rate));
    return security;
  }