Esempio n. 1
0
        // given a clean price and idCode will return the yield of the corresponding bond in BondDictionaryData
        object ICalculator.YieldFromDictionary(string idCode, double Today, double CleanPrice, int Freq, string DayCount, string Compounding)
        {
            // int Freq, string DayCount, string Compounding refers to yield calculation
            // string idCode is the identification code of bond in BondDictionaryData

            // make it volatile
            if (m_xlApp != null)
            {
                m_xlApp.Volatile(true);
            }
            try
            {
                BaseBond bond = null;                                 // initialise a bond
                if (BondDictionaryData.TryGetValue(idCode, out bond)) // is the idCode in dictionary?
                {
                    // update today since I the bond in dictionary can be the same but I can change my reference date to do simulations
                    bond.SetNewToDay(new Date(Today));

                    // Parse enum Type
                    Dc          dc   = (Dc)Enum.Parse(typeof(Dc), DayCount);
                    Compounding comp = (Compounding)Enum.Parse(typeof(Compounding), Compounding);

                    // return the yield given parameters
                    return(bond.Yield(CleanPrice, Freq, dc, comp));
                }
                else
                {
                    return("IdCode not found"); // bond not found
                }
            }
            catch (Exception e)
            {
                return((string)e.ToString());
            }
        }
Esempio n. 2
0
        // given a clean price and idCode will return the yield of the corresponding bond in BondDictionaryData
        object ICalculator.CleanFromYieldFromFile(string idCode, double Today, double Yield, int Freq, string DayCount, string Compounding, string FileFullName)
        {
            // int Freq, string DayCount, string Compounding refers to yield calculation
            // string idCode is the identification code of bond in BondDictionaryData

            // make it volatile
            if (m_xlApp != null)
            {
                m_xlApp.Volatile(true);
            }
            try
            {
                BaseBond bond = null; // initialise a bond
                // deserialize
                BondDictionary SD = new BondDictionary(@FileFullName);
                SD.DeSerialize();

                if (SD.dic.TryGetValue(idCode, out bond)) // is the idCode in dictionary?
                {
                    // update today since I the bond in dictionary can be the same but I can change my reference date to do simulations
                    bond.SetNewToDay(new Date(Today));

                    // Parse enum Type
                    Dc          dc   = (Dc)Enum.Parse(typeof(Dc), DayCount);
                    Compounding comp = (Compounding)Enum.Parse(typeof(Compounding), Compounding);

                    // if  yield is zero return a message
                    if (Yield == 0)
                    {
                        return((string)"YldZero");
                    }

                    // return clean price from yield given parameters
                    return(bond.CleanPriceFromYield(Yield, Freq, dc, comp));
                }
                else
                {
                    return("IdCode not found"); // bond not found
                }
            }
            catch (Exception e)
            {
                return((string)e.ToString());
            }
        }