| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
| 5 | Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl |
| 6 | |
| 7 | This file is part of QuantLib, a free-software/open-source library |
| 8 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 9 | |
| 10 | QuantLib is free software: you can redistribute it and/or modify it |
| 11 | under the terms of the QuantLib license. You should have received a |
| 12 | copy of the license along with this program; if not, please email |
| 13 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 14 | <http://quantlib.org/license.shtml>. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 19 | */ |
| 20 | |
| 21 | #include <ql/instrument.hpp> |
| 22 | #include <ql/settings.hpp> |
| 23 | |
| 24 | namespace QuantLib { |
| 25 | |
| 26 | Instrument::Instrument() |
| 27 | : NPV_(Null<Real>()), errorEstimate_(Null<Real>()) { |
| 28 | // this makes sense in general (if the evaluation date |
| 29 | // changes, you probably want to recalculate) and can also |
| 30 | // help avoid some edge cases when lazy objects only forward |
| 31 | // their first notification. |
| 32 | registerWith(h: Settings::instance().evaluationDate()); |
| 33 | } |
| 34 | |
| 35 | void Instrument::setPricingEngine(const ext::shared_ptr<PricingEngine>& e) { |
| 36 | if (engine_ != nullptr) |
| 37 | unregisterWith(h: engine_); |
| 38 | engine_ = e; |
| 39 | if (engine_ != nullptr) |
| 40 | registerWith(h: engine_); |
| 41 | // trigger (lazy) recalculation and notify observers |
| 42 | update(); |
| 43 | } |
| 44 | |
| 45 | void Instrument::setupArguments(PricingEngine::arguments*) const { |
| 46 | QL_FAIL("Instrument::setupArguments() not implemented" ); |
| 47 | } |
| 48 | |
| 49 | } |
| 50 | |