Beispiel #1
0
 /// <summary>
 /// Method constructs QuantLib option price model with necessary estimators of underlying volatility, risk free rate, and underlying dividend yield
 /// </summary>
 /// <param name="pricingEngineFunc">Function takes option and modeled stochastic process, and returns new pricing engine to run calculations for that option</param>
 /// <param name="underlyingVolEstimator">The underlying volatility estimator</param>
 /// <param name="riskFreeRateEstimator">The risk free rate estimator</param>
 /// <param name="dividendYieldEstimator">The underlying dividend yield estimator</param>
 public QLOptionPriceModel(PricingEngineFuncEx pricingEngineFunc, IQLUnderlyingVolatilityEstimator underlyingVolEstimator, IQLRiskFreeRateEstimator riskFreeRateEstimator, IQLDividendYieldEstimator dividendYieldEstimator)
 {
     _pricingEngineFunc      = pricingEngineFunc;
     _underlyingVolEstimator = underlyingVolEstimator ?? new ConstantQLUnderlyingVolatilityEstimator();
     _riskFreeRateEstimator  = riskFreeRateEstimator ?? new ConstantQLRiskFreeRateEstimator();
     _dividendYieldEstimator = dividendYieldEstimator ?? new ConstantQLDividendYieldEstimator();
 }
Beispiel #2
0
        /// <summary>
        /// Pricing engine for European options using finite-differences.
        /// QuantLib reference: http://quantlib.org/reference/class_quant_lib_1_1_f_d_european_engine.html
        /// </summary>
        /// <returns>New option price model instance</returns>
        public static IOptionPriceModel CrankNicolsonFD()
        {
            PricingEngineFuncEx pricingEngineFunc = (symbol, process) =>
                                                    symbol.ID.OptionStyle == OptionStyle.American ?
                                                    new FDAmericanEngine(process, _timeStepsFD, _timeStepsFD - 1) as IPricingEngine :
                                                    new FDEuropeanEngine(process, _timeStepsFD, _timeStepsFD - 1) as IPricingEngine;

            return(new QLOptionPriceModel(pricingEngineFunc,
                                          _underlyingVolEstimator,
                                          _riskFreeRateEstimator,
                                          _dividendYieldEstimator));
        }
Beispiel #3
0
        /// <summary>
        /// Method constructs QuantLib option price model with necessary estimators of underlying volatility, risk free rate, and underlying dividend yield
        /// </summary>
        /// <param name="pricingEngineFunc">Function takes option and modeled stochastic process, and returns new pricing engine to run calculations for that option</param>
        /// <param name="underlyingVolEstimator">The underlying volatility estimator</param>
        /// <param name="riskFreeRateEstimator">The risk free rate estimator</param>
        /// <param name="dividendYieldEstimator">The underlying dividend yield estimator</param>
        /// <param name="allowedOptionStyles">List of option styles supported by the pricing model. It defaults to both American and European option styles</param>
        public QLOptionPriceModel(PricingEngineFuncEx pricingEngineFunc, IQLUnderlyingVolatilityEstimator underlyingVolEstimator, IQLRiskFreeRateEstimator riskFreeRateEstimator, IQLDividendYieldEstimator dividendYieldEstimator, OptionStyle[] allowedOptionStyles = null)
        {
            _pricingEngineFunc      = pricingEngineFunc;
            _underlyingVolEstimator = underlyingVolEstimator ?? new ConstantQLUnderlyingVolatilityEstimator();
            _riskFreeRateEstimator  = riskFreeRateEstimator ?? new ConstantQLRiskFreeRateEstimator();
            _dividendYieldEstimator = dividendYieldEstimator ?? new ConstantQLDividendYieldEstimator();

            AllowedOptionStyles = allowedOptionStyles ?? _defaultAllowedOptionStyles;

            // Required for QL to consider the option as not expired on the expiration date.
            // This is done in the constructor instead of a static contructor because QLNet.Settings attributes are ThreadStatic,
            // so doing it in a static constructor would only set it for the first thread that instantiates QLOptionPriceModel or
            // accesses any of its static members.
            QLNet.Settings.includeReferenceDateEvents = true;
        }