Exemplo n.º 1
0
        /*! The resulting interest rate has the same day-counting rule
         *  used by the term structure. The same rule should be used
         *  for calculating the passed time t.
         */
        public InterestRate zeroRate(double t, Compounding comp, Frequency freq = Frequency.Annual, bool extrapolate = false)
        {
            if (t.IsEqual(0.0))
            {
                t = dt;
            }
            double compound = 1.0 / discount(t, extrapolate);

            return(InterestRate.impliedRate(compound, dayCounter(), comp, freq, t));
        }
Exemplo n.º 2
0
        //    These methods return the implied zero-yield rate for a
        //    given date or time.  In the former case, the time is
        //    calculated as a fraction of year from the reference date.

        /*! The resulting interest rate has the required daycounting
         *  rule.
         */
        public InterestRate zeroRate(Date d, DayCounter dayCounter, Compounding comp, Frequency freq = Frequency.Annual,
                                     bool extrapolate = false)
        {
            if (d == referenceDate())
            {
                double compound = 1.0 / discount(dt, extrapolate);
                // t has been calculated with a possibly different daycounter
                // but the difference should not matter for very small times
                return(InterestRate.impliedRate(compound, dayCounter, comp, freq, dt));
            }
            double compound1 = 1.0 / discount(d, extrapolate);

            return(InterestRate.impliedRate(compound1, dayCounter, comp, freq, referenceDate(), d));
        }
Exemplo n.º 3
0
        //    These methods returns the forward interest rate between two dates
        //    or times.  In the former case, times are calculated as fractions
        //    of year from the reference date.
        //
        //    If both dates (times) are equal the instantaneous forward rate is
        //    returned.

        /*! The resulting interest rate has the required day-counting
         *  rule.
         */
        public InterestRate forwardRate(Date d1, Date d2, DayCounter dayCounter, Compounding comp,
                                        Frequency freq = Frequency.Annual, bool extrapolate = false)
        {
            if (d1 == d2)
            {
                checkRange(d1, extrapolate);
                double t1       = Math.Max(timeFromReference(d1) - dt / 2.0, 0.0);
                double t2       = t1 + dt;
                double compound = discount(t1, true) / discount(t2, true);
                // times have been calculated with a possibly different daycounter
                // but the difference should not matter for very small times
                return(InterestRate.impliedRate(compound, dayCounter, comp, freq, dt));
            }
            Utils.QL_REQUIRE(d1 < d2, () => d1 + " later than " + d2);
            double compound1 = discount(d1, extrapolate) / discount(d2, extrapolate);

            return(InterestRate.impliedRate(compound1, dayCounter, comp, freq, d1, d2));
        }
Exemplo n.º 4
0
        /*! The resulting interest rate has the same day-counting rule
         *  used by the term structure. The same rule should be used
         *  for calculating the passed times t1 and t2.
         */
        public InterestRate forwardRate(double t1, double t2, Compounding comp, Frequency freq = Frequency.Annual,
                                        bool extrapolate = false)
        {
            double compound;

            if (t2.IsEqual(t1))
            {
                checkRange(t1, extrapolate);
                t1       = Math.Max(t1 - dt / 2.0, 0.0);
                t2       = t1 + dt;
                compound = discount(t1, true) / discount(t2, true);
            }
            else
            {
                Utils.QL_REQUIRE(t2 > t1, () => "t2 (" + t2 + ") < t1 (" + t2 + ")");
                compound = discount(t1, extrapolate) / discount(t2, extrapolate);
            }
            return(InterestRate.impliedRate(compound, dayCounter(), comp, freq, t2 - t1));
        }