00001 /*************************************************************************** 00002 querytable.h 00003 ------------------- 00004 begin : Fri Jul 23 2004 00005 copyright : (C) 2004-2005 by Ace Jones 00006 (C) 2007 Sascha Pfau 00007 email : acejones@users.sourceforge.net 00008 MrPeacock@gmail.com 00009 ***************************************************************************/ 00010 00011 /**************************************************************************** 00012 Contains code from the func_xirr and related methods of financial.cpp 00013 - KOffice 1.6 by Sascha Pfau. Sascha agreed to relicense those methods under 00014 GPLv2 or later. 00015 *****************************************************************************/ 00016 00017 /*************************************************************************** 00018 * * 00019 * This program is free software; you can redistribute it and/or modify * 00020 * it under the terms of the GNU General Public License as published by * 00021 * the Free Software Foundation; either version 2 of the License, or * 00022 * (at your option) any later version. * 00023 * * 00024 ***************************************************************************/ 00025 00026 #ifndef QUERYTABLE_H 00027 #define QUERYTABLE_H 00028 00029 // ---------------------------------------------------------------------------- 00030 // QT Includes 00031 00032 #include <qstringlist.h> 00033 00034 // ---------------------------------------------------------------------------- 00035 // KDE Includes 00036 00037 // ---------------------------------------------------------------------------- 00038 // Project Includes 00039 00040 #include "../mymoney/mymoneyreport.h" 00041 #include "listtable.h" 00042 00043 namespace reports { 00044 00045 class ReportAccount; 00046 00060 class QueryTable : public ListTable 00061 { 00062 public: 00063 QueryTable(const MyMoneyReport&); 00064 void init(void); 00065 00066 protected: 00067 void constructAccountTable(void); 00068 void constructTransactionTable(void); 00069 void constructPerformanceRow( const ReportAccount& account, TableRow& result ) const; 00070 void constructSplitsTable(void); 00071 00072 }; 00073 00074 // 00075 // Cash Flow analysis tools for investment reports 00076 // 00077 00078 class CashFlowListItem 00079 { 00080 public: 00081 CashFlowListItem(void) {} 00082 CashFlowListItem( const QDate& _date, const MyMoneyMoney& _value ): m_date(_date), m_value(_value) {} 00083 bool operator<( const CashFlowListItem _second ) const { return m_date < _second.m_date; } 00084 bool operator<=( const CashFlowListItem _second ) const { return m_date <= _second.m_date; } 00085 bool operator>( const CashFlowListItem _second ) const { return m_date > _second.m_date; } 00086 const QDate& date( void ) const { return m_date; } 00087 const MyMoneyMoney& value( void ) const { return m_value; } 00088 MyMoneyMoney NPV( double _rate ) const; 00089 00090 static void setToday( const QDate& _today ) { m_sToday = _today; } 00091 const QDate& today( void ) const { return m_sToday; } 00092 00093 private: 00094 QDate m_date; 00095 MyMoneyMoney m_value; 00096 00097 static QDate m_sToday; 00098 }; 00099 00100 class CashFlowList: public QValueList<CashFlowListItem> 00101 { 00102 public: 00103 CashFlowList(void) {} 00104 MyMoneyMoney NPV(double rate) const; 00105 double IRR(void) const; 00106 MyMoneyMoney total(void) const; 00107 void dumpDebug(void) const; 00108 00116 double calculateXIRR ( void ) const; 00117 00118 protected: 00119 CashFlowListItem mostRecent(void) const; 00120 00121 private: 00128 double xirrResult ( double& rate ) const; 00129 00137 double xirrResultDerive ( double& rate ) const; 00138 }; 00139 00140 } 00141 00142 #endif // QUERYREPORT_H