Package com.opengamma.financial.convention

Source Code of com.opengamma.financial.convention.GBConventions

/**
* Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.convention;

import static com.opengamma.core.id.ExternalSchemes.bloombergTickerSecurityId;
import static com.opengamma.core.id.ExternalSchemes.tullettPrebonSecurityId;
import static com.opengamma.financial.convention.InMemoryConventionBundleMaster.simpleNameSecurityId;

import org.threeten.bp.Period;

import com.opengamma.core.id.ExternalSchemes;
import com.opengamma.financial.analytics.ircurve.IndexType;
import com.opengamma.financial.convention.businessday.BusinessDayConvention;
import com.opengamma.financial.convention.businessday.BusinessDayConventionFactory;
import com.opengamma.financial.convention.daycount.DayCount;
import com.opengamma.financial.convention.daycount.DayCountFactory;
import com.opengamma.financial.convention.frequency.Frequency;
import com.opengamma.financial.convention.frequency.SimpleFrequencyFactory;
import com.opengamma.financial.convention.yield.SimpleYieldConvention;
import com.opengamma.id.ExternalId;
import com.opengamma.id.ExternalIdBundle;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.time.DateUtils;

/**
* Contains information used to construct standard versions of GBP instruments.
*
*/
public class GBConventions {
  /** Month codes used by Bloomberg */
  private static final char[] BBG_MONTH_CODES = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'};
  /** Modified business day convention */
  private static final BusinessDayConvention MODIFIED = BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Modified Following");
  /** Following business day convention */
  private static final BusinessDayConvention FOLLOWING = BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following");
  /** Act/365 */
  private static final DayCount ACT_365 = DayCountFactory.INSTANCE.getDayCount("Actual/365");
  /** Annual frequency */
  private static final Frequency ANNUAL = SimpleFrequencyFactory.INSTANCE.getFrequency(Frequency.ANNUAL_NAME);
  /** Semi-annual frequency */
  private static final Frequency SEMI_ANNUAL = SimpleFrequencyFactory.INSTANCE.getFrequency(Frequency.SEMI_ANNUAL_NAME);
  /** Quarterly frequency */
  private static final Frequency QUARTERLY = SimpleFrequencyFactory.INSTANCE.getFrequency(Frequency.QUARTERLY_NAME);
  /** GB holidays */
  private static final ExternalId GB = ExternalSchemes.financialRegionId("GB");

  /**
   * Adds conventions for deposit, Libor fixings, swaps, FRAs and IR futures.
   * @param conventionMaster The convention master, not null
   */
  public static synchronized void addFixedIncomeInstrumentConventions(final ConventionBundleMaster conventionMaster) {
    ArgumentChecker.notNull(conventionMaster, "convention master");
    final ConventionBundleMasterUtils utils = new ConventionBundleMasterUtils(conventionMaster);

    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("BP00O/N Index"), simpleNameSecurityId("GBP LIBOR O/N"),
        tullettPrebonSecurityId("ASLIBGBPONL")), "GBP LIBOR O/N", ACT_365, FOLLOWING, Period.ofDays(1), 0, false, GB);
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("BP00T/N Index"), simpleNameSecurityId("GBP LIBOR T/N")),
        "GBP LIBOR T/N", ACT_365, FOLLOWING, Period.ofDays(1), 1, false, GB);

    for (int i = 1; i < 3; i++) {
      final String dayDepositName = "GBP DEPOSIT " + i + "d";
      final ExternalId dayBbgDeposit = bloombergTickerSecurityId("BPDR" + i + "T Curncy");
      final ExternalId daySimpleDeposit = simpleNameSecurityId(dayDepositName);
      final String weekDepositName = "GBP DEPOSIT " + i + "w";
      final ExternalId weekBbgDeposit = bloombergTickerSecurityId("BPDR" + i + "Z Curncy");
      final ExternalId weekTullettDeposit = tullettPrebonSecurityId("MNDEPGBDTDY0" + i + "W");
      final ExternalId weekSimpleDeposit = simpleNameSecurityId(weekDepositName);
      final String weekLiborName = "GBP LIBOR " + i + "w";
      final ExternalId weekBbgLibor = bloombergTickerSecurityId("BP000" + i + "W Index");
      final ExternalId weekTullettLibor = tullettPrebonSecurityId("ASLIBGBP" + i + "WL");
      final ExternalId weekSimpleLibor = simpleNameSecurityId(weekDepositName);
      utils.addConventionBundle(ExternalIdBundle.of(dayBbgDeposit, daySimpleDeposit), dayDepositName, ACT_365, FOLLOWING, Period.ofDays(i), 0, false, GB);
      utils.addConventionBundle(ExternalIdBundle.of(weekBbgDeposit, weekTullettDeposit, weekSimpleDeposit), weekDepositName, ACT_365, FOLLOWING, Period.ofDays(i * 7), 0, false, GB);
      utils.addConventionBundle(ExternalIdBundle.of(weekBbgLibor, weekTullettLibor, weekSimpleLibor), weekLiborName, ACT_365, FOLLOWING, Period.ofDays(i * 7), 0, false, GB);
    }

    for (int i = 1; i < 13; i++) {
      final String liborName = "GBP LIBOR " + i + "m";
      final ExternalId bbgLibor = bloombergTickerSecurityId("BP00" + (i < 10 ? "0" : "") + i + "M Index");
      final ExternalId tullettLibor = tullettPrebonSecurityId("ASLIBGBP" + (i < 10 ? "0" : "") + i + "L");
      final ExternalId simpleLibor = simpleNameSecurityId(liborName);
      final String depositName = "GBP DEPOSIT " + i + "m";
      ExternalId bbgDeposit;
      if (i == 12) {
        bbgDeposit = bloombergTickerSecurityId("BPDR1" + " Curncy");
      } else {
        bbgDeposit = bloombergTickerSecurityId("BPDR" + BBG_MONTH_CODES[i - 1] + " Curncy");
      }
      final ExternalId tullettDeposit = tullettPrebonSecurityId("MNDEPGBDTDY" + (i < 10 ? "0" : "") + i + "M");
      final ExternalId simpleDeposit = simpleNameSecurityId(depositName);
      utils.addConventionBundle(ExternalIdBundle.of(bbgLibor, tullettLibor, simpleLibor), liborName, ACT_365, MODIFIED, Period.ofMonths(i), 0, false, GB);
      utils.addConventionBundle(ExternalIdBundle.of(bbgDeposit, tullettDeposit, simpleDeposit), depositName, ACT_365, MODIFIED, Period.ofMonths(i), 0, false, GB);
    }

    for (int i = 1; i < 6; i++) {
      final String depositName = "GBP DEPOSIT " + i + "y";
      final ExternalId bbgDeposit = bloombergTickerSecurityId("BPDR" + i + " Curncy");
      final ExternalId simpleDeposit = simpleNameSecurityId(depositName);
      utils.addConventionBundle(ExternalIdBundle.of(bbgDeposit, simpleDeposit), depositName, ACT_365, MODIFIED, Period.ofYears(i), 0, false, GB);
    }

    final DayCount swapFixedDayCount = ACT_365;
    final BusinessDayConvention swapFixedBusinessDay = MODIFIED;
    final Frequency swapFixedPaymentFrequency = SEMI_ANNUAL;
    final Frequency swapFixedPaymentFrequency1Y = ANNUAL;
    final DayCount liborDayCount = ACT_365;
    // Overnight Index Swap Convention have additional flag, publicationLag
    final int publicationLagON = 0;

    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_SWAP")), "GBP_SWAP", ACT_365, MODIFIED, SEMI_ANNUAL, 0, GB, ACT_365,
        MODIFIED, SEMI_ANNUAL, 0, simpleNameSecurityId("GBP LIBOR 6m"), GB, true);

    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_3M_SWAP")), "GBP_3M_SWAP", swapFixedDayCount, MODIFIED, ANNUAL, 0, GB, ACT_365,
        MODIFIED, QUARTERLY, 0, simpleNameSecurityId("GBP LIBOR 3m"), GB, true);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_6M_SWAP")), "GBP_6M_SWAP", swapFixedDayCount, swapFixedBusinessDay, swapFixedPaymentFrequency, 0, GB,
        liborDayCount, MODIFIED, SEMI_ANNUAL, 0, simpleNameSecurityId("GBP LIBOR 6m"), GB, true);

    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_3M_FRA")), "GBP_3M_FRA", ACT_365, MODIFIED, ANNUAL, 0, GB, ACT_365,
        MODIFIED, QUARTERLY, 0, simpleNameSecurityId("GBP LIBOR 3m"), GB, true);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_6M_FRA")), "GBP_6M_FRA", ACT_365, MODIFIED, SEMI_ANNUAL, 0, GB,
        ACT_365, MODIFIED, SEMI_ANNUAL, 0, simpleNameSecurityId("GBP LIBOR 6m"), GB, true);

    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId(IndexType.Libor + "_P3M")), IndexType.Libor + "_P3M", ACT_365, MODIFIED,
        null, 0, false, GB);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId(IndexType.Libor + "_P6M")), IndexType.Libor + "_P6M", ACT_365, MODIFIED,
        null, 0, false, GB);
    // SONIA
    utils.addConventionBundle(ExternalIdBundle.of(bloombergTickerSecurityId("SONIO/N Index"), simpleNameSecurityId("GBP SONIO/N")), "GBP SONIO/N", ACT_365,
        FOLLOWING, Period.ofDays(1), 0, false, GB, publicationLagON);
    // OIS - SONIA
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_OIS_SWAP")), "GBP_OIS_SWAP", ACT_365, MODIFIED, ANNUAL, 2, GB,
        ACT_365, MODIFIED, ANNUAL, 2, simpleNameSecurityId("GBP SONIO/N"), GB, true, publicationLagON);

    //TODO sort out the swap names so that they are consistent
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_IBOR_INDEX")), "GBP_IBOR_INDEX", ACT_365, MODIFIED, 0, false);

    final int[] isdaFixTenor = new int[] {2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30};
    // ISDA fixing Libor 11:00am London
    utils.addConventionBundle(
        ExternalIdBundle.of(simpleNameSecurityId("GBP_ISDAFIX_GBPLIBOR11_1Y"), ExternalSchemes.ricSecurityId("GBPSFIX1Y="),
            bloombergTickerSecurityId("BPISDB01 Index")), "GBP_ISDAFIX_GBPLIBOR11_1Y", swapFixedDayCount, swapFixedBusinessDay, swapFixedPaymentFrequency1Y, 0, GB, liborDayCount, MODIFIED,
        QUARTERLY, 2, simpleNameSecurityId("GBP LIBOR 3m"), GB, true, Period.ofYears(1));
    for (final int element : isdaFixTenor) {
      final String tenorString = element + "Y";
      final String tenorStringBbg = String.format("%02d", element);
      utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_ISDAFIX_GBPLIBOR11_" + tenorString),
          ExternalSchemes.ricSecurityId("GBPSFIX" + tenorString + "="), bloombergTickerSecurityId("BPISDB" + tenorStringBbg + " Index")), "GBP_ISDAFIX_GBPLIBOR11_" + tenorString,
          swapFixedDayCount, swapFixedBusinessDay, swapFixedPaymentFrequency, 0, GB, liborDayCount, MODIFIED, SEMI_ANNUAL, 0, simpleNameSecurityId("GBP LIBOR 6m"),
          GB, true, Period.ofYears(element));
    }

  }

  /**
   * Adds conventions for GBP government bonds.
   * @param conventionMaster The convention master, not null
   */
  public static void addTreasuryBondConvention(final ConventionBundleMaster conventionMaster) {
    ArgumentChecker.notNull(conventionMaster, "convention master");
    final ConventionBundleMasterUtils utils = new ConventionBundleMasterUtils(conventionMaster);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GB_TREASURY_BOND_CONVENTION")), "GB_TREASURY_BOND_CONVENTION", false,
        true, 6, 0, true);
  }

  /**
   * Adds conventions for GBP-denominated corporate bonds.
   * @param conventionMaster The convention master, not null
   */
  public static void addCorporateBondConvention(final ConventionBundleMaster conventionMaster) {
    ArgumentChecker.notNull(conventionMaster, "convention master");
    final ConventionBundleMasterUtils utils = new ConventionBundleMasterUtils(conventionMaster);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GB_CORPORATE_BOND_CONVENTION")), "GB_CORPORATE_BOND_CONVENTION", false,
        true, 6, 0, true);
  }

  /**
   * Adds conventions for GBP bond futures.
   * @param conventionMaster The convention master, not null
   */
  public static void addBondFutureConvention(final ConventionBundleMaster conventionMaster) {
    ArgumentChecker.notNull(conventionMaster, "convention master");
    final ConventionBundleMasterUtils utils = new ConventionBundleMasterUtils(conventionMaster);
    utils.addConventionBundle(ExternalIdBundle.of(simpleNameSecurityId("GBP_BOND_FUTURE_DELIVERABLE_CONVENTION")),
        "GBP_BOND_FUTURE_DELIVERABLE_CONVENTION", true, true, 7, 0, DayCountFactory.INSTANCE.getDayCount("Actual/365"), BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following"),
        SimpleYieldConvention.MONEY_MARKET);
  }
}
TOP

Related Classes of com.opengamma.financial.convention.GBConventions

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.