Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/views/reports/core/cashflowlist.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2007 Sascha Pfau <MrPeacock@gmail.com> | ||||
3 | * Copyright 2018 Ralf Habacker <ralf.habacker@freenet.de> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | | ||||
19 | /* | ||||
20 | * This file contains code from the func_xirr and related methods of | ||||
21 | * financial.cpp from KOffice by Sascha Pfau. Sascha agreed to relicense | ||||
22 | * those methods under GPLv2 or later. | ||||
23 | */ | ||||
24 | | ||||
25 | #ifndef CASHFLOWLIST_H | ||||
26 | #define CASHFLOWLIST_H | ||||
27 | | ||||
28 | #include "mymoneymoney.h" | ||||
29 | | ||||
30 | #include <QDate> | ||||
31 | #include <QList> | ||||
32 | | ||||
33 | class CashFlowListItem | ||||
34 | { | ||||
35 | public: | ||||
36 | CashFlowListItem() {} | ||||
37 | CashFlowListItem(const QDate& _date, const MyMoneyMoney& _value): m_date(_date), m_value(_value) {} | ||||
38 | bool operator<(const CashFlowListItem& _second) const { | ||||
39 | return m_date < _second.m_date; | ||||
40 | } | ||||
41 | bool operator<=(const CashFlowListItem& _second) const { | ||||
42 | return m_date <= _second.m_date; | ||||
43 | } | ||||
44 | bool operator>(const CashFlowListItem& _second) const { | ||||
45 | return m_date > _second.m_date; | ||||
46 | } | ||||
47 | const QDate& date() const { | ||||
48 | return m_date; | ||||
49 | } | ||||
50 | const MyMoneyMoney& value() const { | ||||
51 | return m_value; | ||||
52 | } | ||||
53 | | ||||
54 | private: | ||||
55 | QDate m_date; | ||||
56 | MyMoneyMoney m_value; | ||||
57 | }; | ||||
58 | | ||||
59 | /** | ||||
60 | * Cash flow analysis tools for investment reports | ||||
61 | */ | ||||
62 | class CashFlowList: public QList<CashFlowListItem> | ||||
63 | { | ||||
64 | public: | ||||
65 | CashFlowList() {} | ||||
66 | double XIRR(double rate = 0.1) const; | ||||
67 | MyMoneyMoney total() const; | ||||
68 | void dumpDebug() const; | ||||
69 | | ||||
70 | private: | ||||
71 | double xirrResult(double rate) const; | ||||
72 | double xirrResultDerive(double rate) const; | ||||
73 | }; | ||||
74 | | ||||
75 | #endif // CASHFLOWLIST_H |