Пример #1
0
        public void ClosestBondsTest(string input)
        {
            Bond.Bond        sampleInput1 = new Bond.Bond("C2", Bond.BondConst.corp, 15.2, 8.30);
            List <Bond.Bond> govBondList  = LoadBondObjects();

            Bond.BondHolder closestBonds = Bond.BondRun.ClosestBonds(govBondList, sampleInput1);
            string          actual       = closestBonds.closeLesserBond.bondID.ToString() + closestBonds.closeGreaterBond.bondID.ToString();

            Assert.True(input.Equals(actual));
        }
Пример #2
0
        /// <FunctionName> CalSpreadCurve </FunctionName>
        /// <FunctionSummary>
        /// This function cacluates result of spread to curve for a corporate bond by subtracting the
        /// bond term from the result of interpolation of two nearest government bonds.
        /// </FunctionSummary>
        /// <param name="govBondList">List of Bonds whose type is government</param>
        /// <param name="corpBond">A bond object whos type is corpBond</param>
        /// <returns></returns>
        public static double CalSpreadCurve(List <Bond> govBondList, Bond corpBond)
        {
            BondHolder closestBondsList = ClosestBonds(govBondList, corpBond);


            return(corpBond.bondYield -
                   CalInterpol(corpBond.bondTerm,
                               closestBondsList.closeLesserBond.bondTerm,
                               closestBondsList.closeLesserBond.bondYield,
                               closestBondsList.closeGreaterBond.bondTerm,
                               closestBondsList.closeGreaterBond.bondYield
                               ));
        }
Пример #3
0
        /// <FunctionName> CalSpreadBenchmark </FunctionName>
        /// <FunctionSummary>
        /// This function first determines the best candidate in terms of Bond terms for
        /// each corporate bond from the list of government bonds. After it locates the best candidate,
        /// the function outputs the ID of this best candidate Bond and
        /// calculates the yield by subtracting its value from corporate bond's yield
        /// </FunctionSummary>
        /// <Paramters>2 Parameters</Paramters>
        /// <param name="govBondList"> List of Government Bonds for which to benchmark</param>
        /// <param name="corpBond">Corporate Bond for which benchmark against </param>
        /// <returns>It prints the Bond ID and yield calculation. </returns>
        public static string CalSpreadBenchmark(List <Bond> govBondList, Bond corpBond)
        {
            Bond resultBond = null;

            BondHolder closestBondsList = ClosestBonds(govBondList, corpBond);
            double     lesserBondTerm   = Math.Abs(closestBondsList.closeLesserBond.bondTerm - corpBond.bondTerm);
            double     greaterBondTerm  = Math.Abs(closestBondsList.closeGreaterBond.bondTerm - corpBond.bondTerm);

            if (lesserBondTerm < greaterBondTerm)
            {
                resultBond = closestBondsList.closeLesserBond;
            }
            else
            {
                resultBond = closestBondsList.closeGreaterBond;
            }

            string resultValue = resultBond.bondID + " " + Math.Abs(corpBond.bondYield - resultBond.bondYield).ToString("N2") + "%";

            return(resultValue);
        }
Пример #4
0
        /// <FunctionName> closestBonds </FunctionName>
        /// <FunctionSummary>
        /// This function outputs Bond Holder objects class which contains
        /// one nearest bond whose term is lesser than corporate bond.
        /// one nearest bond whose term is greater than corporate bond.
        /// It is necessary for reducing the error for linear interpolation as error is
        /// proportional to the square of the distance between the data points.
        /// </FunctionSummary>
        /// <param name="govBondList">List of Bonds whose type is government</param>
        /// <param name="corpBondYears">A double value representing bond years for a corporate Bond</param>
        /// <returns>BondHolder object that contains two specified objects</returns>
        public static BondHolder ClosestBonds(List <Bond> govBondList, Bond corpBond)
        {
            Bond nearLesserBond  = null;
            Bond nearGreaterBond = null;


            govBondList.Sort((x, y) => x.bondTerm.CompareTo(y.bondTerm));        //In-place Sorting
            CompareBondType compareBondType = new CompareBondType();
            int             index           = govBondList.BinarySearch(corpBond, compareBondType);

            int lesserBond = (~index) - 1;

            nearLesserBond = govBondList[lesserBond];

            int greaterBond = +~index;

            nearGreaterBond = govBondList[greaterBond];

            BondHolder resultBondList = new BondHolder(nearLesserBond, nearGreaterBond);

            return(resultBondList);
        }