1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2010 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include <ql/experimental/exoticoptions/analyticamericanmargrabeengine.hpp>
#include <ql/pricingengines/vanilla/bjerksundstenslandengine.hpp>
#include <ql/exercise.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
namespace QuantLib {
AnalyticAmericanMargrabeEngine::AnalyticAmericanMargrabeEngine(
const boost::shared_ptr<GeneralizedBlackScholesProcess>& process1,
const boost::shared_ptr<GeneralizedBlackScholesProcess>& process2,
Real correlation)
: process1_(process1), process2_(process2), rho_(correlation) {
registerWith(process1_);
registerWith(process2_);
}
void AnalyticAmericanMargrabeEngine::calculate() const {
QL_REQUIRE(arguments_.exercise->type() == Exercise::American,
"not an American option");
boost::shared_ptr<AmericanExercise> exercise =
boost::dynamic_pointer_cast<AmericanExercise>(arguments_.exercise);
QL_REQUIRE(exercise, "not an American option");
boost::shared_ptr<NullPayoff> payoff0 =
boost::dynamic_pointer_cast<NullPayoff>(arguments_.payoff);
QL_REQUIRE(payoff0, "not a null payoff");
// The option can be priced as an American single-asset option
// with an adjusted process and payoff.
Date today = Settings::instance().evaluationDate();
DayCounter rfdc = process1_->riskFreeRate()->dayCounter();
Time t = rfdc.yearFraction(process1_->riskFreeRate()->referenceDate(),
arguments_.exercise->lastDate());
Real s1 = process1_->stateVariable()->value();
Real s2 = process2_->stateVariable()->value();
boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(arguments_.Q1*s1));
boost::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(Option::Call, arguments_.Q2*s2));
DiscountFactor dividendDiscount1 =
process1_->dividendYield()->discount(exercise->lastDate());
Rate q1 = -std::log(dividendDiscount1)/t;
DiscountFactor dividendDiscount2 =
process2_->dividendYield()->discount(exercise->lastDate());
Rate q2 = -std::log(dividendDiscount2)/t;
boost::shared_ptr<YieldTermStructure> qTS(
new FlatForward(today, q1, rfdc));
boost::shared_ptr<YieldTermStructure> rTS(
new FlatForward(today, q2, rfdc));
Real variance1 = process1_->blackVolatility()->blackVariance(
exercise->lastDate(), s1);
Real variance2 = process2_->blackVolatility()->blackVariance(
exercise->lastDate(), s2);
Real variance = variance1 + variance2
- 2*rho_*std::sqrt(variance1)*std::sqrt(variance2);
Volatility volatility = std::sqrt(variance/t);
boost::shared_ptr<BlackVolTermStructure> volTS(
new BlackConstantVol(today, NullCalendar(), volatility, rfdc));
boost::shared_ptr<BlackScholesMertonProcess> stochProcess(new
BlackScholesMertonProcess(Handle<Quote>(spot),
Handle<YieldTermStructure>(qTS),
Handle<YieldTermStructure>(rTS),
Handle<BlackVolTermStructure>(volTS)));
boost::shared_ptr<PricingEngine> engine(
new BjerksundStenslandApproximationEngine(stochProcess));
VanillaOption option(payoff, exercise);
option.setPricingEngine(engine);
results_.value = option.NPV();
}
}
|