コード例 #1
0
        public void TestComputeAmericanCallByBinomialPricer()
        {
            var n      = 15;
            var rf     = 0.02;
            var option = new Option
            {
                Type       = OptionType.Call,
                Underlying = new Security {
                    Volatility = 0.3, MarketPrice = 100, YieldRate = 0.01
                },
                Strike         = 110,
                TimeToMaturity = 0.25,
            };

            using (ReportTime.Start())
            {
                BinomialPricer.ComputeOption(option, rf, n);
            }
        }
コード例 #2
0
        public void TestVarianceMatrix()
        {
            var secs = FileReaders.ReadSecurities(@"securities.csv");
            var covs = FileReaders.ReadCorrelations(@"correlations.csv", secs);

            using (ReportTime.Start())
            {
                Dictionary <Security, double> weights;
                var expectedReturn = 9d;
                var matrix         = Portfolios.ComputeCovariances(covs);
                var variance       = Portfolios.ComputePortfolioMinimumVariance(matrix, expectedReturn, out weights);


                Console.WriteLine(weights.Aggregate("Weights:" + Environment.NewLine,
                                                    (str, pair) => str + (Environment.NewLine + pair.Key.Symbol + "," + pair.Value)));
                Console.WriteLine("ExpectedReturn: " + expectedReturn);
                Console.WriteLine("Variance: " + variance);
                Console.WriteLine("Sharpe: " + expectedReturn / Math.Sqrt(variance));
            }
        }
コード例 #3
0
        public static void TestComputeAmericanPutByBinomialPricer()
        {
            var n      = 15;
            var rf     = 0.02;
            var option = new Option
            {
                Type       = OptionType.Put,
                Underlying = new Security {
                    Volatility = 0.3, MarketPrice = 100, YieldRate = 0.01
                },
                Strike         = 110,
                TimeToMaturity = 0.25,
            };

            using (ReportTime.Start())
            {
                BinomialPricer.ComputeOption(option, rf, n);
                Assert.Greater(option.FairPrice, 2.60);
                Assert.Less(option.FairPrice, 2.61);
            }
        }
コード例 #4
0
        public static void TestComputeAmericanPutByBinomialPricer()
        {
            var n      = 15;
            var rf     = 0.02;
            var option = new Option
            {
                Type       = OptionType.Put,
                Underlying = new Security {
                    Volatility = 0.3, MarketPrice = 100, YieldRate = 0.01
                },
                Strike         = 110,
                TimeToMaturity = 0.25,
            };

            using (ReportTime.Start())
            {
                BinomialPricer.ComputeOption(option, rf, n);
                Console.WriteLine(option.FairPrice >= 12.359);
                Console.WriteLine(option.FairPrice <= 12.360);
            }
        }