Example #1
0
        /// <summary>
        /// Gets the Greeks.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="spot">The spot.</param>
        /// <param name="strike">The strike.</param>
        /// <param name="vol">The vol.</param>
        /// <param name="expiry"></param>
        /// <param name="paystyle">The paystyle.</param>
        /// <param name="zeroDates"></param>
        /// <param name="zeroRates">The zero curve.</param>
        /// <param name="divDates"></param>
        /// <param name="divAms">The div curve.</param>
        /// <param name="gridsteps">The gridsteps.</param>
        /// <param name="smoo">The smoo.</param>
        /// <param name="flatFlag">if set to <c>true</c> [flat flag].</param>
        /// <param name="today"></param>
        /// <returns></returns>
        public static double[] BinomialGetGreeks(string style, double spot, double strike, double vol, DateTime today, DateTime expiry,
                                                 string paystyle, DateTime[] zeroDates, double[] zeroRates, DateTime[] divDates, double[] divAms, double gridsteps, string smoo, bool flatFlag)
        {
            const int arrsize = 4;

            gridsteps = (gridsteps == 0.0) ? 20 : gridsteps;
            int       nGridsteps = Convert.ToInt32(gridsteps);
            string    smoothing  = (smoo.ToLower().Equals("n")) ? "n" : "y";
            double    t          = expiry.Subtract(today).Days / 365.0;
            ZeroCurve myZero     = (new Wrapper()).UnpackZero(today, zeroDates, zeroRates);
            DivList   myDiv      = (new Wrapper()).UnpackDiv(today, expiry, divDates, divAms);
            var       retArray   = new double[arrsize];
            //create the tree
            var myTree = new DiscreteTree(t, vol, spot, nGridsteps, true)
            {
                Gridsteps = nGridsteps
            };

            myTree.MakeGrid(myZero, myDiv);
            //create pricer
            var myPrice = new Pricer(strike, paystyle, smoothing, style);

            myPrice.MakeGrid(myTree);
            myPrice.Price();
            var myGreeks = new Greeks();

            myGreeks.MakeDeltaGamma(myTree, myPrice, myZero, myDiv);
            double delta = myGreeks.Delta;
            double gamma = myGreeks.Gamma;

            myGreeks.MakeVega(myTree, myPrice, myZero, myDiv);
            double vega = myGreeks.Vega;

            myGreeks.MakeTheta(myTree, myPrice, myZero, myDiv);
            double theta = myGreeks.Theta;

            retArray[0] = delta;
            retArray[1] = gamma;
            retArray[2] = vega;
            retArray[3] = theta;
            return(retArray);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="myZero"></param>
        /// <param name="myDiv"></param>
        /// <param name="orcParams"></param>
        /// <param name="t"></param>
        /// <param name="strike"></param>
        /// <param name="spot"></param>
        /// <param name="style"></param>
        /// <param name="paystyle"></param>
        /// <param name="gridsteps"></param>
        /// <returns></returns>
        public static double FindPrice(ZeroCurve myZero, DivList myDiv, double[] orcParams, double t,
                                       double strike, double spot, string style, string paystyle, double gridsteps)
        {
            //get the atfwd
            double atFwd = GetATMfwd(myZero, myDiv, spot, t);
            //unpack the orc paramters
            //double currentVol = OrcParams[0];
            //double slopeRef = OrcParams[1];
            //double putCurve = OrcParams[2];
            //double callCurve = OrcParams[3];
            //double dnCutOff = OrcParams[4];
            //double upCutOff = OrcParams[5];
            //double refFwd = OrcParams[6];
            //double refVol = OrcParams[7];
            //double vcr = OrcParams[8];
            //double scr = OrcParams[9];
            //double ssr = OrcParams[10];
            //double dsr = OrcParams[11];
            //double usr = OrcParams[12];

            //set up the tree
            var myTree     = new DiscreteTree();
            var myVol      = new OrcWingVol();
            int nGridsteps = (gridsteps < 20.0) ? 20 : Convert.ToInt32(gridsteps);

            myTree.Gridsteps = nGridsteps;
            myTree.Tau       = t;
            myTree.Sig       = myVol.Orcvol(atFwd, strike);
            myTree.Spot      = spot;
            myTree.MakeGrid(myZero, myDiv);
            //create pricer
            var myPrice = new Pricer {
                Strike = strike, Payoff = paystyle, Smoothing = "y", Style = style
            };

            myPrice.MakeGrid(myTree);
            double pr = myPrice.Price();

            return(pr);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="style"></param>
        /// <param name="spot"></param>
        /// <param name="strike"></param>
        /// <param name="vol"></param>
        /// <param name="today"></param>
        /// <param name="expiry"></param>
        /// <param name="paystyle"></param>
        /// <param name="zeroDates"></param>
        /// <param name="zeroRates"></param>
        /// <param name="divDates"></param>
        /// <param name="divAms"></param>
        /// <param name="gridsteps"></param>
        /// <param name="smoo"></param>
        /// <param name="flatFlag"></param>
        /// <returns></returns>
        public static double BinomialPricer(string style, double spot, double strike, double vol, DateTime today, DateTime expiry,
                                            string paystyle, DateTime[] zeroDates, double[] zeroRates, DateTime[] divDates, double[] divAms, double gridsteps, string smoo, bool flatFlag)
        {
            gridsteps = (gridsteps == 0.0) ? 20 : gridsteps;
            int       nGridsteps = Convert.ToInt32(gridsteps);
            string    smoothing  = (smoo.ToLower().Equals("n")) ? "n" : "y";
            double    t          = expiry.Subtract(today).Days / 365.0;
            var       wrapper    = new Wrapper();
            ZeroCurve myZero     = wrapper.UnpackZero(today, zeroDates, zeroRates);
            DivList   myDiv      = wrapper.UnpackDiv(today, expiry, divDates, divAms);
            //create the tree
            var myTree = new DiscreteTree(t, vol, spot, nGridsteps, true);

            myTree.MakeGrid(myZero, myDiv);
            //create pricer
            var myPrice = new Pricer(strike, paystyle, smoothing, style);

            myPrice.MakeGrid(myTree);
            double pr = myPrice.Price();

            return(pr);
        }