Exemplo n.º 1
0
            public override void Run()
            {
                StartTime = DateTime.Parse("01/01/2000");
                EndTime   = DateTime.Parse("12/31/2019");

                foreach (var dataSource in _testDataSources)
                {
                    AddDataSource(dataSource);
                }

                foreach (DateTime simTime in SimTimes)
                {
                    Instrument underlying = Instruments
                                            .Where(i => i.IsOption == false)
                                            .First();

                    Instrument option = Instruments
                                        .Where(i => i.IsOption == true)
                                        .First();

                    double riskFreeRate  = _riskFree;
                    double dividendYield = _divYield;

                    var iv     = option.BlackScholesImplied(riskFreeRate, dividendYield);
                    var greeks = option.BlackScholes(iv.Volatility, riskFreeRate, dividendYield);

#if false
                    Output.WriteLine("impliedVol = {0:F8}, delta = {1:F8}, gamma = {2:F8}, theta = {3:F8}, vega = {4:F8}",
                                     iv.Volatility, greeks.Delta, greeks.Gamma, greeks.Theta, greeks.Vega);
#else
                    //Assert.IsTrue(Math.Abs(iv.Price - greeks.Price) < 1e-5);
                    Assert.IsTrue(Math.Abs(iv.Volatility - _iv) < 1e-5);
                    Assert.IsTrue(Math.Abs(greeks.Delta - _delta) < 1e-5);
                    Assert.IsTrue(Math.Abs(greeks.Gamma - _gamma) < 1e-5);
                    Assert.IsTrue(Math.Abs(greeks.Theta - _theta) < 1e-5);
                    Assert.IsTrue(Math.Abs(greeks.Vega - _vega) < 1e-5);
#endif
                }
            }