// Oldham, Jeffrey D. and Collin LeMaistre // 2000Apr18 // CS3352 // Possible Classes for Financial Engine // For all of these classes except the rates and statistics classes, // we envision using unique objects per time frame. That is, each // time frame will have its own objects. // Type Declarations typedef double Money; typedef unsigned long ul; typedef double Fraction; // always in the range [0,1] typedef double Rate; // asset monthly rate of increase #include // ASSET TYPES enum asset { largeCoStocks, LTGovtBonds, ITGovtBonds, Treas, inflation }; // Enumerated constants are just fancy named integers. It is best to // use them just using their names. Photocopies from Stroustrup's C++ // book on enum's are available outside my office HAS201J. // sample use code: // asset a = ; // switch (a) { // case largeCoStocks: // work with large company stocks; // break; // case LTGovtBonds: // work with long-term govt bonds; // break; // case ITGovtBonds: // work with intermediate-term govt bonds; // break; // case Treas: // work with US Treasury bills; // break; // case inflation: // work with inflation; // break; // } // another sample use: // asset a = ; // if (a == LTGovtBonds) { do the right thing; } // TIME // Stores all dates for the current time frame. // Months are specified as 1, 2, ..., 12. class time { public: // Constructor // input <- beginning of time frame (year, month) // number of months between incrementing // asset-holding period (in months) // duration of time frame (in months) // (optional) person's age (in years) // Only specify if using age-dependent asset allocations. // If not computing taxes, the asset-holding period's value is ignored. time(const ul startYear, const ul startMonth, const ul incrementPeriod, const ul assetHoldingPeriod, const ul duration, const ul age = 0); // Return the current year and month. ul year(void) const; // returns number, e.g., 1945 ul month(void) const; // returns number, e.g., 1, 2, ..., 12 // Return the number of years since 1926. ul yearsSince1926(void) const; // Return the number of years since the time frame began. ul yearsSinceTimeFrameBegan(void) const; // Move to next month, i.e., move time forward one month. void nextMonth(void); // Check for incrementing, selling all assets, and end of the time frame. bool incrementP(void) const; // returns true if should increment // investment at the end of this month bool sellAssetsP(void) const; // returns true if should sell all assets // at the end of this month bool endOfTimeFrameP(void) const; // returns true if this is last month // of time frame // For age-dependent asset allocations only: // Call this function only inside the assetAllocation class! double currentAge(void) const; // age in years (possibly with a // fraction for months) private: // add variables here }; // HISTORICAL RATE INFORMATION // Stores historical asset return rates and return rates. // Return rates are fractions, not percentages. // E.g., a return rate of 13.4% is returned as 0.134. class rates { public: // Constructor: // input <- monthly modification amount // large company stock capital appreciation data file // large company stock income return date file // LT govt bond capital appreciation date file // LT govt bond income return date file // IT govt bond capital appreciation date file // IT govt bond income return date file // inflation CPI data file rates(const Rate monthlyModificationAmount, const string lcStkCapAppr, const string lcStkIncome, const string ltGBCapAppr, const string ltGBIncome, const string itGBCapAppr, const string itGBIncome, const string treasury, const string inflation); ); // Return the combined capital appreciation, income return, and // monthly modification amount. // This function should only be called if ignoring taxes. Rate totalReturn(const time & t, const asset a) const { // return asset's capital appreciation + asset's income return + // monthly modification amount } // Return the capital appreciation modified by a proportion of the // monthly modification amount. // This function should only be called if computing taxes. Rate capApprecReturn(const time & t, const asset a) const { // return asset's capital appreciation + its fraction of the // monthly modification amount } // Return the income return modified by a proportion of the // monthly modification amount. // This function should only be called if computing taxes. Rate incomeReturn(const time & t, const asset a) const; private: }; // ASSET ALLOCATIONS // Stores the asset allocations for each time period. // The returned asset allocations are numbers in the range [0,1]. // Types of Age-Varying Formulae enum assetFormulaChoice { none, conservative, moderate, aggressive }; class assetAllocation { public: // Specify a fixed asset allocation, i.e., asset allocation // independent of time. assetAllocation(const Fraction LCStockAllocation, const Fraction LTGovtAllocation, const Fraction ITGovtAllocation, const Fraction TreasAllocation); // Specify an asset allocation varying with time. assetAllocation(const assetFormulaChoice choice); // Return the specified asset's allocation for the current time. // For fixed allocation, the function ignores the time. // Programmers note: If using age-varying formulae, returns 0 for // ITGovtBonds, and Treas. Calling with inflation is an error. Fraction findAllocation(const time & t, const asset a) const; private: assetFormulaChoice assetFormula; // use `none' for fixed allocation // store the fixed allocations here }; // STATISTICS // Compute statistics on final investment amounts. // Ending investment values less than zero, i.e., bankruptcy, are // treated as zero. class statistics { public: statistics(const Money financialGoal); // Prints the probability of success, the average, and the standard // deviation. ~statistics(void); // Invoked at the end of each time frame, giving the ending // investment amount. void nextValue(const Money investmentAmount); private: Money financialGoal; // desired ending investment Money sumSoFar; // sum of ending investment amounts Money squareSumsSoFar; // sum of (ending investment amounts)^2 ul numberOfTimeFramesSoFar; ul numberOfSuccessesSoFar; // number of ending amounts >= desired // ending }; // INVESTMENT // Stores the current investment's value, updating each month. class investment { public: // Constructor // input <- asset allocation object (already initialized) // historical rates object (already initialized) // time object (already initialized) // initial investment value // increment amount // boolean true if increment is inflated every month // boolean true if taxes should be computed // (optional) long-term capital gains tax rate // (optional) short-term capital gains and ordinary income tax rate // The tax rates need not be specified if taxes are not being computed. investment(assetAllocation & aa, rates & r, time & t, const Money initialInvestmentValue, const Money incrementAmount, const bool inflateIncrement, const bool taxedP, const Rate capGainsTaxRate = 0, const Rate incomeTaxRate = 0); // Modify the investment's value per this month's data. // output-> true if this was the last month of the time frame bool updateInvestmentValue(void); private: };