?> QuantXpress – Deliver high performance automated trading and connectivity solutions



Options Pricing


BlitzTrader API provides implementation of the classic Black-Scholes option model for pricing Calls or Put. It also computes IV and Greeks: delta, gamma, theta, vega and rho The Library is used in our standard strategy of IV Scalping to compute delta position used to hedge the open position in options by buying/selling an underline contract.
BlackSholes and OptionsGreek class provides API method to evaluate options pricing and Greeks
 
using namespace QX.Base.Financial
.........
private IVObject _ivOptionObject = 
              new IVObject("OptionInstrument",
                           "Option Instrument",
                            true,
                            InstrumentType.Options,
                            MarketDataType.All,
                            OrderEventType.All);

private IVObject _ivUnderlyingObject =
              new IVObject("UnderlyingInstrument",
                           "Underlying Instrument",
                           true,
                           InstrumentType.Equity | InstrumentType.Futures,
                           MarketDataType.All,
                           OrderEventType.All);
.............................
.............................

IVInfo _ivInfoOption = base.GetIVInfo(_ivOptionObject);
Options _optionInstrument = ((Options)_ivInfoOption.IVInstrument.Instrument);

IVInfo _ivInfoUnderlying = base.GetIVInfo(_ivUnderlyingObject);
int _optionMaturityDays = _optionInstrument.RemainingExpiryDays;
double _timeToMaturityInYearsInABS = (double)_optionMaturityDays / 365;

// 10% risk free Interest rate
double _riskFreeInterestRateInABS = .01; 
double _dividendYieldInABS = 0;
private double GetCallOptionsImpliedVolatility(double optionPrice,
                                               double underlyingPrice)
{
    double marketVolatility = 0;
    marketVolatility = BlackScholes.GetCallInitialImpliedVolatility(underlyingPrice,
                                                                   _optionInstrument.StrikePrice,
                                                                   _timeToMaturityInYearsInABS,
                                                                   _riskFreeInterestRateInABS,
                                                                   optionPrice,
                                                                   _dividendYieldInABS) / 100;

     return marketVolatility;

}
private double GetPutOptionsImpliedVolatility(double optionPrice,
                                               double underlyingPrice)
{
    double marketVolatility = 0;
    marketVolatility = BlackScholes. GetPutInitialImpliedVolatility (underlyingPrice,
                                                                    _optionInstrument.StrikePrice,
                                                                    _timeToMaturityInYearsInABS,
                                                                    _riskFreeInterestRateInABS,
                                                                    optionPrice,
                                                                    _dividendYieldInABS) / 100;

     return marketVolatility;
}
private double GetUnderlyingDelta(OrderSide underlyingOrderSide, double ivValue)
{
    double underlyingPrice = 0;
    if (underlyingOrderSide == OrderSide.Buy)
        underlyingPrice = 
            _ivInfoUnderlying.MarketDataContainer.TouchLineInfo.BestAskPrice;
    else if (underlyingOrderSide == OrderSide.Sell)
        underlyingPrice = 
            _ivInfoUnderlying.MarketDataContainer.TouchLineInfo.BestBidPrice;

    if (underlyingPrice <= 0)
        return 0;

    double delta = 0;

    if (_optionInstrument.OptionType == OptionType.CA ||
                _optionInstrument.OptionType == OptionType.CE)
    {
        delta = OptionsGreeks.GetCallOptionDelta(
                    underlyingPrice,
                    _optionInstrument.StrikePrice,
                    _riskFreeInterestRateInABS,
                    ivValue,
                    _timeToMaturityInYearsInABS,
                    _dividendYieldInABS);
    }
    else if (_optionInstrument.OptionType == OptionType.PA ||
                _optionInstrument.OptionType == OptionType.PE)
    {
        delta = OptionsGreeks.GetPutOptionDelta(
                    underlyingPrice,
                    _optionInstrument.StrikePrice,
                    _riskFreeInterestRateInABS,
                    ivValue,
                    _timeToMaturityInYearsInABS,
                    _dividendYieldInABS);
    }

    return delta;
}