示例#1
0
        public static void test_beta_black_perf()
        {
            Console.WriteLine("Computing ... ");
            var N   = 100000;
            var tic = DateTime.Now;

            for (var i = 0; i < N; ++i)
            {
                ClosedForm.black76(OptionType.Put, 10.0, 4.0, 0.5, 0.4);
                ClosedForm.black76(OptionType.Put, 10.0, 8.0, 1.5, 0.4);
                ClosedForm.black76(OptionType.Put, 10.0, 4.0, 0.5, 0.4);
                ClosedForm.black76(OptionType.Put, 10.0, 8.0, 1.5, 0.4);
                ClosedForm.black76(OptionType.Put, 10.0, 4.0, 0.5, 0.4);
                ClosedForm.black76(OptionType.Put, 10.0, 8.0, 1.5, 0.4);
            }
            var toc   = DateTime.Now;
            var ticBB = DateTime.Now;

            for (var i = 0; i < N; ++i)
            {
                BetaBlack.beta_black(0.1, OptionType.Put, 10.0, 4.0, 0.5, 0.4);
                BetaBlack.beta_black(0.1, OptionType.Put, 8.0, 4.0, 0.5, 0.4);
                BetaBlack.beta_black(0.5, OptionType.Put, 10.0, 4.0, 0.5, 0.4);
                BetaBlack.beta_black(0.5, OptionType.Put, 8.0, 4.0, 0.5, 0.4);
                BetaBlack.beta_black(0.5, OptionType.Put, -10.0, -14.0, 0.5, 0.4);
                BetaBlack.beta_black(0.5, OptionType.Put, -8.0, -10.0, 0.5, 0.4);
            }
            var tocBB = DateTime.Now;

            var ticBBP = DateTime.Now;

            var ignore = 0.0;

            for (var i = 0; i < N; ++i)
            {
                BetaBlack.beta_black_b(0.1, OptionType.Put, 10.0, 4.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
                BetaBlack.beta_black_b(0.1, OptionType.Put, 8.0, 4.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
                BetaBlack.beta_black_b(0.5, OptionType.Put, 10.0, 4.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
                BetaBlack.beta_black_b(0.5, OptionType.Put, 8.0, 4.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
                BetaBlack.beta_black_b(0.5, OptionType.Put, -10.0, -14.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
                BetaBlack.beta_black_b(0.5, OptionType.Put, -8.0, -10.0, 0.5, 0.4, ref ignore, ref ignore, ref ignore,
                                       ref ignore, ref ignore, 1.0);
            }

            var tocBBP = DateTime.Now;

            Console.WriteLine("Done");
            Console.WriteLine($"Black: {(toc - tic).TotalMilliseconds}");
            Console.WriteLine($"B-Black: {(tocBB - ticBB).TotalMilliseconds}");
            Console.WriteLine($"First Order Risk B-Black : {(tocBBP - ticBBP).TotalMilliseconds}");
            Console.WriteLine($"PV time in # blacks: {(tocBB - ticBB).TotalMilliseconds / (toc - tic).TotalMilliseconds}");
            Console.WriteLine($"Risk first order time in # blacks: {(tocBBP - ticBBP).TotalMilliseconds / (toc - tic).TotalMilliseconds}");
        }
示例#2
0
        public static double beta_black_normal_vol(double beta, double F, double K, double T, double sigma)
        {
            var optType = OptionType.Put; // F > K ? OptionType.Put : OptionType.Call;
            var bbPrice = beta_black(beta, optType, F, K, T, sigma);

            try
            {
                return(ClosedForm.ibachelier(optType, F, K, T, bbPrice));
            }
            catch (Exception e)
            {
                FS.WithInfo(e, $"beta ={beta}, optType = {optType}, F = {F}, K = {K}, T = {T}, sigma = {sigma}, bbPrice = {bbPrice}");
                throw;
            }
        }