21#include <ql/experimental/fx/blackdeltacalculator.hpp>
25Real
getStrikeFromDelta(Option::Type optionType, Real delta, DeltaVolQuote::DeltaType dt, Real spot, Real domDiscount,
26 Real forDiscount, QuantLib::ext::shared_ptr<BlackVolTermStructure> vol, Real t, Real accuracy,
28 Real forward = spot / domDiscount * forDiscount;
29 Real result = forward, lastResult;
32 Real stddev = std::sqrt(vol->blackVariance(t, result));
34 BlackDeltaCalculator bdc(optionType, dt, spot, domDiscount, forDiscount, stddev);
36 result = bdc.strikeFromDelta(delta);
37 }
catch (
const std::exception& e) {
38 QL_FAIL(
"getStrikeFromDelta("
39 << (optionType == Option::Call ? 1.0 : -1.0) * delta <<
") could not be computed for spot=" << spot
40 <<
", forward=" << spot / domDiscount * forDiscount <<
" (domRate=" << -std::log(domDiscount) / t
41 <<
", forRate=" << -std::log(forDiscount) / t <<
"), vol=" << stddev / std::sqrt(t)
42 <<
", expiry=" << t <<
": " << e.what());
44 }
while (std::abs((result - lastResult) / lastResult) > accuracy && ++iterations < maxIterations);
45 QL_REQUIRE(iterations < maxIterations,
"getStrikeFromDelta: max iterations ("
46 << maxIterations <<
"), no solution found for accuracy " << accuracy
47 <<
", last iterations: " << lastResult <<
"/" << result
48 <<
", spot=" << spot <<
", forward=" << spot / domDiscount * forDiscount
49 <<
" (domRate=" << -std::log(domDiscount) / t
50 <<
", forRate=" << -std::log(forDiscount) / t <<
"), expiry=" << t);
55Real
getAtmStrike(DeltaVolQuote::DeltaType dt, DeltaVolQuote::AtmType at, Real spot, Real domDiscount, Real forDiscount,
56 QuantLib::ext::shared_ptr<BlackVolTermStructure> vol, Real t, Real accuracy, Size maxIterations) {
57 Real forward = spot / domDiscount * forDiscount;
58 Real result = forward, lastResult;
61 Real stddev = std::sqrt(vol->blackVariance(t, result));
63 BlackDeltaCalculator bdc(Option::Call, dt, spot, domDiscount, forDiscount, stddev);
65 result = bdc.atmStrike(at);
66 }
catch (
const std::exception& e) {
67 QL_FAIL(
"getAtmStrike() could not be computed for spot="
68 << spot <<
", forward=" << spot / domDiscount * forDiscount
69 <<
" (domRate=" << -std::log(domDiscount) / t <<
", forRate=" << -std::log(forDiscount) / t
70 <<
"), vol=" << stddev / std::sqrt(t) <<
", expiry=" << t <<
": " << e.what());
72 }
while (std::abs((result - lastResult) / lastResult) > accuracy && ++iterations < maxIterations);
73 QL_REQUIRE(iterations < maxIterations,
"getAtmStrike: max iterations ("
74 << maxIterations <<
"), no solution found for accuracy " << accuracy
75 <<
", last iterations: " << lastResult <<
"/" << result
76 <<
", spot=" << spot <<
", forward=" << spot / domDiscount * forDiscount
77 <<
" (domRate=" << -std::log(domDiscount) / t
78 <<
", forRate=" << -std::log(forDiscount) / t <<
"), expiry=" << t);
utilities to calculate strikes from deltas and atm strikes on smiles
Real getStrikeFromDelta(Option::Type optionType, Real delta, DeltaVolQuote::DeltaType dt, Real spot, Real domDiscount, Real forDiscount, QuantLib::ext::shared_ptr< BlackVolTermStructure > vol, Real t, Real accuracy, Size maxIterations)
Real getAtmStrike(DeltaVolQuote::DeltaType dt, DeltaVolQuote::AtmType at, Real spot, Real domDiscount, Real forDiscount, QuantLib::ext::shared_ptr< BlackVolTermStructure > vol, Real t, Real accuracy, Size maxIterations)