Java Code Examples for java.time.YearMonth#format()

The following examples show how to use java.time.YearMonth#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EtdIdUtils.java    From Strata with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an identifier for an ETD option instrument.
 * <p>
 * This takes into account the expiry of the underlying instrument. If the underlying expiry
 * is the same as the expiry of the option, the identifier is the same as the normal one.
 * Otherwise, the underlying expiry is added after the option expiry. For example:
 * {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50-U201709'}.
 *
 * @param exchangeId  the MIC code of the exchange where the instruments are traded
 * @param contractCode  the code supplied by the exchange for use in clearing and margining, such as in SPAN
 * @param expiryMonth  the month of expiry
 * @param variant  the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex'
 * @param version  the non-negative version, zero by default
 * @param putCall  the Put/Call flag
 * @param strikePrice  the strike price
 * @param underlyingExpiryMonth  the expiry of the underlying instrument, such as a future, may be null
 * @return the identifier
 */
public static SecurityId optionId(
    ExchangeId exchangeId,
    EtdContractCode contractCode,
    YearMonth expiryMonth,
    EtdVariant variant,
    int version,
    PutCall putCall,
    double strikePrice,
    YearMonth underlyingExpiryMonth) {

  ArgChecker.notNull(exchangeId, "exchangeId");
  ArgChecker.notNull(contractCode, "contractCode");
  ArgChecker.notNull(expiryMonth, "expiryMonth");
  ArgChecker.notNull(variant, "variant");
  ArgChecker.notNull(putCall, "putCall");

  String putCallStr = putCall == PutCall.PUT ? "P" : "C";
  String versionCode = version > 0 ? "V" + version + SEPARATOR : "";

  NumberFormat f = NumberFormat.getIntegerInstance(Locale.ENGLISH);
  f.setGroupingUsed(false);
  f.setMaximumFractionDigits(8);
  String strikeStr = f.format(strikePrice).replace('-', 'M');

  String underlying = "";
  if (underlyingExpiryMonth != null && !underlyingExpiryMonth.equals(expiryMonth)) {
    underlying = SEPARATOR + "U" + underlyingExpiryMonth.format(YM_FORMAT);
  }

  String id = new StringBuilder(40)
      .append(OPT_PREFIX)
      .append(exchangeId)
      .append(SEPARATOR)
      .append(contractCode)
      .append(SEPARATOR)
      .append(expiryMonth.format(YM_FORMAT))
      .append(variant.getCode())
      .append(SEPARATOR)
      .append(versionCode)
      .append(putCallStr)
      .append(strikeStr)
      .append(underlying)
      .toString();
  return SecurityId.of(ETD_SCHEME, id);
}
 
Example 2
Source File: YearMonthDateParameterMetadata.java    From Strata with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains an instance using the year-month.
 * 
 * @param date  the date associated with the parameter
 * @param yearMonth  the year-month of the curve node
 * @return the parameter metadata based on the year-month
 */
public static YearMonthDateParameterMetadata of(LocalDate date, YearMonth yearMonth) {
  ArgChecker.notNull(date, "date");
  ArgChecker.notNull(yearMonth, "yearMonth");
  return new YearMonthDateParameterMetadata(date, yearMonth, yearMonth.format(FORMATTER));
}