Ejemplo n.º 1
0
 public InterestRateModel(InterestRateModel arg0)
     : this(AkaApiPINVOKE.new_InterestRateModel__SWIG_3(InterestRateModel.getCPtr(arg0)), true)
 {
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 2
0
        // ***********************************************************
        // EXAMPLE METHODS
        // ***********************************************************
        /// <summary>
        /// Example of how to value a bond. </summary>
        public static int exampleValuation()
        {
            Date pvdate = new Date(2000, 1, 1);
            Date mdate = new Date(2030, 1, 1);

            Console.WriteLine("pvdate: " + pvdate.Libdate() + " mdate: " + mdate.Libdate());
            /* timing variables */
            long start = 0;

            InterestRateModel model = new InterestRateModel();
            if (!model.SetVolatility(vol))
            {
                Console.Write("Warning: invalid volatility '{0:F}', using 0\n", vol);
            }
            if (!model.SetRate(.5, rate))
            {
                Console.Write("Warning: invalid input rate '{0:F}', using 2%\n", rate);
                rate = 2;
                model.SetRate(.5, rate);
            }
            if (ctype == CurveType.LINEAR)
            {
                model.SetRate(1, rate + .01);
                model.SetRate(30, rate + .3);
            }
            else if (ctype == CurveType.ASYM)
            {
                double[] terms = new double[] {1, 3, 5, 7, 10, 15, 30};
                for (int i = 0; i < terms.Length; i++)
                {
                    model.SetRate(terms[i], rate + 2 * (1 - 1.0 / terms[i]));
                }
            }
            if (quiet == false)
            {
                Console.Write("Making a par rate curve with {0:g2} volatility", vol);
                Console.Write(", {0:F1} yr = {1:F2}%", 1.0, model.GetRate(1));
                Console.Write(", {0:F1} yr = {1:F2}%", 30.0, model.GetRate(30));
            }

            if (timing)
            {
                start = CurrentUnixTimeMillis();
            }
            model.Solve();
            if (timing)
            {
                start = CurrentUnixTimeMillis() - start;
                Console.Write("Seconds to fit the base curve = {0:F2}\n", INSECS(start));
            }
            if (!msgs(model))
            {
                return model.Error();
            }

            // make the bond
            if (quiet == false)
            {
                Console.Write("\nMaking a 30 year {0:g10}% bond maturing on {1:D}", coupon, mdate.Libdate());
            }
            Date idate = new Date(mdate.YearOf() - 30, mdate.MonthOf(), mdate.DayOf());
            Bond bond = new Bond("example", idate, mdate, coupon);
            if (!msgs(bond))
            {
                return bond.Error();
            }

            if (!bullet)
            {
                Date cdate = new Date(idate.YearOf() + 5, idate.MonthOf(), idate.DayOf());
                if (quiet == false)
                {
                    Console.Write(" callable {0:D} at par", cdate.Libdate());
                }
                if (!bond.SetCall(cdate, 100))
                {
                    Console.Write("failed to add call at {0:D}\n", cdate.Libdate());
                }
            }
            if (quiet == false)
            {
                Console.Write("\n\n");
            }

            if (quiet == false)
            {
                string underline = "--------------------";
                string fmt = "%10.10s %8.8s %8.8s %8.8s %8.8s %8.8s";
                Console.Write(fmt, "pvdate  ", fromoas ? "price" : "oas", "accrued", "optval", "duration", "convex.");
                Console.Write("\n");
                Console.Write(fmt, underline, underline, underline, underline, underline, underline);
                Console.Write("\n");
            }

            Value value = new Value(bond, model, pvdate);
            if (!msgs(value))
            {
                return value.Error();
            }

            // loop through pvdates
            start = CurrentUnixTimeMillis();
            int cnt = 0;
            for (cnt = 0; pvdate.IsLT(mdate) && cnt < days; pvdate.PlusEqual(1), cnt++)
            {
                if (cnt > 0)
                {
                    value.Reset(bond, pvdate);
                    if (!msgs(value))
                    {
                        break;
                    }
                }
                double oas = fromoas ? quote : value.Oas(quote);
                double price = fromoas ? value.Price(quote) : quote;
                if (!msgs(value) || oas == Value.BadValue || price == Value.BadValue)
                {
                    break;
                }

                if (quiet == false)
                {
                    Duration duration = value.EffectiveDuration(oas);
                    Console.Write("{0:D2}/{1:D2}/{2:D4} {3,8:F3} {4,8:F3} {5,8:F3} {6,8:F3} {7,8:F3}", pvdate.MonthOf(), pvdate.DayOf(), pvdate.YearOf(), fromoas ? price : oas, value.Accrued(), value.OptionValue(oas), duration.duration, duration.convexity);
                    Console.Write("\n");
                }
            }
            if (timing)
            {
                Console.Write("\nSeconds to value the bond for {0:D} pvdates = {1:F2}\n", cnt, INSECS(CurrentUnixTimeMillis() - start));
            }
            return 0;
        }
Ejemplo n.º 3
0
 public InterestRateModel(InterestRateModel.INPUTTYPE arg0)
     : this(AkaApiPINVOKE.new_InterestRateModel__SWIG_0((int)arg0), true)
 {
 }
Ejemplo n.º 4
0
 public InterestRateModel(InterestRateModel arg0, double forward_period)
     : this(AkaApiPINVOKE.new_InterestRateModel__SWIG_2(InterestRateModel.getCPtr(arg0), forward_period), true)
 {
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 5
0
 public bool AddTransition(double years, InterestRateModel arg1)
 {
     bool ret = AkaApiPINVOKE.InterestRateScenario_AddTransition(swigCPtr, years, InterestRateModel.getCPtr(arg1));
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Ejemplo n.º 6
0
 internal static HandleRef getCPtr(InterestRateModel obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Ejemplo n.º 7
0
 public InterestRateScenario(double years, InterestRateModel horizonmodel)
     : this(AkaApiPINVOKE.new_InterestRateScenario__SWIG_2(years, InterestRateModel.getCPtr(horizonmodel)), true)
 {
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 8
0
 public Value(Bond arg0, InterestRateModel arg1, SinkingFundStatus arg2, Date pvdate, Date tradedate)
     : this(AkaApiPINVOKE.new_Value__SWIG_6(Bond.getCPtr(arg0), InterestRateModel.getCPtr(arg1), SinkingFundStatus.getCPtr(arg2), Date.getCPtr(pvdate), Date.getCPtr(tradedate)), true)
 {
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 9
0
 public int Reset(Bond arg0, InterestRateModel arg1, SinkingFundStatus arg2, Date pvdate, Date tradedate)
 {
     int ret = AkaApiPINVOKE.Value_Reset__SWIG_5(swigCPtr, Bond.getCPtr(arg0), InterestRateModel.getCPtr(arg1), SinkingFundStatus.getCPtr(arg2), Date.getCPtr(pvdate), Date.getCPtr(tradedate));
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Ejemplo n.º 10
0
 public int Reset(Bond arg0, InterestRateModel arg1, Date pvdate)
 {
     int ret = AkaApiPINVOKE.Value_Reset__SWIG_2(swigCPtr, Bond.getCPtr(arg0), InterestRateModel.getCPtr(arg1), Date.getCPtr(pvdate));
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Ejemplo n.º 11
0
 public Value(Bond arg0, InterestRateModel arg1, Date pvdate)
     : this(AkaApiPINVOKE.new_Value__SWIG_3(Bond.getCPtr(arg0), InterestRateModel.getCPtr(arg1), Date.getCPtr(pvdate)), true)
 {
     if (AkaApiPINVOKE.SWIGPendingException.Pending) throw AkaApiPINVOKE.SWIGPendingException.Retrieve();
 }