QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
mc_discr_arith_av_price.cpp
Go to the documentation of this file.
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 Ferdinando Ametrano
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
23
24namespace QuantLib {
25
27 Option::Type type,
28 Real strike, DiscountFactor discount,
29 Real runningSum, Size pastFixings)
30 : payoff_(type, strike), discount_(discount),
31 runningSum_(runningSum), pastFixings_(pastFixings) {
32 QL_REQUIRE(strike>=0.0,
33 "strike less than zero not allowed");
34 }
35
37 Size n = path.length();
38 QL_REQUIRE(n>1, "the path cannot be empty");
39
40 Real sum;
41 Size fixings;
42 if (path.timeGrid().mandatoryTimes()[0]==0.0) {
43 // include initial fixing
44 sum = std::accumulate(path.begin(),path.end(),runningSum_);
45 fixings = pastFixings_ + n;
46 } else {
47 sum = std::accumulate(path.begin()+1,path.end(),runningSum_);
48 fixings = pastFixings_ + n - 1;
49 }
50 Real averagePrice = sum/fixings;
51 return discount_ * payoff_(averagePrice);
52 }
53
54}
ArithmeticAPOPathPricer(Option::Type type, Real strike, DiscountFactor discount, Real runningSum=0.0, Size pastFixings=0)
Real operator()(const Path &path) const override
single-factor random walk
Definition: path.hpp:40
Size length() const
Definition: path.hpp:94
iterator end() const
Definition: path.hpp:150
iterator begin() const
Definition: path.hpp:146
const TimeGrid & timeGrid() const
time grid
Definition: path.hpp:142
const std::vector< Time > & mandatoryTimes() const
Definition: timegrid.hpp:151
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
const ext::shared_ptr< Payoff > payoff_
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Monte Carlo engine for discrete arithmetic average price Asian.
Monte Carlo engine for discrete geometric average price Asian.
Definition: any.hpp:35