#ifndef assetAllocation_H #define assetAllocation_H 1 // Oldham, Jeffrey D. // 2000Apr // CS3352 #include // has max() and min() #include "time.h" #include "types.h" // ASSET ALLOCATIONS // Stores the asset allocations for each time period. // The returned asset allocations are numbers in the range [0,1]. class assetAllocation { public: // Specify an asset allocation. The fixed asset allocations are // used only if the assetFormulaChoice parameter is "none". assetAllocation(const assetFormulaChoice &choice, const Fraction &LCStockAllocation, const Fraction <GovtAllocation, const Fraction &ITGovtAllocation, const Fraction &TreasAllocation) { if ((m_assetFormula = choice) == none) { m_LCStck = LCStockAllocation; m_LTGov = LTGovtAllocation; m_ITGov = ITGovtAllocation; m_Treas = TreasAllocation; } return; } // 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 { if (m_assetFormula == none) { // fixed allocation switch (a) { // asset allocation type case largeCoStocks: return m_LCStck; break; case LTGovtBonds: return m_LTGov; break; case ITGovtBonds: return m_ITGov; break; case Treas: return m_Treas; break; default: // some invalid value throw "invalid allocation type"; break; } } else { switch (a) { // allocation type case largeCoStocks: switch (m_assetFormula) { // asset allocation type case conservative: return min(125-t.currentAge(), (double) 100) / 100.0; break; case moderate: return min(135-t.currentAge(), (double) 100) / 100.0; break; case aggressive: return min(145-t.currentAge(), (double) 100) / 100.0; break; default: // some invalid value throw "invalid allocation type"; break; } break; case LTGovtBonds: return 1.00 - findAllocation(t, largeCoStocks); break; case ITGovtBonds: case Treas: return 0; break; default: // some invalid value throw "invalid allocation type"; break; } } } private: assetFormulaChoice m_assetFormula; // use `none' for fixed allocation Fraction m_LCStck; Fraction m_LTGov; Fraction m_ITGov; Fraction m_Treas; }; #endif