QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mc_discr_arith_av_strike.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
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/pricingengines/asian/mc_discr_arith_av_strike.hpp>
21
22namespace QuantLib {
23
25 DiscountFactor discount,
26 Real runningSum,
27 Size pastFixings)
28 : type_(type), discount_(discount),
29 runningSum_(runningSum), pastFixings_(pastFixings) {}
30
31
33 Size n = path.length();
34 QL_REQUIRE(n > 1, "the path cannot be empty");
35
36 Real averageStrike;
37 if (path.timeGrid().mandatoryTimes()[0]==0.0) {
38 // include initial fixing
39 averageStrike =
40 std::accumulate(path.begin(),path.end(),runningSum_) /
41 (pastFixings_ + n);
42 } else {
43 averageStrike =
44 std::accumulate(path.begin()+1,path.end(),runningSum_) /
45 (pastFixings_ + n - 1);
46 }
47
48 return discount_
49 * PlainVanillaPayoff(type_, averageStrike)(path.back());
50 }
51
52}
53
ArithmeticASOPathPricer(Option::Type type, 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
Real back() const
final asset value
Definition: path.hpp:130
const TimeGrid & timeGrid() const
time grid
Definition: path.hpp:142
Plain-vanilla payoff.
Definition: payoffs.hpp:105
const std::vector< Time > & mandatoryTimes() const
Definition: timegrid.hpp:151
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
Definition: any.hpp:35