mymoneyforecast.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mymoneyforecast.h
00003                              -------------------
00004     begin                : Wed May 30 2007
00005     copyright            : (C) 2007 by Alvaro Soliverez
00006     email                : asoliverez@gmail.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef MYMONEYFORECAST_H
00019 #define MYMONEYFORECAST_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 // ----------------------------------------------------------------------------
00026 // QT Includes
00027 
00028 #include <qmap.h>
00029 #include <qvaluelist.h>
00030 #include <qstring.h>
00031 
00032 // ----------------------------------------------------------------------------
00033 // Project Includes
00034 
00035 #include <kmymoney/mymoneyobject.h>
00036 #include <kmymoney/mymoneyaccount.h>
00037 #include <kmymoney/mymoneymoney.h>
00038 #include <kmymoney/mymoneyscheduled.h>
00039 #include <kmymoney/export.h>
00040 #include "mymoneybudget.h"
00041 
00048 class MyMoneyForecast
00049 {
00050 public:
00051   MyMoneyForecast();
00052   ~MyMoneyForecast();
00053 
00057   void doForecast();
00058 
00062   QValueList<MyMoneyAccount> accountList(void);
00063 
00069   static MyMoneyMoney calculateAccountTrend(const MyMoneyAccount& acc, int forecastDays);
00070 
00074   MyMoneyMoney forecastBalance(const MyMoneyAccount& acc, QDate forecastDate);
00075 
00081   MyMoneyMoney forecastBalance(const MyMoneyAccount& acc, int offset);
00082 
00086   bool isForecastAccount(const MyMoneyAccount& acc);
00087 
00092   int daysToMinimumBalance(const MyMoneyAccount& acc);
00093 
00099   int daysToZeroBalance(const MyMoneyAccount& acc);
00100 
00104   MyMoneyMoney accountCycleVariation(const MyMoneyAccount& acc);
00105 
00109   MyMoneyMoney accountTotalVariation(const MyMoneyAccount& acc);
00110 
00114   QValueList<QDate> accountMinimumBalanceDateList(const MyMoneyAccount& acc);
00115 
00119   QValueList<QDate> accountMaximumBalanceDateList(const MyMoneyAccount& acc);
00120 
00124   MyMoneyMoney accountAverageBalance(const MyMoneyAccount& acc);
00125 
00129   void createBudget(MyMoneyBudget& budget, QDate historyStart, QDate historyEnd, QDate budgetStart, QDate budgetEnd, const bool returnBudget);
00130 
00134   int historyDays(void) const { return (m_historyStartDate.daysTo(m_historyEndDate) + 1); }
00135 
00136   void setAccountsCycle(int accountsCycle)   { m_accountsCycle = accountsCycle; }
00137   void setForecastCycles(int forecastCycles)   { m_forecastCycles = forecastCycles; }
00138   void setForecastDays(int forecastDays)   { m_forecastDays = forecastDays; }
00139   void setBeginForecastDate(QDate beginForecastDate) { m_beginForecastDate = beginForecastDate; }
00140   void setBeginForecastDay(int beginDay)   { m_beginForecastDay = beginDay; }
00141   void setForecastMethod(int forecastMethod) { m_forecastMethod = forecastMethod; }
00142   void setHistoryStartDate(QDate historyStartDate) { m_historyStartDate = historyStartDate; }
00143   void setHistoryEndDate(QDate historyEndDate) { m_historyEndDate = historyEndDate; }
00144   void setHistoryStartDate(int daysToStartDate) { setHistoryStartDate(QDate::currentDate().addDays(-daysToStartDate)); }
00145   void setHistoryEndDate(int daysToEndDate) { setHistoryEndDate(QDate::currentDate().addDays(-daysToEndDate)); }
00146   void setForecastStartDate(QDate _startDate) { m_forecastStartDate = _startDate; }
00147   void setForecastEndDate(QDate _endDate) { m_forecastEndDate = _endDate; }
00148   void setSkipOpeningDate(bool _skip) { m_skipOpeningDate = _skip; }
00149   void setHistoryMethod(int historyMethod) { m_historyMethod = historyMethod; }
00150   void setIncludeUnusedAccounts(bool _bool) { m_includeUnusedAccounts = _bool; }
00151   void setForecastDone(bool _bool) { m_forecastDone = _bool; }
00152   void setIncludeFutureTransactions(bool _bool) { m_includeFutureTransactions = _bool; }
00153   void setIncludeScheduledTransactions(bool _bool) { m_includeScheduledTransactions = _bool; }
00154 
00155   int accountsCycle(void) const   { return m_accountsCycle; }
00156   int forecastCycles(void) const   { return m_forecastCycles; }
00157   int forecastDays(void) const { return m_forecastDays; }
00158   QDate beginForecastDate(void) const   { return m_beginForecastDate; }
00159   int beginForecastDay(void) const   { return m_beginForecastDay; }
00160   int forecastMethod(void) const   { return m_forecastMethod; }
00161   QDate historyStartDate(void) const { return m_historyStartDate; }
00162   QDate historyEndDate(void) const { return m_historyEndDate; }
00163   QDate forecastStartDate(void) const { return m_forecastStartDate; }
00164   QDate forecastEndDate(void) const { return m_forecastEndDate; }
00165   bool skipOpeningDate(void) const { return m_skipOpeningDate; }
00166   int historyMethod(void) const   { return m_historyMethod; }
00167   bool isIncludingUnusedAccounts(void) const { return m_includeUnusedAccounts; }
00168   bool isForecastDone(void) const { return m_forecastDone; }
00169   bool isIncludingFutureTransactions(void) const { return m_includeFutureTransactions; }
00170   bool isIncludingScheduledTransactions(void) const { return m_includeScheduledTransactions; }
00171 
00182   static void calculateAutoLoan(const MyMoneySchedule& schedule, MyMoneyTransaction& transaction, const QMap<QString, MyMoneyMoney>& balances);
00183 
00184 private:
00185 
00186   enum EForecastMethod {eScheduled = 0, eHistoric = 1 };
00187 
00191   typedef QMap<QDate, MyMoneyMoney> dailyBalances;
00192 
00196   typedef QMap<int, MyMoneyMoney> trendBalances;
00197 
00201   static QValueList<MyMoneyAccount> forecastAccountList(void);
00202 
00206   QValueList<MyMoneyAccount> budgetAccountList(void);
00207 
00211   void calculateHistoricDailyBalances(void);
00212 
00216   void calculateHistoricMonthlyBalances();
00217 
00221   void calculateScheduledMonthlyBalances();
00222 
00226   void doFutureScheduledForecast(void);
00227 
00231   void addFutureTransactions(void);
00232 
00236   void addScheduledTransactions (void);
00237 
00241   void calculateScheduledDailyBalances(void);
00242 
00246   void setStartingBalance(const MyMoneyAccount& acc);
00247 
00254   MyMoneyMoney accountMovingAverage(const MyMoneyAccount& acc, const int trendDay, const int forecastTerms);
00255 
00259   MyMoneyMoney accountWeightedMovingAverage(const MyMoneyAccount& acc, const int trendDay, const int totalWeight);
00260 
00264   MyMoneyMoney accountLinearRegression(const MyMoneyAccount &acc, const int trendDay, const int totalWeight, const MyMoneyMoney meanTerms);
00265 
00269   void calculateAccountTrendList(void);
00270 
00274   void setForecastAccountList(void);
00275 
00279   void setBudgetAccountList(void);
00280 
00284   void pastTransactions(void);
00285 
00297   int calculateBeginForecastDay();
00298 
00303   void purgeForecastAccountsList(QMap<QString, dailyBalances>& accountList);
00304 
00308   QMap<QString, dailyBalances> m_accountList;
00309 
00313   QMap<QString, dailyBalances> m_accountListPast;
00314 
00318   QMap<QString, trendBalances> m_accountTrendList;
00319 
00323   QMap<QString, QString> m_nameIdx;
00324 
00328   int m_accountsCycle;
00329 
00333   int m_forecastCycles;
00334 
00338   int m_forecastDays;
00339 
00343   QDate m_beginForecastDate;
00344 
00348   int m_beginForecastDay;
00349 
00353   int m_forecastMethod;
00354 
00358   int m_historyMethod;
00359 
00363   QDate m_historyStartDate;
00364 
00368   QDate m_historyEndDate;
00369 
00373   QDate m_forecastStartDate;
00374 
00378   QDate m_forecastEndDate;
00379 
00383   bool m_skipOpeningDate;
00384 
00388   bool m_includeUnusedAccounts;
00389 
00393   bool m_forecastDone;
00394 
00398   bool m_includeFutureTransactions;
00399 
00403   bool m_includeScheduledTransactions;
00404 
00405 };
00406 
00407 #endif // MYMONEYFORECAST_H
00408 

Generated on Wed Jan 26 13:03:18 2011 for KMyMoney by  doxygen 1.5.6