25#include <ql/event.hpp>
26#include <ql/instruments/vanillaswingoption.hpp>
31 const Size secPerDay = 24U * 3600U;
33 std::pair<std::vector<Date>, std::vector<Size> >
34 createDateTimes(
const Date& from,
const Date& to,
Size stepSize) {
36 std::vector<Size> secs;
37 std::vector<Date> dates;
40 Size iterStepSize = 0U;
42 while (iterDate <= to) {
43 dates.push_back(iterDate);
44 secs.push_back(iterStepSize);
46 iterStepSize+=stepSize;
47 if (iterStepSize >= secPerDay) {
49 iterStepSize%=secPerDay;
53 return std::pair<std::vector<Date>,std::vector<Size> >(dates, secs);
59 seconds_(seconds.empty() ?
std::vector<
Size>(dates.size(), 0U) : seconds) {
61 "dates and seconds must have the same size");
64 "a date can not have more than 24*3600 seconds");
69 "date times must be sorted");
78 seconds_(createDateTimes(from, to, stepSizeSecs).second) {
84 const Date& refDate)
const {
92 t += dt*
seconds()[i]/(24*3600.);
94 QL_REQUIRE(t >= 0,
"exercise dates must not contain past date");
108 QL_FAIL(
"unknown/illegal option type");
122 QL_REQUIRE(
payoff,
"no payoff given");
123 QL_REQUIRE(
exercise,
"no exercise given");
126 "minExerciseRights <= maxExerciseRights");
128 "number of exercise rights exceeds "
129 "number of exercise dates");
135 QL_REQUIRE(
arguments !=
nullptr,
"wrong argument type");
138 = ext::dynamic_pointer_cast<StrikedTypePayoff>(
payoff_);
140 = ext::dynamic_pointer_cast<SwingExercise>(
exercise_);
degenerate base class for the Acyclic Visitor pattern
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
std::vector< Date > dates_
const std::vector< Date > & dates() const
Returns all exercise dates.
ext::shared_ptr< Payoff > payoff_
ext::shared_ptr< Exercise > exercise_
virtual void accept(AcyclicVisitor &)
const std::vector< Size > seconds_
SwingExercise(const std::vector< Date > &dates, const std::vector< Size > &seconds=std::vector< Size >())
const std::vector< Size > & seconds() const
std::vector< Time > exerciseTimes(const DayCounter &dc, const Date &refDate) const
Real operator()(Real price) const override
void accept(AcyclicVisitor &) override
ext::shared_ptr< SwingExercise > exercise
ext::shared_ptr< StrikedTypePayoff > payoff
void validate() const override
const Size minExerciseRights_
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
const Size maxExerciseRights_
Visitor for a specific class
virtual void visit(T &)=0
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container