Пример #1
0
        private static ZeroCurve UnpackZero(DateTime today, DateTime[] dates, double[] amts)
        {
            int n1 = dates.Length;
            int n2 = dates.Length;

            if (n1 != n2)
            {
                throw new Exception("Rate ranges must be of the same length");
            }
            var zc = new ZeroCurve {
                Ratepoints = n1
            };

            zc.MakeArrays();
            int kdx = 0;

            for (int idx = 0; idx < n1; idx++)
            {
                double time = dates[idx].Subtract(today).Days / 365.0;
                double rate = amts[idx];
                zc.SetR(kdx, rate, time);
                kdx++;
            }
            return(zc);
        }
Пример #2
0
        /// <summary>
        /// Unpacks the zero rate curve.
        /// </summary>
        /// <param name="inZero">The in zero.</param>
        /// <returns></returns>
        public static ZeroCurve UnpackZeroRateCurve(ZeroAUDCurve inZero)
        {
            var myZero = new ZeroCurve {
                Ratepoints = inZero.Rates.Length
            };

            myZero.MakeArrays();
            int idx = 0;

            foreach (ZeroRate dt in inZero.ZeroRates)
            {
                TimeSpan ts = dt.TenorDate - inZero.CurveDate;
                myZero.SetR(idx, dt.Rate, (ts.Days / 365.0));
                idx++;
            }
            return(myZero);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="today"></param>
        /// <param name="spot"></param>
        /// <param name="strike"></param>
        /// <param name="sig"></param>
        /// <param name="dexp"></param>
        /// <param name="sPay"></param>
        /// <param name="sStyle"></param>
        /// <param name="nGrid"></param>
        /// <param name="tStep"></param>
        /// <param name="iNum"></param>
        /// <param name="divamsAsArray"></param>
        /// <param name="divdatesAsArray"></param>
        /// <param name="zeramsAsArray"></param>
        /// <param name="zerdatesAsArray"></param>
        /// <returns></returns>
        public double GetEquityGreeks(DateTime today,
                                      double spot,
                                      double strike,
                                      double sig,
                                      DateTime dexp,
                                      string sPay,
                                      string sStyle,
                                      int nGrid,
                                      double tStep,
                                      int iNum,
                                      Excel.Range divamsAsArray,
                                      Excel.Range divdatesAsArray,
                                      Excel.Range zeramsAsArray,
                                      Excel.Range zerdatesAsArray
                                      )
        {
            //Map the ranges
            var divams   = DataRangeHelper.StripDoubleRange(divamsAsArray);
            var divdates = DataRangeHelper.StripDateTimeRange(divamsAsArray);
            var zerams   = DataRangeHelper.StripDoubleRange(zeramsAsArray);
            var zerdates = DataRangeHelper.StripDateTimeRange(zerdatesAsArray);
            //set up the DivList
            int nd    = divdates.Count; //GetUpperBound(0) + 1;
            var myDiv = new DivList {
                Divpoints = nd
            };

            myDiv.MakeArrays();
            for (int idx = 0; idx != nd; idx++)
            {
                double   r  = divams[idx];
                DateTime dp = divdates[idx];
                TimeSpan ts = dp - today;
                myDiv.SetD(idx, r, ts.Days / 365.0);
            }
            //set up the zero
            int nz     = zerdates.Count;//GetUpperBound(0) + 1;
            var myZero = new ZeroCurve {
                Ratepoints = nz
            };

            myZero.MakeArrays();
            for (int idx = 0; idx != nz; idx++)
            {
                double   r  = zerams[idx];
                DateTime dp = zerdates[idx];
                TimeSpan ts = dp - today;
                myZero.SetR(idx, r, ts.Days / 365.0);
            }
            //compute the discounted dividends to  expiry and work out continuous
            TimeSpan tsE  = dexp - today;
            double   texp = tsE.Days / 365.0;

            for (int idx = 0; idx != nd; idx++)
            {
                if (myDiv.GetT(idx) <= texp)
                {
                    double d = myDiv.GetD(idx) * Math.Exp(-myDiv.GetT(idx) * myZero.LinInterp(myDiv.GetT(idx)));
                }
            }
            //double qc = -Math.Log((spot - sum) / spot) / texp;
            //double rc = myZero.linInterp(texp);
            var myG = new Grid
            {
                XL     = Math.Log(spot) - 8.0 * sig * Math.Sqrt(texp),
                Xu     = Math.Log(spot) + 8.0 * sig * Math.Sqrt(texp),
                Steps  = nGrid,
                Strike = strike,
                Spot   = spot,
                SPay   = sPay,
                SStyle = sStyle,
                T      = texp
            };

            myG.NTsteps = Convert.ToInt32(myG.T / tStep);
            myG.Sig     = sig;
            var    greeks = new double[4];
            double price  = myG.Pricer(myZero, myDiv, ref greeks, true);

            myG.Sig += 0.01;
            double priceUp = myG.Pricer(myZero, myDiv, ref greeks, false);

            greeks[3] = priceUp - price;
            return(greeks[iNum]);
        }