/src/quantlib/ql/instruments/perpetualfutures.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2025 Hiroto Ogawa |
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 | | <https://www.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/instruments/perpetualfutures.hpp> |
21 | | #include <ql/time/calendars/nullcalendar.hpp> |
22 | | #include <utility> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | PerpetualFutures::PerpetualFutures( |
27 | | PerpetualFutures::PayoffType payoffType, |
28 | | PerpetualFutures::FundingType fundingType, |
29 | | Period fundingFrequency, |
30 | | Calendar cal, |
31 | 0 | DayCounter dc) : payoffType_(payoffType), fundingType_(fundingType), fundingFrequency_(fundingFrequency), |
32 | 0 | cal_(std::move(cal)), dc_(std::move(dc)) { |
33 | 0 | } Unexecuted instantiation: QuantLib::PerpetualFutures::PerpetualFutures(QuantLib::PerpetualFutures::PayoffType, QuantLib::PerpetualFutures::FundingType, QuantLib::Period, QuantLib::Calendar, QuantLib::DayCounter) Unexecuted instantiation: QuantLib::PerpetualFutures::PerpetualFutures(QuantLib::PerpetualFutures::PayoffType, QuantLib::PerpetualFutures::FundingType, QuantLib::Period, QuantLib::Calendar, QuantLib::DayCounter) |
34 | | |
35 | 0 | void PerpetualFutures::setupArguments(PricingEngine::arguments* args) const { |
36 | 0 | auto* moreArgs = dynamic_cast<PerpetualFutures::arguments*>(args); |
37 | 0 | QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); |
38 | 0 | moreArgs->payoffType = payoffType_; |
39 | 0 | moreArgs->fundingType = fundingType_; |
40 | 0 | moreArgs->fundingFrequency = fundingFrequency_; |
41 | 0 | moreArgs->cal = cal_; |
42 | 0 | moreArgs->dc = dc_; |
43 | 0 | } |
44 | | |
45 | | PerpetualFutures::arguments::arguments() |
46 | 0 | : payoffType(PerpetualFutures::PayoffType(-1)), fundingType(PerpetualFutures::FundingType(-1)), |
47 | 0 | fundingFrequency(Period(8, Hours)), cal(NullCalendar()), |
48 | 0 | dc(ActualActual(ActualActual::ISDA)) {} |
49 | | |
50 | 0 | void PerpetualFutures::arguments::validate() const { |
51 | 0 | switch (payoffType) { |
52 | 0 | case PerpetualFutures::Linear: |
53 | 0 | case PerpetualFutures::Inverse: |
54 | 0 | case PerpetualFutures::Quanto: |
55 | 0 | break; |
56 | 0 | default: |
57 | 0 | QL_FAIL("unknown payoff type"); |
58 | 0 | } |
59 | 0 | switch (fundingType) { |
60 | 0 | case PerpetualFutures::FundingWithPreviousSpot: |
61 | 0 | break; |
62 | 0 | case PerpetualFutures::FundingWithCurrentSpot: |
63 | 0 | break; |
64 | 0 | default: |
65 | 0 | QL_FAIL("unknown funding type"); |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | 0 | std::ostream& operator<<(std::ostream& out, PerpetualFutures::PayoffType type) { |
70 | 0 | switch (type) { |
71 | 0 | case PerpetualFutures::Linear: |
72 | 0 | return out << "Linear"; |
73 | 0 | case PerpetualFutures::Inverse: |
74 | 0 | return out << "Inverse"; |
75 | 0 | case PerpetualFutures::Quanto: |
76 | 0 | return out << "Quanto"; |
77 | 0 | default: |
78 | 0 | QL_FAIL("unknown PerpetualFutures::PayoffType(" << int(type) << ")"); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | 0 | std::ostream& operator<<(std::ostream& out, PerpetualFutures::FundingType type) { |
83 | 0 | switch (type) { |
84 | 0 | case PerpetualFutures::FundingWithPreviousSpot: |
85 | 0 | return out << "FundingWithPreviousSpot"; |
86 | 0 | case PerpetualFutures::FundingWithCurrentSpot: |
87 | 0 | return out << "FundingWithCurrentSpot"; |
88 | 0 | default: |
89 | | QL_FAIL("unknown PerpetualFutures::FundingType(" << int(type) << ")"); |
90 | 0 | } |
91 | 0 | } |
92 | | |
93 | | } |
94 | | |