예제 #1
0
        public double[] CalcualteModelOutput(double[] para)
        {
            var x10     = para[0];
            var x20     = para[1];
            var alpha   = para[2];
            var beta    = para[3];
            var gamma   = para[4];
            var epsilon = para[5];
            var eita    = para[6];
            var vega    = para[7];
            var c       = para[8];

            var LS2Factor = new StaticTwoFactorLongstaffSchwartzModel();

            LS2Factor.maturities = maturities;
            LS2Factor.x10        = x10;
            LS2Factor.x20        = x20;
            LS2Factor.alpha      = alpha;
            LS2Factor.beta       = beta;
            LS2Factor.gamma      = gamma;
            LS2Factor.epsilon    = epsilon;
            LS2Factor.eita       = eita;
            LS2Factor.vega       = vega;
            //LS2Factor.c = c;
            var modelyields = LS2Factor.GetYields();

            return(modelyields);
        }
예제 #2
0
        private double StaticTwoFactorLongstaffSchwartzModelObj(double[] para)
        {
            var error      = 0.0;
            var lowerbound = new double[9] {
                0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, -29.99
            };
            var upperbound = new double[9] {
                29.99, 29.99, 29.99, 29.99, 29.99, 29.99, 29.99, 29.99, 29.99
            };

            if (CheckStaticTwoFactorLongstaffSchwartzModelPara(para, lowerbound, upperbound) == false)
            {
                error = 99999999999999.99;
            }
            else
            {
                var x10     = para[0];
                var x20     = para[1];
                var alpha   = para[2];
                var beta    = para[3];
                var gamma   = para[4];
                var epsilon = para[5];
                var eita    = para[6];
                var vega    = para[7];
                var c       = para[8];

                var LS2Factor = new StaticTwoFactorLongstaffSchwartzModel();
                LS2Factor.maturities = maturities;
                LS2Factor.x10        = x10;
                LS2Factor.x20        = x20;
                LS2Factor.alpha      = alpha;
                LS2Factor.beta       = beta;
                LS2Factor.gamma      = gamma;
                LS2Factor.epsilon    = epsilon;
                LS2Factor.eita       = eita;
                LS2Factor.vega       = vega;
                //LS2Factor.c = c;

                var modelyields = LS2Factor.GetYields();

                for (int i = 0; i < modelyields.Length; i++)
                {
                    error = error + (modelyields[i] - yields[i]) * (modelyields[i] - yields[i]);
                }
                if (Double.IsNaN(error))
                {
                    error = 99999999999999.99;
                }
            }

            return(error);
        }