| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2009 Roland Lichters |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | #include <ql/event.hpp> |
| 21 | #include <ql/experimental/credit/riskyassetswapoption.hpp> |
| 22 | #include <ql/math/distributions/normaldistribution.hpp> |
| 23 | #include <utility> |
| 24 | |
| 25 | namespace QuantLib { |
| 26 | |
| 27 | RiskyAssetSwapOption::RiskyAssetSwapOption(ext::shared_ptr<RiskyAssetSwap> asw, |
| 28 | const Date& expiry, |
| 29 | Rate marketSpread, |
| 30 | Volatility spreadVolatility) |
| 31 | : asw_(std::move(asw)), expiry_(expiry), marketSpread_(marketSpread), |
| 32 | spreadVolatility_(spreadVolatility) {} |
| 33 | |
| 34 | bool RiskyAssetSwapOption::isExpired() const { |
| 35 | return detail::simple_event(expiry_).hasOccurred(); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | void RiskyAssetSwapOption::performCalculations() const { |
| 40 | Real w; |
| 41 | if (asw_->fixedPayer()) // strike receiver = asw call = spread put |
| 42 | w = -1.0; |
| 43 | else |
| 44 | w = 1.0; |
| 45 | |
| 46 | Date today = Settings::instance().evaluationDate(); |
| 47 | Time expiryTime = Actual365Fixed().yearFraction(d1: today, d2: expiry_); |
| 48 | Real stdDev = spreadVolatility_ * std::sqrt(x: expiryTime); |
| 49 | Real d = (asw_->spread() - marketSpread_) / stdDev; |
| 50 | Real A0 = asw_->nominal() * asw_->floatAnnuity(); |
| 51 | |
| 52 | NPV_ = A0 * stdDev * (w*d * CumulativeNormalDistribution()(w*d) |
| 53 | + NormalDistribution()(d)); |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | |