European Vanilla Call and Put Option pricing and Implied Volatility calculation in C++
Add EuropeanVanilla.h and EuropeanVanilla.cpp in your project.
The 'UpdatePriceAndGreeks' method gives prices, deltas, gammas, thetas, and vegas of both call and put option
double StrikePrice = 20;
EuropeanVanilla pricer(StrikePrice); // class object requires strike price
double StockPrice = 15;
double DaysToExpiry = 30;
double InterestRate = 0.05;
double Volatility = 0.2;
pricer.UpdatePriceAndGreeks(StockPrice, InterestRate, DaysToExpiry, Volatility); // calculate price and greeks and updates public members
cout << pricer.CallPrice << endl;
cout << pricer.PutPrice << endl;
cout << pricer.CallDelta << endl;
cout << pricer.PutDelta << endl;
cout << pricer.CallGamma << endl;
cout << pricer.PutGamma << endl;
cout << pricer.CallTheta << endl;
cout << pricer.PutTheta << endl;
cout << pricer.CallVega << endl;
cout << pricer.PutVega << endl;
cout << "Call IV: " << pricer.ImpliedVolatility(StockPrice, InterestRate, DaysToExpiry, CallPrice, 'C') << endl;
cout << "Put IV: " << pricer.ImpliedVolatility(StockPrice, InterestRate, DaysToExpiry, PutPrice, 'P') << endl;