optionPricingExample.cpp

This example show how to price option using Black-Scholes model.

option_example_call_pv.png
option_example_put_pv.png
option_example_call_delta.png
option_example_put_delta.png
option_example_gamma.png
option_example_vega.png
option_example_volga.png
option_example_vanna.png
#include <juliant.hpp>
using namespace julian;
int main() {
//
// Defining auxiliary objects
//
Date today(2018,APR,26);
PLNHoliday holiday;
Calendar calendar = BuildCalendar()
.addHoliday(holiday)
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
//
.withDelta(1e-4, NumDiffScheme::FWD, "Delta_fwd")
.withDelta(1e-3, NumDiffScheme::BWD, "Delta_bwd")
.build();
//
// Performing calculations
//
for (double s = 50.0; s <= 150.0; s += 0.25) {
model.setAssetPrize(s);
auto greeks = risks->getRisks(model, pricer, option_c);
input.add("Spot", s);
input.add("Type", "Call");
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);
input.add("Spot", s);
input.add("Type", "Put");
input.add(greeks);
df.append(input);
}
df.printToCsv("options",';');
}