Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="myZero"></param>
        /// <param name="myDivList"></param>
        /// <param name="spot"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static double GetATMfwd(ZeroCurve myZero, DivList myDivList, double spot, double t)
        {
            double spotstar = spot;

            //compute the discounted dividends and take off spot
            if ((myDivList != null) && (myZero != null))
            {
                for (int idx = 0; idx < myDivList.Divpoints; idx++)
                {
                    if (myDivList.GetT(idx) <= t)
                    {
                        double d1 = myDivList.GetD(idx);
                        double r1 = myZero.LinInterp(myDivList.GetT(idx));
                        double t1 = Math.Exp(-r1 * myDivList.GetT(idx));
                        spotstar -= d1 * t1;
                    }
                }
            }
            //gross up to expiry to get atfwd
            if (myZero != null)
            {
                double r = myZero.LinInterp(t);
                return(spotstar * Math.Exp(r * t));
            }
            return(0);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="myZero"></param>
 /// <param name="q"></param>
 /// <param name="spot"></param>
 /// <param name="t"></param>
 /// <returns></returns>
 public static double GetATMfwd(ZeroCurve myZero, double q, double spot, double t)
 {
     //compute the discounted dividends and take off spot
     if ((myZero != null))
     {
         double spotstar = spot * Math.Exp(-q * t);
         double r        = myZero.LinInterp(t);
         return(spotstar * Math.Exp(r * t));
     }
     return(0);
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spot"></param>
        /// <param name="strike"></param>
        /// <param name="vol"></param>
        /// <param name="paystyle"></param>
        /// <param name="today"></param>
        /// <param name="expiry"></param>
        /// <param name="zeroDates"></param>
        /// <param name="zeroRates"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        public static double BlackScholesPricerContDiv(double spot, double strike, double vol, string paystyle, DateTime today, DateTime expiry,
                                                       DateTime[] zeroDates, double[] zeroRates, double q)
        {
            double    t      = expiry.Subtract(today).Days / 365.0;
            ZeroCurve myZero = (new Wrapper()).UnpackZero(today, zeroDates, zeroRates);
            double    fwd    = Collar.GetATMfwd(myZero, q, spot, t);
            double    r      = myZero.LinInterp(t);
            //create default pricer
            var myPrice = new Pricer {
                Strike = strike, Payoff = paystyle
            };
            double pr = myPrice.BSprice(fwd, t, strike, r, vol, paystyle);

            return(pr);
        }
Esempio n. 4
0
        //fill grid forward rates
        private void FillForwardRate(ZeroCurve myZero)
        {
            double dt = Tau / Gridsteps;

            if (myZero != null)
            {
                if (FlatFlag)
                {
                    FlatRate = myZero.LinInterp(Tau);
                }
                for (int idx = 0; idx < Gridsteps; idx++)
                {
                    SetR(idx, FlatFlag ? FlatRate : myZero.ForwardRate(idx * dt, (idx + 1) * dt));
                }
            }
        }
Esempio n. 5
0
        //public spotStar
        private void MakeSpotStar(ZeroCurve myZero, DivList myDivList)
        {
            _spotstar = Spot;

            if (myDivList != null && myZero != null)
            {
                for (int idx = 0; idx < myDivList.Divpoints; idx++)
                {
                    if (myDivList.GetT(idx) <= Tau)
                    {
                        double d1 = myDivList.GetD(idx);
                        double r1 = myZero.LinInterp(myDivList.GetT(idx));
                        double t1 = Math.Exp(-r1 * myDivList.GetT(idx));
                        _spotstar -= d1 * t1;
                    }
                }
            }
        }
Esempio n. 6
0
 //public spotStar
 private void MakeSpotZero(ZeroCurve myZero, DivList myDivList)
 {
     _spot0 = Spot;
     _ratio = new double[myDivList.Divpoints];
     if (myZero != null)
     {
         for (int idx = 0; idx < myDivList.Divpoints; idx++)
         {
             if (myDivList.GetT(idx) <= Tau)
             {
                 double d1 = myDivList.GetD(idx);
                 double r1 = myZero.LinInterp(myDivList.GetT(idx));
                 double t1 = Math.Exp(-r1 * myDivList.GetT(idx));
                 _ratio[idx] = d1 * t1 / _spot0;
                 if (_ratio[idx] > 1)
                 {
                     throw new Exception("Dividend greater than spot");
                 }
                 _spot0 = _spot0 * (1 - _ratio[idx]);
             }
         }
     }
 }