optionPricingExample.cpp
This example show how to price option using Black-Scholes model.
#include <juliant.hpp>
using namespace julian;
int main() {
//
// Defining auxiliary objects
//
Date today(2018,APR,26);
PLNHoliday holiday;
.addHoliday(holiday)
.withSpotLag(2);
InterestRate rate;
ACT365 yf;
//
// Creating market model
//
ir::FlatCurve curve1(rate, 0.05, today, calendar);
ir::FlatCurve curve2(rate, 0.02, today, calendar);
FlatVolatility volatility(today, 0.15, yf);
BlackScholesModel model(today, 100.0, curve1, curve2, volatility);
//
// Creating option
//
auto exp = today + 2*YEAR;
EuropeanOpt option_c(today, today, exp, exp, 1000.0, 100.0, CALL);
EuropeanOpt option_p(today, today, exp, exp, 1000.0, 100.0, PUT);
//
// Creating pricer and greeks report
//
AnalyticalPricingEngine pricer;
.withDelta()
.withGamma()
.withVega()
.withVolga()
.withVanna()
.withTheta()
.build();
//
// Performing calculations
//
DataFrame df;
for (double s = 50.0; s <= 150.0; s += 0.25) {
model.setAssetPrize(s);
DataEntryClerk input;
input.add(greeks);
df.append(input);
}
for (double s = 50.0; s <= 150.0; s += 0.25) {
model.setAssetPrize(s);
auto greeks = risks->getRisks(model, pricer, option_p);
DataEntryClerk input;
input.add("Spot", s);
input.add(greeks);
df.append(input);
}
}