Class Helper

java.lang.Object
org.drip.analytics.support.Helper

public class Helper
extends java.lang.Object
Helper contains the collection of the analytics related utility functions used by the modules. Following are some of the functionality that it exposes:

  • Yield to Discount Factor, and vice versa
  • Map Bloomberg Day Count Codes to Credit Analytics Day Count Codes
  • Generate rule-based curve node manifest measure bumps
  • Generate loss periods using a variety of different schemes
  • Aggregate/disaggregate/merge coupon period lists
  • Create fixings objects, rate index from currency/coupon/frequency
  • String Tenor/Month Code/Work-out
  • Standard Treasury Bench-mark off of Maturity


Author:
Lakshmi Krishnamurthy
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int LEFT_TENOR_EQUALS
    Tenor Comparator - Left Tenor Matches Right
    static int LEFT_TENOR_GREATER
    Tenor Comparator - Left Tenor Greater than Right
    static int LEFT_TENOR_LESSER
    Tenor Comparator - Left Tenor Lesser than Right
  • Constructor Summary

    Constructors
    Constructor Description
    Helper()  
  • Method Summary

    Modifier and Type Method Description
    static boolean AccumulateMeasures​(CaseInsensitiveTreeMap<java.lang.Double> mapOutput, java.lang.String strPrefix, CaseInsensitiveTreeMap<java.lang.Double> mapInput)
    Append the Prefixed Map Entries of the specified Input Map onto the Output Map
    static java.util.Set<CompositePeriod> AggregateComponentPeriods​(Component[] aComp)
    Aggregate the period lists for an array of components
    static java.lang.String AggregateTenor​(java.lang.String strBaseTenor, java.lang.String strRollTenor)
    Aggregate the Base and the Roll Tenors onto a Composite Tenor
    static java.lang.String BaseTsyBmk​(int iValueDate, int iMaturityDate)
    Return the standard on-the-run benchmark treasury string from the valuation and the maturity dates
    static double BondFuturesPriceAUDBillStyle​(JulianDate dtValue, Bond bond, double dblReferenceIndex)
    Compute the Bond Futures Price AUD Bill Style from the Reference Index Level
    static double[] BumpQuotes​(double[] adblQuotesIn, double dblBump, boolean bIsProportional)
    Bump the input array quotes
    static java.lang.String CalcRateIndex​(java.lang.String strCouponCurrency, int iCouponFreq)
    Calculate the rate index from the coupon currency and the frequency
    static LatentStateFixingsContainer CreateFixingsObject​(Bond bond, JulianDate dtFixing, double dblFixing)
    Create the Latent State Fixings object from the bond, the fixings date, and the fixing.
    static double DF2Yield​(int iFreqIn, double dblDF, double dblTime)
    Calculate the yield from the specified discount factor to the given time.
    static double DIStylePriceFromRate​(double dblDIRate, int iStartDate, int iEndDate, java.lang.String strCalendar)
    Compute the DI-Style Price given the Rate
    static double DIStyleRateFromPrice​(double dblDIPrice, int iStartDate, int iEndDate, java.lang.String strCalendar)
    Compute the DI-Style Rate given the Price
    static JulianDate[] FromTenor​(JulianDate dtSpot, java.lang.String[] astrTenor)
    Convert the Array of Tenors into Dates off of a Spot
    static java.lang.String GetDayCountFromBBGCode​(java.lang.String strBBGDC)
    Get the DRIP day count from the Bloomberg code
    static java.lang.String GetMonthCodeFromFreq​(int iFreq)
    Retrieve the month code from input frequency
    static java.lang.String GetTenorFromFreq​(int iFreq)
    Retrieve the tenor from the frequency
    static void Init()
    Initialize IR switcher and Bloomberg day count maps
    static java.lang.String IntervalHMSMS​(long lElapsedNanos)
    Converts the Nano-Second Interval into aH:bM:cS:dMS Format
    static boolean LabelMatch​(LatentStateLabel lslLeft, LatentStateLabel lslRight)
    Do the Left and the Right Labels Match?
    static java.util.List<CompositePeriod> MergePeriodLists​(java.util.List<CompositePeriod> lsPeriod1, java.util.List<CompositePeriod> lsPeriod2)
    Merge two lists of periods
    static double NominalYieldToPostTaxEquivalent​(double dblNominalYield, double dblTaxRate)
    Convert the Nominal Yield to the Post Tax Equivalent Yield
    static double[] NormalizedEqualWeightedArray​(int iNumElement)
    Construct a Normalized, Equally Weighted Array from the Specified Number of Elements
    static double OISFromLIBORSwapFedFundBasis​(double dblLIBORSwapRate, double dblFedFundLIBORSwapBasis)
    Compute the uncompounded OIS Rate from the LIBOR Swap Rate and the LIBOR Swap Rate - Fed Fund Basis.
    static double OISFromLIBORSwapFedFundBasis2​(double dblLIBORSwapRate, double dblFedFundLIBORSwapBasis)
    Compute the Daily Compounded OIS Rate from the LIBOR Swap Rate and the LIBOR Swap Rate - Fed Fund Basis.
    static double[] ParallelNodeBump​(double[] adblNode, double dblBump)
    Generate an Array of Bumped Nodes
    static java.lang.String ParseFromBBGDCCode​(java.lang.String strBBGDCCode)
    Convert the Bloomberg day count code to DRIP day count code.
    static double PostTaxEquivalentYieldToNominal​(double dblPostTaxEquivalentYield, double dblTaxRate)
    Convert the Post Tax Equivalent Yield to the Nominal Yield
    static java.lang.String RateIndexFromCcyAndCouponFreq​(java.lang.String strCcy, int iCouponFreq)
    Calculate the rate index from currency and coupon frequency
    static JulianDate[] SpotDateArray​(JulianDate dtSpot, int iCount)
    Generate an Array of Repeated Spot Dates
    static java.lang.String SwitchIRCurve​(java.lang.String strCurveIn)
    Switch the given IR curve if necessary
    static int TenorCompare​(java.lang.String strTenorLeft, java.lang.String strTenorRight)
    Compare the Left and the Right Tenors
    static int[] TenorToDate​(JulianDate dtSpot, java.lang.String[] astrTenor)
    Retrieve the Date Array From the Tenor Array
    static int TenorToDays​(java.lang.String strTenor)
    Retrieve the Number of Days from the Tenor
    static int TenorToFreq​(java.lang.String strTenor)
    Retrieve the Annual Frequency from the Tenor
    static int TenorToMonths​(java.lang.String strTenor)
    Retrieve the Number of Months from the Tenor
    static double TenorToYearFraction​(java.lang.String strTenor)
    Retrieve the Year Fraction from the Tenor
    static double[] TenorToYearFraction​(java.lang.String[] astrTenor, boolean bForward)
    Retrieve the Year Fraction from the Tenor Array
    static int TenorToYears​(java.lang.String strTenor)
    Retrieve the Number of Years from the Tenor
    static double[] TweakManifestMeasure​(double[] adblQuotesIn, ManifestMeasureTweak ntp)
    Tweak the Manifest Measures (gor the given set of nodes) in accordance with the specified tweak parameters
    static java.lang.String WorkoutTypeToString​(int iWOType)
    Turn the work out type to string
    static double Yield2DF​(int iFreqIn, double dblYield, double dblTime)
    Calculate the discount factor from the specified frequency, yield, and accrual year fraction

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LEFT_TENOR_GREATER

      public static int LEFT_TENOR_GREATER
      Tenor Comparator - Left Tenor Greater than Right
    • LEFT_TENOR_LESSER

      public static int LEFT_TENOR_LESSER
      Tenor Comparator - Left Tenor Lesser than Right
    • LEFT_TENOR_EQUALS

      public static int LEFT_TENOR_EQUALS
      Tenor Comparator - Left Tenor Matches Right
  • Constructor Details

    • Helper

      public Helper()
  • Method Details

    • Init

      public static final void Init()
      Initialize IR switcher and Bloomberg day count maps
    • Yield2DF

      public static final double Yield2DF​(int iFreqIn, double dblYield, double dblTime) throws java.lang.Exception
      Calculate the discount factor from the specified frequency, yield, and accrual year fraction
      Parameters:
      iFreqIn - Input frequency - if zero, set to semi-annual.
      dblYield - Yield
      dblTime - Time in DC years
      Returns:
      the discount factor
      Throws:
      java.lang.Exception - if input are invalid.
    • DF2Yield

      public static final double DF2Yield​(int iFreqIn, double dblDF, double dblTime) throws java.lang.Exception
      Calculate the yield from the specified discount factor to the given time.
      Parameters:
      iFreqIn - Yield calculation frequency - defaults to semi-annual if zero.
      dblDF - Discount Factor
      dblTime - Time to which the yield/DF are specified
      Returns:
      Implied yield
      Throws:
      java.lang.Exception - Thrown if yield cannot be computed
    • OISFromLIBORSwapFedFundBasis

      public static final double OISFromLIBORSwapFedFundBasis​(double dblLIBORSwapRate, double dblFedFundLIBORSwapBasis) throws java.lang.Exception
      Compute the uncompounded OIS Rate from the LIBOR Swap Rate and the LIBOR Swap Rate - Fed Fund Basis. The calculation is from the following Bloomberg Publication: - Lipman, H. and F. Mercurio (2012): OIS Discounting and Dual-Curve Stripping Methodology at Bloomberg
      Parameters:
      dblLIBORSwapRate - LIBOR Swap Rate
      dblFedFundLIBORSwapBasis - Fed Fund - LIBOR Swap Rate Basis
      Returns:
      The Uncompounded OIS Rate
      Throws:
      java.lang.Exception - Thrown if the Inputs are invalid
    • OISFromLIBORSwapFedFundBasis2

      public static final double OISFromLIBORSwapFedFundBasis2​(double dblLIBORSwapRate, double dblFedFundLIBORSwapBasis) throws java.lang.Exception
      Compute the Daily Compounded OIS Rate from the LIBOR Swap Rate and the LIBOR Swap Rate - Fed Fund Basis. The calculation is from the following Bloomberg Publication: - Lipman, H. and F. Mercurio (2012): OIS Discounting and Dual-Curve Stripping Methodology at Bloomberg
      Parameters:
      dblLIBORSwapRate - LIBOR Swap Rate
      dblFedFundLIBORSwapBasis - Fed Fund - LIBOR Swap Rate Basis
      Returns:
      The Daily Compounded OIS Rate
      Throws:
      java.lang.Exception - Thrown if the Inputs are invalid
    • DIStylePriceFromRate

      public static final double DIStylePriceFromRate​(double dblDIRate, int iStartDate, int iEndDate, java.lang.String strCalendar) throws java.lang.Exception
      Compute the DI-Style Price given the Rate
      Parameters:
      dblDIRate - The DI Rate
      iStartDate - The Start Date
      iEndDate - The End Date
      strCalendar - The Calendar
      Returns:
      The DI-Style Price
      Throws:
      java.lang.Exception - Thrown if the DI-Style Price cannot be calculated
    • DIStyleRateFromPrice

      public static final double DIStyleRateFromPrice​(double dblDIPrice, int iStartDate, int iEndDate, java.lang.String strCalendar) throws java.lang.Exception
      Compute the DI-Style Rate given the Price
      Parameters:
      dblDIPrice - The DI Price
      iStartDate - The Start Date
      iEndDate - The End Date
      strCalendar - The Calendar
      Returns:
      The DI-Style Rate
      Throws:
      java.lang.Exception - Thrown if the DI-Style Price cannot be calculated
    • NominalYieldToPostTaxEquivalent

      public static final double NominalYieldToPostTaxEquivalent​(double dblNominalYield, double dblTaxRate) throws java.lang.Exception
      Convert the Nominal Yield to the Post Tax Equivalent Yield
      Parameters:
      dblNominalYield - The Nominal Yield
      dblTaxRate - The Tax Rate
      Returns:
      The Post Tax Equivalent Yield
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • PostTaxEquivalentYieldToNominal

      public static final double PostTaxEquivalentYieldToNominal​(double dblPostTaxEquivalentYield, double dblTaxRate) throws java.lang.Exception
      Convert the Post Tax Equivalent Yield to the Nominal Yield
      Parameters:
      dblPostTaxEquivalentYield - The Post Tax Equivalent Yield
      dblTaxRate - The Tax Rate
      Returns:
      The Nominal Yield
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • BaseTsyBmk

      public static final java.lang.String BaseTsyBmk​(int iValueDate, int iMaturityDate)
      Return the standard on-the-run benchmark treasury string from the valuation and the maturity dates
      Parameters:
      iValueDate - the Valuation date
      iMaturityDate - the Maturity date
      Returns:
      the standard on-the-run benchmark treasury string
    • WorkoutTypeToString

      public static final java.lang.String WorkoutTypeToString​(int iWOType)
      Turn the work out type to string
      Parameters:
      iWOType - One of the WO_TYPE_* fields in the WorkoutInfo class
      Returns:
      String representation of the work out type field
    • ParseFromBBGDCCode

      public static final java.lang.String ParseFromBBGDCCode​(java.lang.String strBBGDCCode)
      Convert the Bloomberg day count code to DRIP day count code.
      Parameters:
      strBBGDCCode - String representing the Bloomberg day count code.
      Returns:
      String representing the DRIP day count code.
    • GetTenorFromFreq

      public static final java.lang.String GetTenorFromFreq​(int iFreq)
      Retrieve the tenor from the frequency
      Parameters:
      iFreq - Integer frequency
      Returns:
      String representing the tenor
    • TenorToYears

      public static final int TenorToYears​(java.lang.String strTenor) throws java.lang.Exception
      Retrieve the Number of Years from the Tenor
      Parameters:
      strTenor - The Specified Tenor
      Returns:
      The Number of Years
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToMonths

      public static final int TenorToMonths​(java.lang.String strTenor) throws java.lang.Exception
      Retrieve the Number of Months from the Tenor
      Parameters:
      strTenor - The Specified Tenor
      Returns:
      The Number of Months
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToDays

      public static final int TenorToDays​(java.lang.String strTenor) throws java.lang.Exception
      Retrieve the Number of Days from the Tenor
      Parameters:
      strTenor - The Specified Tenor
      Returns:
      The Number of Days
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToYearFraction

      public static final double TenorToYearFraction​(java.lang.String strTenor) throws java.lang.Exception
      Retrieve the Year Fraction from the Tenor
      Parameters:
      strTenor - The Specified Tenor
      Returns:
      The Year Fraction
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToYearFraction

      public static final double[] TenorToYearFraction​(java.lang.String[] astrTenor, boolean bForward) throws java.lang.Exception
      Retrieve the Year Fraction from the Tenor Array
      Parameters:
      astrTenor - The Specified Tenor Array
      bForward - TRUE - Generated the Incremental Forward Year Fraction
      Returns:
      The Year Fraction Array
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToFreq

      public static final int TenorToFreq​(java.lang.String strTenor) throws java.lang.Exception
      Retrieve the Annual Frequency from the Tenor
      Parameters:
      strTenor - The Specified Tenor
      Returns:
      The Annual Frequency
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • TenorToDate

      public static final int[] TenorToDate​(JulianDate dtSpot, java.lang.String[] astrTenor)
      Retrieve the Date Array From the Tenor Array
      Parameters:
      dtSpot - The Spot Date Array
      astrTenor - The Specified Tenor Array
      Returns:
      The Date Array From the Tenor Array
    • TenorCompare

      public static final int TenorCompare​(java.lang.String strTenorLeft, java.lang.String strTenorRight) throws java.lang.Exception
      Compare the Left and the Right Tenors
      Parameters:
      strTenorLeft - Left Tenor
      strTenorRight - Right Tenor
      Returns:
      Results of the Comparison
      Throws:
      java.lang.Exception - Thrown if the Comparison cannot be done
    • GetMonthCodeFromFreq

      public static final java.lang.String GetMonthCodeFromFreq​(int iFreq)
      Retrieve the month code from input frequency
      Parameters:
      iFreq - Integer frequency
      Returns:
      String representing the month code
    • CalcRateIndex

      public static final java.lang.String CalcRateIndex​(java.lang.String strCouponCurrency, int iCouponFreq)
      Calculate the rate index from the coupon currency and the frequency
      Parameters:
      strCouponCurrency - String representing the coupon currency
      iCouponFreq - Integer representing the coupon frequency
      Returns:
      String representing the rate index
    • GetDayCountFromBBGCode

      public static final java.lang.String GetDayCountFromBBGCode​(java.lang.String strBBGDC)
      Get the DRIP day count from the Bloomberg code
      Parameters:
      strBBGDC - String representing the Bloomberg day count convention
      Returns:
      String representing DRIP day count
    • RateIndexFromCcyAndCouponFreq

      public static final java.lang.String RateIndexFromCcyAndCouponFreq​(java.lang.String strCcy, int iCouponFreq)
      Calculate the rate index from currency and coupon frequency
      Parameters:
      strCcy - String representing coupon currency
      iCouponFreq - Integer representing coupon frequency
      Returns:
      String representing the rate index
    • SwitchIRCurve

      public static final java.lang.String SwitchIRCurve​(java.lang.String strCurveIn)
      Switch the given IR curve if necessary
      Parameters:
      strCurveIn - String representing the input curve
      Returns:
      String representing the switched curve
    • CreateFixingsObject

      public static final LatentStateFixingsContainer CreateFixingsObject​(Bond bond, JulianDate dtFixing, double dblFixing)
      Create the Latent State Fixings object from the bond, the fixings date, and the fixing.
      Parameters:
      bond - The input bond
      dtFixing - The Fixings Date
      dblFixing - Double representing the fixing
      Returns:
      The Latent State Fixings Instance
    • BumpQuotes

      public static final double[] BumpQuotes​(double[] adblQuotesIn, double dblBump, boolean bIsProportional)
      Bump the input array quotes
      Parameters:
      adblQuotesIn - Array of the input double quotes
      dblBump - Bump amount
      bIsProportional - True - Bump is proportional
      Returns:
      Bumped array output
    • TweakManifestMeasure

      public static final double[] TweakManifestMeasure​(double[] adblQuotesIn, ManifestMeasureTweak ntp)
      Tweak the Manifest Measures (gor the given set of nodes) in accordance with the specified tweak parameters
      Parameters:
      adblQuotesIn - Array of quotes to be bumped
      ntp - NodeTweakParams input
      Returns:
      Bumped array output
    • MergePeriodLists

      public static final java.util.List<CompositePeriod> MergePeriodLists​(java.util.List<CompositePeriod> lsPeriod1, java.util.List<CompositePeriod> lsPeriod2)
      Merge two lists of periods
      Parameters:
      lsPeriod1 - Period 1
      lsPeriod2 - Period 2
      Returns:
      The Merged Period List
    • AggregateComponentPeriods

      public static final java.util.Set<CompositePeriod> AggregateComponentPeriods​(Component[] aComp)
      Aggregate the period lists for an array of components
      Parameters:
      aComp - Array of Components
      Returns:
      The Aggregated Period Set
    • AccumulateMeasures

      public static final boolean AccumulateMeasures​(CaseInsensitiveTreeMap<java.lang.Double> mapOutput, java.lang.String strPrefix, CaseInsensitiveTreeMap<java.lang.Double> mapInput)
      Append the Prefixed Map Entries of the specified Input Map onto the Output Map
      Parameters:
      mapOutput - The Output Map
      strPrefix - The Entry Prefix
      mapInput - The Input Map
      Returns:
      TRUE - At least one entry appended
    • LabelMatch

      public static final boolean LabelMatch​(LatentStateLabel lslLeft, LatentStateLabel lslRight)
      Do the Left and the Right Labels Match?
      Parameters:
      lslLeft - Left Cash Flow Period Label
      lslRight - Right Cash Flow Period Label
      Returns:
      TRUE - The Labels Match
    • BondFuturesPriceAUDBillStyle

      public static final double BondFuturesPriceAUDBillStyle​(JulianDate dtValue, Bond bond, double dblReferenceIndex) throws java.lang.Exception
      Compute the Bond Futures Price AUD Bill Style from the Reference Index Level
      Parameters:
      dtValue - The Valuation Date
      bond - The Bond Instance
      dblReferenceIndex - The Reference Index
      Returns:
      The Bond Futures Price AUD Bill Style
      Throws:
      java.lang.Exception - Thrown if the Bond Futures Price AUD Bill Style cannot be computed
    • NormalizedEqualWeightedArray

      public static final double[] NormalizedEqualWeightedArray​(int iNumElement)
      Construct a Normalized, Equally Weighted Array from the Specified Number of Elements
      Parameters:
      iNumElement - Number of Elements
      Returns:
      The Normalized, Equally Weighted Array
    • AggregateTenor

      public static final java.lang.String AggregateTenor​(java.lang.String strBaseTenor, java.lang.String strRollTenor)
      Aggregate the Base and the Roll Tenors onto a Composite Tenor
      Parameters:
      strBaseTenor - The Base Tenor
      strRollTenor - The Roll Tenor
      Returns:
      The Agrregated Composite Tenor
    • FromTenor

      public static final JulianDate[] FromTenor​(JulianDate dtSpot, java.lang.String[] astrTenor)
      Convert the Array of Tenors into Dates off of a Spot
      Parameters:
      dtSpot - Spot Date
      astrTenor - Array of Tenors
      Returns:
      Array of Dates
    • SpotDateArray

      public static final JulianDate[] SpotDateArray​(JulianDate dtSpot, int iCount)
      Generate an Array of Repeated Spot Dates
      Parameters:
      dtSpot - Spot Date
      iCount - Repeat Count
      Returns:
      Array of the Repeated Spot Dates
    • ParallelNodeBump

      public static final double[] ParallelNodeBump​(double[] adblNode, double dblBump)
      Generate an Array of Bumped Nodes
      Parameters:
      adblNode - Array of Unbumped Nodes
      dblBump - Bump Amount
      Returns:
      Array of Bumped Nodes
    • IntervalHMSMS

      public static final java.lang.String IntervalHMSMS​(long lElapsedNanos)
      Converts the Nano-Second Interval into aH:bM:cS:dMS Format
      Parameters:
      lElapsedNanos - The Elapsed Nano Time
      Returns:
      The Nano-Second Interval in the aH:bM:cS:dMS Format