// This file (code1.txt) includes ss.cpp and ss.h (cut into 2 files as shown below) // The ChumpPolitics Social Security Simulator // Article at: http://auxchumppolitics.blogspot.com/2007/12/social-security-part-ii.html // //================================================================================== //========================= ss.h =========== cut here ============================== //================================================================================== // THIS FILE IS MACHINE GENERATED. DO NOT EDIT // migrationValue: // migrationValue vs. age and class, 16695 = (985.0e3/59.0) from population division working paper number 38, page 28, US Census Bureau: // salaryMultiplier: // salaryMultiplier vs. age and class, derived from: Consumer Expenditure Survey, 2001, US Dept of Labor, Bureau of Labor Statistics, Apr 2003, Report 966. And also Statistical Abstract of the United States, 2003, page 445, U.S. Census Bureau: // disabilityMultiplier: // disabilityMultiplier vs. age and class, From OACT/TR04: // survivorMultiplier: // survivorMultiplier vs. age and class, From OACT/TR04: // retirementMultiplier: // (initial legacy values) retirementMultiplier vs. age and class, From OACT/TR04: // numberOfPeople: // numberOfPeople vs. age; From legacy model: US Census Bureau, Statistical Abstract of the United States: // numberOfEarners: // numberOfEarners vs. age; Derived from OACT/TR04, currently not used.: // birthRate: // birthRate vs. age; From legacy model: US Census Bureau, and Social Security: // mortalityRate: // mortalityRate vs. age; From legacy model: US Census Bureau, and Social Security: // currentPopulation: // current population vs. age and class (2000) http://www.census.gov/ipc/www/usinterimproj/usproj2000-2050.csv: const int NUMBEROFAGES = (100); typedef struct _PopulationData { int age; double currentPopulation; double mortalityRate; double birthRate; double numberOfPeople; double migrationValue; double salaryMultiplier; double numberOfEarners; double disabilityMultiplier; double survivorMultiplier; double retirementMultiplier; } PopulationData ; PopulationData peopleData[NUMBEROFAGES] = { {0 , 3.86394e+006 , 0.00451 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {1 , 3.82085e+006 , 0.00062 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {2 , 3.80166e+006 , 0.00046 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {3 , 3.82567e+006 , 0.00035 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {4 , 3.90605e+006 , 0.00029 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {5 , 3.95881e+006 , 0.00025 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {6 , 4.00967e+006 , 0.00023 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {7 , 4.0972e+006 , 0.00021 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {8 , 4.16798e+006 , 0.00018 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {9 , 4.24944e+006 , 0.00016 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {10 , 4.27702e+006 , 0.00014 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {11 , 4.15916e+006 , 0.00014 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {12 , 4.09103e+006 , 0.00019 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {13 , 4.03284e+006 , 0.0003 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {14 , 4.04837e+006 , 0.00044 , 0 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {15 , 4.03438e+006 , 0.00061 , 0.0205 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {16 , 3.99324e+006 , 0.00076 , 0.0381 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {17 , 4.03616e+006 , 0.00088 , 0.0602 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {18 , 4.05877e+006 , 0.00095 , 0.083 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {19 , 4.11666e+006 , 0.00098 , 0.0997 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {20 , 4.07599e+006 , 0.001 , 0.1097 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {21 , 3.89804e+006 , 0.00103 , 0.12 , 1 , 16695 , 0 , 1 , 0 , 0 , 0 }, {22 , 3.7845e+006 , 0.00106 , 0.112 , 2.1 , 16695 , 0.59 , 1.2 , 0.03 , 0.08 , 0 }, {23 , 3.70097e+006 , 0.00108 , 0.1104 , 2.2 , 16695 , 0.59 , 1.2 , 0.03 , 0.08 , 0 }, {24 , 3.65653e+006 , 0.00111 , 0.1101 , 2.2 , 16695 , 0.59 , 1.2 , 0.03 , 0.08 , 0 }, {25 , 3.72699e+006 , 0.00113 , 0.1105 , 2.3 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {26 , 3.65886e+006 , 0.00116 , 0.1116 , 2.3 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {27 , 3.75521e+006 , 0.00119 , 0.1115 , 2.3 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {28 , 3.9432e+006 , 0.00124 , 0.1099 , 2.3 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {29 , 4.18424e+006 , 0.00131 , 0.1061 , 2.2 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {30 , 4.28535e+006 , 0.00138 , 0.0999 , 2.1 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {31 , 4.08577e+006 , 0.00145 , 0.0909 , 2 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {32 , 4.00422e+006 , 0.0015 , 0.0806 , 2 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {33 , 4.02364e+006 , 0.00155 , 0.07 , 2 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {34 , 4.15209e+006 , 0.00161 , 0.0602 , 2 , 16695 , 1.32 , 1.5 , 0.15 , 0.13 , 0 }, {35 , 4.43636e+006 , 0.00169 , 0.0506 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {36 , 4.51605e+006 , 0.00177 , 0.0411 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {37 , 4.51893e+006 , 0.00188 , 0.0324 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {38 , 4.54764e+006 , 0.002 , 0.0249 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {39 , 4.59752e+006 , 0.00214 , 0.0186 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {40 , 4.68792e+006 , 0.00229 , 0.0133 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {41 , 4.52834e+006 , 0.00247 , 0.0088 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {42 , 4.52875e+006 , 0.00261 , 0.0056 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {43 , 4.44357e+006 , 0.00277 , 0.0034 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {44 , 4.33396e+006 , 0.00294 , 0.0019 , 1.9 , 16695 , 1.66 , 1.7 , 0.45 , 0.38 , 0 }, {45 , 4.33368e+006 , 0.00314 , 0.0009 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {46 , 4.14955e+006 , 0.00336 , 0.0003 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {47 , 4.03646e+006 , 0.00363 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {48 , 3.91784e+006 , 0.00394 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {49 , 3.78889e+006 , 0.00429 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {50 , 3.79486e+006 , 0.00468 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {51 , 3.66214e+006 , 0.00511 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {52 , 3.68249e+006 , 0.0056 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {53 , 3.65037e+006 , 0.00615 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {54 , 2.99982e+006 , 0.00676 , 0 , 1.8 , 16695 , 1.88 , 1.9 , 0.9 , 0.88 , 0 }, {55 , 2.83988e+006 , 0.00743 , 0 , 1.7 , 16695 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {56 , 2.83795e+006 , 0.00815 , 0 , 1.7 , 16695 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {57 , 2.85412e+006 , 0.00893 , 0 , 1.7 , 16695 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {58 , 2.61384e+006 , 0.00979 , 0 , 1.7 , 16695 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {59 , 2.41324e+006 , 0.01071 , 0 , 1.7 , 16695 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {60 , 2.33027e+006 , 0.01171 , 0 , 1.7 , 0 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {61 , 2.24123e+006 , 0.01277 , 0 , 1.7 , 0 , 1.16 , 1.4 , 1.8 , 1.5 , 0 }, {62 , 2.17881e+006 , 0.01391 , 0 , 1.7 , 0 , 1.16 , 1.4 , 1.8 , 1.5 , 1.1 }, {63 , 2.07681e+006 , 0.01512 , 0 , 1.7 , 0 , 1.16 , 1.4 , 1.8 , 1.5 , 1.09 }, {64 , 2.0376e+006 , 0.01642 , 0 , 1.7 , 0 , 1.16 , 1.4 , 1.8 , 1.5 , 1.08 }, {65 , 2.02591e+006 , 0.01781 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.07 }, {66 , 1.89448e+006 , 0.018 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {67 , 1.88008e+006 , 0.019 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {68 , 1.86443e+006 , 0.02 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {69 , 1.86906e+006 , 0.021 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {70 , 1.86697e+006 , 0.023 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {71 , 1.79885e+006 , 0.025 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {72 , 1.77925e+006 , 0.028 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {73 , 1.72908e+006 , 0.03 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {74 , 1.67579e+006 , 0.034 , 0 , 1.6 , 0 , 0.3 , 1 , 2.2 , 2.1 , 1.06 }, {75 , 1.64383e+006 , 0.037 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {76 , 1.5647e+006 , 0.04 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {77 , 1.46846e+006 , 0.045 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {78 , 1.4224e+006 , 0.05 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {79 , 1.32599e+006 , 0.065 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {80 , 1.21596e+006 , 0.07 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {81 , 1.0874e+006 , 0.075 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {82 , 986690 , 0.08 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {83 , 890070 , 0.085 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {84 , 804548 , 0.09 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {85 , 730078 , 0.095 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {86 , 640051 , 0.1 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {87 , 559013 , 0.11 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {88 , 471387 , 0.12 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {89 , 402272 , 0.14 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {90 , 331929 , 0.16 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {91 , 269034 , 0.17 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {92 , 219123 , 0.18 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {93 , 171448 , 0.2 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {94 , 132250 , 0.21 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {95 , 99429 , 0.22 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {96 , 73497 , 0.24 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {97 , 53400 , 0.26 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {98 , 36770 , 0.3 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, {99 , 77619 , 1 , 0 , 1.6 , 0 , 0.08 , 1 , 1.8 , 1.9 , 0.94 }, }; //================================================================================== //========================= ss.cpp========== cut here ============================== //================================================================================== /******************************************************************* ss.cpp -- version 1.0 -- Jan 27, 2005 ver1.0 1/27/05 initial 2.0 2/18/05 revised benefit calc. for multiple caps., added logNormal dist. 3.0 3/04/05 fixed payroll for lifting cap., fixed logNormal dist. 4.0 3/15/05 better retirementAge adjust, added PrivateAccounts 4.1 3/16/05 improved bend points for private accounts ********************************************************************/ /* Copyright (C) 2005-2007 ChumpPolitics * * Disclaimer: This experimental program is provided for informational * and educational purposes only. * * Stochastic simulation of the Social Security trust fund * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include "ss.h" // simulation currently set for typical case (Exhaustion in 2042) // Simulation control variables: // set MONTECARLOSIMULATION to 0, for testing typical case (ie exhaustion at year 2042). otherwise Set to 1 #define MONTECARLOSIMULATION (0) const int MAXIMUMTRIES = (1); // set to 10000 or more to create a Probability distribution simulation (and make sure MONTECARLOSIMULATION = 1 !!), otherwise set to 1 to simulate just one case // set ENABLESEED to 1 to simulate a particular run derived from a Probability Distribution simulation (note: MAXIMUMTRIES to 1 and MONTECARLOSIMULATION to 1) #define ENABLESEED (0) const int SIMULATIONSEEDVALUE = (1348032766); // set this value to simulate a particular run derived from a Probability Distribution simulation #define PRIVATIZATIONFLAG (0) // conclusion: You can't get there from here. transition costs are a killer /* For testing SS "fixes" */ const double PAYROLLCAPMULTIPLIER = (1.0); // (1.0 = current SS, ie exhaustion at year 2042) const double EXPENSESCAPMULTIPLIER = (1.0); // optional, for testing separate caps const int BEGINFIXDATE = (1999); // old const int ENDFIXDATE = (2198); // old const double PAYROLLRATEADJUSTMENT = (0.0); // old 0.009 //--------------------------------------------------------------------------------------------------------------------------- // type of simulation | MONTECARLOSIMULATION | MAXIMUMTRIES | ENABLESEED | SIMULATIONSEEDVALUE | PAYROLLCAPMULTIPLIER //---------------------------+------------------------+--------------+------------+---------------------+-------------------- // typical case | 0 | 1 | 0 | not used | 1.0 // probability distribution | 1 | 1000+ | 0 | not used | 1.0 // specific case | 1 | 1 | 1 | set specific value | 1.0 note: set SIMULATIONSEEDVALUE to a particular value, derived from a Probability Distribution Simulation (see above) // typical case, fixed | 0 | 1 | 0 | not used | ? // 90% cases, fixed | 1 | 1000+ | 0 | not used | ? //--------------------------------------------------------------------------------------------------------------------------- const int STARTINGYEAR = (2000); const int STOPPINGYEAR = (2085); // 2085 const int NUMBEROFBUCKETS = (STOPPINGYEAR - STARTINGYEAR + 1); const int CURRENTYEAR = (2005); // the household Class consists of 100 age groups times 7 different classes (poor to superRich) = 700 different population groupings (cohorts) const int NUMBEROFCLASSES = (7); const int ADULTAGE = (22); const int BENEFITSAGE = (62); const int INDEXINGAGE = (60); const int EMPLOYMENTAGE = (25+2); const int LASTAGE = (99); const int RETIREMENTAGE = (65); /* values as of the end of 1999 */ const double STARTTRUSTFUND = (896.1e9); // OACT/TR04: table IV.A3 const double STARTCPI = (168.3); const double STARTGDP = (9519.5); const double STARTOVERHEAD = (3.8e9); // OACT/TR04 II: table IV.A3 const double EARNINGSGROWTHRATE = (0.039); // OACT/TR04 II: Table V.B1 (also verified with: wages+ otherLaborIncome + proprietors income, from stat abs us, 2003 p.445 personal income and its distribution: mean: 0.0405645) const double INITIALRETIREMENTADJUSTMENT = (1/1.039); // For init retirement est. 1/(1+earningsgrowthrate) const double LOGEARNINGSGROWTHRATE = (log(EARNINGSGROWTHRATE)); // not used const double ESTIMATEDINTERESTRATE = (0.058); // OACT/TR04 II: table V.B1 0.058 const double LOGESTIMATEDINTERESTRATE = (log(ESTIMATEDINTERESTRATE)); const double STARTBEND1 = (531.0); // OACT/TR04 year 2000 const double STARTBEND2 = (3202.0); // OACT/TR04 year 2000 const double STARTBEND3 = (1.0e99); // SS Fix test const double STARTNATIONALAVERAGEWAGEINDEX = (32154.82); // OACT/COLA Year 2000 const double STARTRAILROADEXPENSES = (3.7e9); // OACT/TR04 II: table IV.A3 const double STARTCOSTOFLIVINGADJUSTMENT = (0.028); // OACT/TR04 II: table V.B1 const double LOGSTARTCOSTOFLIVINGADJUSTMENT = (log(STARTCOSTOFLIVINGADJUSTMENT)); // not used const double STARTPAYROLLTAXRATE = (0.062); // OACT/TR04 const double STARTBENEFITSTAXRATE = (0.0425); // 0.03 empirically derived const double STARTGDPRATE = (0.071); // avg (1950-2002) const double ESTIMATEDBENEFITSTAXRATEGROWTH = (0.01); // 0.005 0.0125 0.020 empirically derived const double ESTIMATEDMORTALITYRATEDECREASE = (0.007); // 0.007 From OACT/TR04 p.73 -- population distribution: 1990-2080: 5yr_mean: -0.0344028 5yr_variance: 3.45096e-005 5yr_sd: 0.00587449 (min:-0.041894 max:-0.0186296) 1 + mean' = (1 + mean)**(1/5) mean' = .00698, newMortalityRate = oldMortalityRate * (1 + mean') per year ... with sd/5 adjustments (also see: Table V.A1.--Principal Demographic Assumptions, Calendar Years 1940-2080) /* For stochastic model: standard deviation values */ const double EARNINGSGROWTHSTANDARDDEVIATION = (0.026); // 0.026 from: wages+ otherLaborIncome + proprietors income, from stat abs us, 2003 p.445 personal income and its distribution: Predictor: mean: 0.0405645 variance: 0.000672978 sd: 0.0259418 (min:0.0193954 max:0.0770984) const double LOGEARNINGSGROWTHSTANDARDDEVIATION = (log(1.0 + (EARNINGSGROWTHSTANDARDDEVIATION / EARNINGSGROWTHRATE))); const double MORTALITYRATESTANDARDDEVIATION = (0.00587449 / 5.0); // 0.00587449/5.0 see ESTIMATEDMORTALITYRATEDECREASE above const double COSTOFLIVINGSTANDARDDEVIATION = (0.0302); // (old:1983-2004: 0.0103) from OACT/COLA oct,19,2004 COLA data from 1975-2004, Predictor: simple mean: 4.50333 variance: 9.14966 sd: 3.02484 (min:1.3 max:14.3) const double LOGCOSTOFLIVINGSTANDARDDEVIATION = (log(1.0 + (COSTOFLIVINGSTANDARDDEVIATION / STARTCOSTOFLIVINGADJUSTMENT))); const double LOGINTERESTRATESTANDARDDEVIATION = (log(1.0 + (0.0086 / ESTIMATEDINTERESTRATE))); // 0.022 0.0086 OACT/TR04 II table V.B2 (interest-rate) 1993-2008, mean: 5.6875 variance: 0.739844 sd: 0.860142 (min:4.1 max:7.1) const char *className[NUMBEROFCLASSES] = { "SuperRich", "Rich", "UpperClass", "UpperMiddleClass", "MiddleClass", "LowerMiddleClass", "Poor", }; // "weighting constants", the distribution of population, salary, benefits per each economic class (superRich to poor) const double classPercentages[NUMBEROFCLASSES] = { 0.01, 0.02, 0.07, 0.2, 0.2, 0.24, 0.26 }; // from Recent TRends in Wealth Ownership, by EN Wolff, Working Paper #300, Jerome Levy Economics Institute, Apr 2000 (class based on Net Worth) also see: www.inequality.org const double classSalary[NUMBEROFCLASSES] = { 3.1, 0.9, 0.70, 0.60, 0.42, 0.22, 0.10 }; // derived from: Consumer Expenditure Survey, 2001, US Dept of Labor, Bureau of Labor Statistics, Apr 2003, Report 966. And also Statistical Abstract of the United States, 2003, page 445, U.S. Census Bureau // not used, calculate on fly: const double classDisability[NUMBEROFCLASSES] = { 0.02, 0.02, 0.04, 0.2, 0.4, 2.6, 3.8 }; // From OACT/TR04 const double classDisability[NUMBEROFCLASSES] = { 0.02, 0.02, 0.04, 0.5, 1.0, 2.6, 3.8 }; // From OACT/TR04 const double classSurvivor[NUMBEROFCLASSES] = { 1.6, 1.6, 1.6, 1.55, 1.5, 1.4, 0.5 }; // From OACT/TR04 const double classRetirement[NUMBEROFCLASSES] = { 1.6, 1.6, 1.6, 1.55, 1.5, 1.4, 0.5 }; // From OACT/TR04 /* --------------------- miscellaneous functions ------------------------- */ #define IA 16807 #define IM 2147483647 #define AM (1.0/IM) #define IQ 127773 #define IR 2836 int gbl_frand_val = 0; /* from Park and Miller */ double RandomNumber() { int k; double ans; k = gbl_frand_val / IQ; gbl_frand_val = IA * (gbl_frand_val - k * IQ) - IR * k; if (gbl_frand_val < 0) gbl_frand_val += IM; ans = AM * gbl_frand_val; return(ans); } void InitializeRandom() { time_t t1; while(gbl_frand_val == 0){ t1 = time(&t1); gbl_frand_val = -((int )t1); // gbl_frand_val = 0xdeadface; } RandomNumber(); } int ReadSeed () { return(gbl_frand_val) ; } void SetSeed (int value) { gbl_frand_val = value; } /* from Allen-Tildesley [f.24] */ // Returns standardNormal random variable: NormalVariable = (standardNormalVariable * standardDeviation) + mean double GaussianRandom() { int i; double sum,r,r2,tmp; sum = 0.0; for (i=0; i < 12; i++) sum += RandomNumber(); r = (sum - 6.0) / 4.0; r2 = r * r ; tmp = ((((0.029899776 * r2 + 0.008355968) * r2 + 0.076542912) * r2 + 0.252408784 ) * r2 + 3.949846138 ) * r; return(tmp); } // used for model verification typedef struct _tab4b1{ int year ; double incomeRate ; double costRate ; double workerRatio; // table 4.b2 double populationWorkers; // table 4.b2 double population65; // table 4.b2 double incomeExcludingInterest; // table VI.F9,F10 p.181,183 double cost; // table VI.F9,F10 p.181,183 double trustFund; // table VI.F9,F10 p.181,183 } TAB4B1 ; TAB4B1 table4b1[] = { {1999,12.71,10.51,3.4,151.3e6,37.9e6,471.2e9, 392.9e9, 896.1e9}, {2000,12.69,10.4, 3.4,153.7e6,38.6e6,504.8e9, 415.1e9, 1049.4e9}, {2001,12.71,10.56,3.4,153.7e6,38.9e6,529.1e9, 438.9e9, 1212.5e9}, {2002,12.74,10.91,3.3,153.8e6,39.1e6,546.3e9, 461.7e9, 1378.0e9}, {2003,12.71,11.04,3.3,154.3e6,39.3e6,546.9e9, 479.1e9, 1530.8e9}, {2004,12.71,11.07,3.3,154.3e6,39.3e6,564.7e9, 500.3e9, 1684.1e9}, {2005,12.73,10.87,3.3,159.0e6,39.9e6,605.2e9, 517.6e9, 1867.3e9}, {2006,12.73,10.77,3.3,159.0e6,39.9e6,634.5e9, 538.3e9, 2067.5e9}, {2007,12.75,10.75,3.3,159.0e6,39.9e6, 667.4e9, 563.4e9, 2286.6e9}, {2008,12.79,10.8 ,3.3,159.0e6,39.9e6, 701.9e9, 594.0e9, 2523.1e9}, {2009,12.78,10.95,3.3,159.0e6,39.9e6, 735.3e9, 631.6e9, 2769.7e9}, {2010,12.8,11.08 ,3.2,167.7e6,43.2e6, 771.9e9, 670.0e9, 3029.6e9}, {2011,12.85,11.25,3.1,167.7e6,43.2e6, 811.8e9, 711.9e9, 3303.3e9}, {2012,12.88,11.5, 3.1,167.7e6,43.2e6, 850.6e9, 760.3e9, 3583.5e9}, {2013,12.91,11.76,3.0,167.7e6,43.2e6, 889.0e9, 811.6e9, 3867.1e9}, {2015,12.95,12.3 ,2.9,173.0e6,49.5e6, 973.1e9, 926.8e9, 4442.1e9}, {2020,13.04,13.93,2.6,177.1e6,57.3e6, 1213.9e9, 1299.4e9, 5775.8e9}, {2025,13.13,15.56,2.3,179.5e6,64.8e6, 1501.1e9, 1782.2e9, 6574.5e9}, {2030,13.21,16.83,2.2,181.9e6,71.5e6, 1852.1e9, 2364.0e9, 6370.0e9}, {2035,13.26,17.56,2.1,184.5e6,76.0e6, 2285.3e9, 3032.3e9, 4735.8e9}, {2040,13.28,17.76,2.0,187.5e6,78.4e6, 2817.9e9, 3777.7e9, 479.6e9}, {2045,13.29,17.82,2.0,190.4e6,79.9e6, 3470.0e9, 4663.0e9, 0.0e9}, {2050,13.29,17.9, 2.0,192.9e6,81.5e6, 4261.0e9, 5749.0e9, 0.0e9}, {2055,13.31,18.12,2.0,195.3e6,83.7e6, 5228.0e9, 7133.0e9, 0.0e9}, {2060,13.33,18.39,2.0,197.5e6,86.2e6, 6411.0e9, 8866.0e9, 0.0e9}, {2065,13.35,18.68,1.9,199.7e6,88.8e6, 7861.0e9, 11027.0e9, 0.0e9}, {2070,13.36,18.93,1.9,202.0e6,91.2e6, 9642.0e9, 13689.0e9, 0.0e9}, {2075,13.39,19.14,1.9,204.2e6,93.4e6, 11819.0e9, 16960.0e9, 0.0e9}, {2080,13.39,19.14,1.9,204.2e6,93.4e6, 14478.0e9, 21004.0e9, 0.0e9}, {9999,13.39,19.14,1.9,204.2e6,93.4e6, 14478.0e9, 21004.0e9, 0.0e9} }; /* --------------------- end miscellaneous functions ------------------------- */ class Government { public: // accessible by all Government(){} int ReadAge(){return(globalRetirementAge) ;} void ReadGovernment(double &trust1,double &taxes1,double &totalBenefits1, double &payrollBaseRate1,double &expensesBaseRate1, double &traditionalBaseRate1, double &taxablePayroll1) { trust1 = socialSecurityTrust ; taxes1 = taxes ; totalBenefits1 = totalBenefits; payrollBaseRate1 = payrollBaseRate ; expensesBaseRate1 = expensesBaseRate ; traditionalBaseRate1 = traditionalBaseRate; taxablePayroll1 = taxablePayroll; #if 0 // stuff to print, as needed // printf("(bene: ret:%g (%g), sur:%g (%g), dis:%g (%g))\n", retirementBenefits, retirementBenefits / totalBenefits,survivorBenefits,survivorBenefits / totalBenefits,disabilityBenefits,disabilityBenefits / totalBenefits); // printf("income/payroll:%g costs/payroll:%g\n",totalIncome / taxablePayroll, totalExpenses / taxablePayroll); // printf("incomeRate:%g\n",100.0 * totalIncome / taxablePayroll); // printf("costRate:%g\n", 100.0 * totalExpenses / taxablePayroll); // printf("yearlyInterest:%g, taxablePayroll:%g\n",yearlyInterest,taxablePayroll); // printf("nationalAverageWageIndex:%g\n",nationalAverageWageIndex); // printf("bend1:%g\n",bend1); // printf("bend2:%g\n",bend2); printf("incomeLessInterest:%g\n",taxes + totalTaxOnBenefits); printf("interestIncome:%g\n",yearlyInterest); printf("totalIncome:%g\n",totalIncome + yearlyInterest); printf("retirementBenefits:%g\n",retirementBenefits); printf("survivorBenefits:%g\n",survivorBenefits ); printf("disabilityBenefits:%g\n",disabilityBenefits); printf("disabilityRatio:%g (test:%g)\n",(survivorBenefits + disabilityBenefits) / totalBenefits, (retirementBenefits + survivorBenefits + disabilityBenefits)); printf("cost:%g\n",totalExpenses); #endif if (bend2 > expensesBaseRate) { // for debugging fprintf(stderr,"bend2:%g expensesBaseRate:%g\n",bend2,expensesBaseRate); exit(1); } /* if */ } void InitializeGovernment(int year) { globalRetirementAge = (RETIREMENTAGE); socialSecurityTrust = STARTTRUSTFUND ; overhead = STARTOVERHEAD; railroadExpenses = STARTRAILROADEXPENSES; costOfLivingAdjustment = 0.0; bend1 = STARTBEND1 ; bend2 = STARTBEND2; bend3 = STARTBEND3; nationalAverageWageIndex = STARTNATIONALAVERAGEWAGEINDEX; gdp = STARTGDP; consumerPriceIndex = STARTCPI; taxRate = STARTPAYROLLTAXRATE; payrollBaseRate = 0.0; benefitsTaxRate = STARTBENEFITSTAXRATE; interestRate = 0.0; InitializeYear(year,0.0,0.0,0.0) ; } void ReadBase(double &payrollBaseRate1,double &taxRate1, double &bend1output,double &bend2output, double &bend3output, double &expensesBaseRate1, double &nationalAverageWageIndex1, int &globalRetirementAge1) { payrollBaseRate1 = payrollBaseRate ; // The payroll cap (SocialSecurity calls it the base.) taxRate1 = taxRate ; bend1output = bend1 ; bend2output = bend2; bend3output = bend3; nationalAverageWageIndex1 = nationalAverageWageIndex; expensesBaseRate1 = expensesBaseRate ; // the simulator test of breaking the salary cap into 2 parts: the payroll cap and the expenses cap. globalRetirementAge1 = globalRetirementAge; } void UpdateSocialSecurity(double taxes1,double totalBenefits1, double taxablePayroll1, double retirementBenefits1, double survivorBenefits1, double disabilityBenefits1) { double x; socialSecurityTrust += taxes1 - totalBenefits1 ; x = benefitsTaxRate * totalBenefits1 ; // tax on SS benefits!!! socialSecurityTrust += x ; totalTaxOnBenefits += x; taxes += taxes1 ; totalBenefits += totalBenefits1; retirementBenefits += retirementBenefits1 ; survivorBenefits += survivorBenefits1 ; disabilityBenefits += disabilityBenefits1; taxablePayroll += taxablePayroll1; } double YearlyOperatingCycle() { int rt = 0; // printf("2 socialSecurityTrust:%g\n",socialSecurityTrust); yearlyInterest = socialSecurityTrust * interestRate; if (yearlyInterest < 0.0) { // printf("ERROR!!!! TRUST FUND IS NEGATIVE ##############\n"); yearlyInterest = 0.0; } /* if */ socialSecurityTrust += yearlyInterest; socialSecurityTrust -= railroadExpenses; socialSecurityTrust -= overhead; // printf("1 socialSecurityTrust:%g\n",socialSecurityTrust); totalExpenses = totalBenefits + railroadExpenses + overhead ; totalIncome = taxes + totalTaxOnBenefits; gdp *= (1.0 + STARTGDPRATE); // currently not used consumerPriceIndex *= (1.0 + costOfLivingAdjustment); // ditto return(100.0 * socialSecurityTrust / totalBenefits) ; // return trustFund Ratio. } void InitializeYear(int year, double costOfLivingAdjustment1, double interestRate1, double averageWageGrowthRate) { static double baseRates1[CURRENTYEAR - STARTINGYEAR + 1] = {76200.0, 80400.0, 84900.0, 87000.0, 87900.0, 90000.0}; static double bend1table[CURRENTYEAR - STARTINGYEAR + 1] = {531.0,561.0,592.0,606.0,612.0,624.0}; static double bend2table[CURRENTYEAR - STARTINGYEAR + 1] = {3202.0,3381.0,3567.0,3653.0,3689.0,3760.0}; static double bend3table[CURRENTYEAR - STARTINGYEAR + 1] = {1.0e99, 1.0e99, 1.0e99, 1.0e99, 1.0e99, 6000.0}; static double nationalAverageWageIndextable[CURRENTYEAR - STARTINGYEAR + 1] = {32154.82,32921.92,33252.09,33892.68,35057.39,36507.12}; double x; taxes = 0.0 ; totalBenefits = 0.0; retirementBenefits = 0.0 ; survivorBenefits = 0.0 ; disabilityBenefits = 0.0; taxablePayroll = 0.0; totalTaxOnBenefits = 0.0; costOfLivingAdjustment = costOfLivingAdjustment1; // monte carlo variable interestRate = interestRate1; if (year < STARTINGYEAR) { fprintf(stderr,"impossible %d\n",year); exit(1); } /* if */ if (year <= CURRENTYEAR) { payrollBaseRate = baseRates1[year - STARTINGYEAR]; expensesBaseRate = payrollBaseRate; traditionalBaseRate = payrollBaseRate; bend1 = bend1table[year - STARTINGYEAR]; bend2 = bend2table[year - STARTINGYEAR]; bend3 = bend3table[year - STARTINGYEAR]; nationalAverageWageIndex = nationalAverageWageIndextable[year - STARTINGYEAR]; } /* if */ else { traditionalBaseRate *= (1.0 + averageWageGrowthRate); // for comparisons with expensesBaseRate & payrollBaseRate if ((year >= BEGINFIXDATE) && (year < ENDFIXDATE)) { #if 0 if (((year == 2012)) ) { // for payroll cap SS fix test !!!!!!!!!! payrollBaseRate *= 2.0e6; // 1.0=cap, 2.0e6=no cap } /* if */ // if (((year == 2006)) ) { // for payroll rate, SS fix test !!!!!!!!!! // taxRate += PAYROLLRATEADJUSTMENT; // } /* if */ if (((year == 2040)) ) { // for RETIREMENTAGE test, SS fix test !!!!!!!!!! // globalRetirementAge += 2; } /* if */ if (((year == 2080)) ) { // for RETIREMENTAGE test, SS fix test !!!!!!!!!! // globalRetirementAge += 2; } /* if */ if (((year == 2120)) ) { // for RETIREMENTAGE test, SS fix test !!!!!!!!!! // globalRetirementAge += 2; } /* if */ #endif payrollBaseRate *= (1.0 + averageWageGrowthRate * PAYROLLCAPMULTIPLIER); // ss fix test: the duel cap test expensesBaseRate = payrollBaseRate; // expensesBaseRate *= (1.0 + averageWageGrowthRate * EXPENSESCAPMULTIPLIER); // ss fix test: the duel cap test } /* if */ else { payrollBaseRate *= (1.0 + averageWageGrowthRate); // ss fix test: the duel cap test expensesBaseRate *= (1.0 + averageWageGrowthRate); // ss fix test: the duel cap test // payrollBaseRate = traditionalBaseRate; // expensesBaseRate = traditionalBaseRate; taxRate = STARTPAYROLLTAXRATE; } /* else */ x = 1.0 + averageWageGrowthRate; #if PRIVATIZATIONFLAG // x = 1.0 + costOfLivingAdjustment; #endif bend1 *= (x) ; bend2 *= (x) ; bend3 *= (x) ; nationalAverageWageIndex *= (x) ; } /* else */ if (year > STARTINGYEAR) { benefitsTaxRate *= (1.0 + ESTIMATEDBENEFITSTAXRATEGROWTH); // tax on benefits } /* if */ } protected: // accessible by subclass private: // accessible by this class only double socialSecurityTrust; double overhead; double railroadExpenses; double costOfLivingAdjustment; double consumerPriceIndex; double gdp; double taxRate; double payrollBaseRate; double expensesBaseRate; double traditionalBaseRate; double interestRate; double taxes ; double totalBenefits; double retirementBenefits,survivorBenefits,disabilityBenefits; double taxablePayroll; double totalExpenses ; double totalIncome; double yearlyInterest; double totalTaxOnBenefits; double benefitsTaxRate; double bend1 ; double bend2; double bend3; double nationalAverageWageIndex; int globalRetirementAge; }; const NUMBEROFACCOUNTBUCKETS = (1000); // const double testBenefits[NUMBEROFCLASSES] = {93328.3,93328.3,93328.3,92469.1, 85618.8,61722.8, 37055.4,}; // RETIREMENTAGE 65 const double testBenefits[NUMBEROFCLASSES] = {309000,133000,117000,109000,91000, 65000,39000}; // RETIREMENTAGE 67 class AccountStudy { public: // accessible by all AccountStudy(){}; void InitializeStudy(int tries) { int i,j ; if (tries == 0) { for (i = 0; i < NUMBEROFCLASSES; i++) { for (j = 0; j < NUMBEROFACCOUNTBUCKETS; j++) { buckets[i][j] = 0; } /* jForLoop */ } /* iForLoop */ } /* if */ for (i = 0; i < NUMBEROFCLASSES; i++) { finalAge[i] = 0; finalYear[i] = 0; stockMarket[i] = 0.0 ; bondMarket[i] = 0.0 ; principal[i] = 0.0 ; totalSalary[i] = 0.0; retirementBenefits[i] = 0.0; } /* iForLoop */ testAge = 23; logStandardDeviationStock = log(1.16) ; // 0.149077 logAverageStock = log(1.089); // 1.072 0.0696027 allocationCap = 1000.0; // 1000 bucketSize = 1000.0; } void PrintStudyAll(int tries) { const char *className1[NUMBEROFCLASSES] = { "Super Rich", "Rich", "Upper Class", "Upper Middle Class", "Middle Class", "Lower Middle Class", "Poor", }; int i,j,k,count,temporary,percentileSize,percentileBoundary ; char *currentColor; double x, cola; char s[100]; for (i = 0; i < 100; i++) { s[i] = ' '; } /* iForLoop */ for (i = 0; i < NUMBEROFCLASSES; i++) { printf("%s%g\n",className1[i],testBenefits[i]); // printf("%s\n",className[i]); // printf("finalAge: %d finalYear:%d tries:%d\n",finalAge[i], finalYear[i], tries); percentileSize = tries / 10; for (j = 0, count = 0,temporary = 10,percentileBoundary = percentileSize; j < NUMBEROFACCOUNTBUCKETS; j++) { k = buckets[i][j] ; x = (double )j * bucketSize; // printf("%s[%d] bucket:%d $%g\n",className[i],j,k,x); count += k; if (count >= percentileBoundary ) { cola = (int )(log(x / testBenefits[i]) / log(1.028) + 0.5) + finalAge[i]; // printf("percentile%d (benefits:%g) (SS:%g) (cola:%g) count:%d percentileSize:%d\n",temporary,x,testBenefits[i],cola,count,percentileSize); currentColor = "red" ; if (cola > 67) { currentColor = "yellow"; } /* if */ if (cola >= 75) { currentColor = "green"; } /* if */ if (temporary < 91) { printf("%g\n",currentColor,x); } /* if */ percentileBoundary += percentileSize; temporary += 10; } /* if */ if (k > 49) { k = 49; } /* if */ s[k] = 0; // printf("buckets[%6f]: %02d: %s\n",x,buckets[i][j],s); s[k] = '#'; } /* jForLoop */ printf("\n"); } /* iForLoop */ // exit(0); } void InitializeYear(int year,double averageWageGrowthRate) { int i ; double x,x1,x2; holdYear = year; x1 = GaussianRandom(); x = exp( (x1 * logStandardDeviationStock) + (logAverageStock) ) ; x2 = 1.0 + exp(LOGESTIMATEDINTERESTRATE + (GaussianRandom() * LOGINTERESTRATESTANDARDDEVIATION)); for (i = 0; i < NUMBEROFCLASSES; i++) { stockMarket[i] *= x ; stockMarket[i] *= 0.997 ; // expenses .3% bondMarket[i] *= x2 ; bondMarket[i] *= 0.997 ; } /* iForLoop */ testAge++; if (holdYear > 2009) { allocationCap = allocationCap * (1.0 + averageWageGrowthRate) + 100.0; } /* if */ } double UpdateStudy(int age,int classIndex,double payrollTaxRate,double salary,double retirementBenefits1) { double contributionAmount,stockAllocation; if ((holdYear - age) < 1950) { return(0.0) ; } /* if */ if (holdYear < 2009) { return(0.0) ; } /* if */ if ((holdYear == 2009) && (age < 44)) { return(0.0) ; } /* if */ if ((holdYear == 2010) && (age < 32)) { return(0.0) ; } /* if */ // if (classIndex < 5) { // return(0.0) ; // } /* if */ contributionAmount = salary * 0.04 ; // contributionAmount = 0.0; if (contributionAmount > allocationCap) { contributionAmount = allocationCap; } /* if */ if ((age == testAge) && (finalAge[classIndex] == 0)) { stockAllocation = -0.025 * age + 1.625 ; // stockAllocation = 1.0; if (stockAllocation < 0.0) { stockAllocation = 0.0; } /* if */ if (stockAllocation > 1.0) { stockAllocation = 1.0; } /* if */ totalSalary[classIndex] += salary; principal[classIndex] += salary * (payrollTaxRate * 2.0) ; stockMarket[classIndex] += contributionAmount * stockAllocation; bondMarket[classIndex] += contributionAmount * (1.0 - stockAllocation); retirementBenefits[classIndex] = retirementBenefits1; if (retirementBenefits1 != 0) { // worker has retired // printf("test: %d age:%d\n",classIndex,age); StudyDistribution(classIndex); // freeze the study } /* if */ // printf("%s[%d]: salary:%g payrolltax:%g retirebenef:%g\n",className[classIndex],age,salary,payrollTax,retirementBenefits1); } /* if */ return(contributionAmount) ; } protected: // accessible by subclass private: // accessible by this class only void PrintStudy() { int i ; double annuity ; double annuityConversion = 12.0 * 600.0 / 1.0e5; printf("testAge: %d\n",testAge); for (i = 0; i < NUMBEROFCLASSES; i++) { annuity = (stockMarket[i] + bondMarket[i]) * annuityConversion; printf("// %s\n",className[i]); printf("{ %d\n",i); printf("stockMarket: %g\n",stockMarket[i]); printf("bondMarket: %g\n",bondMarket[i]); printf("annuity: %g\n",annuity); printf("principal: %g\n",principal[i]); printf("totalSalary: %g\n",totalSalary[i]); printf("retirementBenefits: %g\n",retirementBenefits[i]); printf("totalBenefits: %g\n",retirementBenefits[i] + annuity); printf("basicSocialSecurity: %g\n",testBenefits[i]); } /* iForLoop */ } void StudyDistribution(int i) { int j ; double annuity,totalBenefits ; double annuityConversion = 12.0 * 600.0 / 1.0e5; finalYear[i] = holdYear ; finalAge[i] = testAge; annuity = (stockMarket[i] + bondMarket[i]) * annuityConversion; totalBenefits = retirementBenefits[i] + annuity; j = (int )(totalBenefits / bucketSize); if (j < 0) { j = 0; } /* if */ if (j >= NUMBEROFACCOUNTBUCKETS) { j = NUMBEROFACCOUNTBUCKETS - 1; } /* if */ buckets[i][j]++; } int finalAge[NUMBEROFCLASSES]; int finalYear[NUMBEROFCLASSES]; double stockMarket[NUMBEROFCLASSES] ; double bondMarket[NUMBEROFCLASSES] ; double principal[NUMBEROFCLASSES] ; double totalSalary[NUMBEROFCLASSES] ; double retirementBenefits[NUMBEROFCLASSES] ; int buckets[NUMBEROFCLASSES][NUMBEROFACCOUNTBUCKETS] ; int testAge; int holdYear; double logStandardDeviationStock; double logAverageStock; double allocationCap; double bucketSize; }; AccountStudy privateAccounts; class Household { public: // accessible by all Household(){} ; void Household::AdvanceYear(Household *first) { static double currentPopulationNew, retirementBenefitsNew, pendingRetirementBenefitNew; double newBirths,deaths; double temporary; if (headOfHouseholdAge == 0) { currentPopulationNew = 0.0; // these static variables carry over variables from age group N to age group N+1 retirementBenefitsNew = 0.0; // init to 0 at age 0 pendingRetirementBenefitNew = 0.0; } /* if */ /* births */ newBirths = currentPopulation * birthRate ; /* deaths, inheritance */ deaths = currentPopulation * mortalityRate; currentPopulation -= deaths; currentPopulation += migrationValue; /* aging: household[age-1] => household[age] => household[age+1] */ temporary = currentPopulationNew; currentPopulationNew = currentPopulation ; currentPopulation = temporary; temporary = retirementBenefitsNew; retirementBenefitsNew = retirementBenefit ; retirementBenefit = temporary; temporary = pendingRetirementBenefitNew ; pendingRetirementBenefitNew = pendingRetirementBenefit ; pendingRetirementBenefit = temporary; first->currentPopulation += newBirths; // all the births for this year add to age0 } void Household::YearlyOperatingCycle(Household *first, double &payrollTax1, double &benefits1, double &taxablePayroll1,double &retirementBenefits1,double &survivorBenefits1,double &disabilityBenefits1) { // calculate how much payroll tax to pay, and how much benefits to receive double x,numberOfHouseholds,percentage; double accountContribution = 0.0; x = salary; if (x > payrollTaxBase) { // ss payroll cap x = payrollTaxBase; } /* if */ #if PRIVATIZATIONFLAG accountContribution = privateAccounts.UpdateStudy(headOfHouseholdAge,householdClass,payrollTaxRate,x,retirementBenefit); #endif numberOfHouseholds = CalculateNumberOfHouseholds(); taxablePayroll1 = x * numberOfHouseholds; payrollTax = x * (payrollTaxRate * 2.0); // times 2.0 = personal+business percentage = 1.0 - (accountContribution / payrollTax); // reduce benefits payrollTax = (payrollTax - accountContribution) * numberOfHouseholds; // carve-out totalBenefits = disabilityBenefits + survivorBenefits + retirementBenefit ; totalBenefits *= numberOfHouseholds; payrollTax1 = payrollTax ; benefits1 = totalBenefits; retirementBenefits1 = retirementBenefit * numberOfHouseholds ; survivorBenefits1 = survivorBenefits * numberOfHouseholds ; disabilityBenefits1 = disabilityBenefits * numberOfHouseholds; CalculateBenefits(percentage); } void InitializeHousehold(int householdClass1,int headOfHouseholdAge1, int year) { householdClass = householdClass1 ; headOfHouseholdAge = headOfHouseholdAge1 ; currentPopulation = peopleData[headOfHouseholdAge].currentPopulation * classPercentages[householdClass]; numberOfPeople = peopleData[headOfHouseholdAge].numberOfPeople; numberOfEarners = peopleData[headOfHouseholdAge].numberOfEarners; mortalityRate = peopleData[headOfHouseholdAge].mortalityRate; // the following weighting numbers for birthRate through retirementBenefits were "curve-fit" birthRate = 0.985 * 0.5 * peopleData[headOfHouseholdAge].birthRate; migrationValue = peopleData[headOfHouseholdAge].migrationValue * classPercentages[householdClass]; salary = 89483.0 * 1.09 * peopleData[headOfHouseholdAge].salaryMultiplier * classSalary[householdClass]; disabilityBenefits = 235.0 * peopleData[headOfHouseholdAge].disabilityMultiplier * classDisability[householdClass]; survivorBenefits = 718.0 * peopleData[headOfHouseholdAge].survivorMultiplier * classSurvivor[householdClass]; retirementBenefit = 0.0; pendingRetirementBenefit = 0.0; cash = 0.0; InitializeYear(year); } void ReadPopulation(double ¤tPopulation1,double &numberOfHouseholds1, double &salary1, double &payrollTax1,double &benefits1) { currentPopulation1 = currentPopulation ; numberOfHouseholds1 = CalculateNumberOfHouseholds(); salary1 = salary; payrollTax1 = payrollTax; benefits1 = totalBenefits; // printf("retirementBenefits[%s][%d]:%g\n",className[householdClass],headOfHouseholdAge,retirementBenefit); } static void Household::SetGlobalVariables(double payrollTaxbase1,double payrollTaxRate1,double costOfLivingAdjustment1, double bend1input, double bend2input, double bend3input, double wageGrowthRate1,double averageWageGrowthRate1,double mortalityRateDecrease1,double expensesTaxbase1, double nationalAverageWageIndex1, int globalRetirementAge1) { payrollTaxBase = payrollTaxbase1; expensesTaxBase = expensesTaxbase1; payrollTaxRate = payrollTaxRate1; costOfLivingAdjustment = costOfLivingAdjustment1 ; bend1 = bend1input ; bend2 = bend2input; bend3 = bend3input; wageGrowthRate = wageGrowthRate1 ; averageWageGrowthRate = averageWageGrowthRate1; mortalityRateDecrease = mortalityRateDecrease1; nationalAverageWageIndex = nationalAverageWageIndex1; globalRetirementAge = globalRetirementAge1; } void InitializeYear(int year) { if (year > STARTINGYEAR) { if (headOfHouseholdAge == globalRetirementAge) { retirementBenefit = pendingRetirementBenefit ; } /* else */ salary *= (1.0 + wageGrowthRate) ; // a monte carlo variable mortalityRate *= (1.0 - mortalityRateDecrease); // a monte carlo variable retirementBenefit *= (1.0 + costOfLivingAdjustment); disabilityBenefits *= (1.0 + averageWageGrowthRate); survivorBenefits *= (1.0 + averageWageGrowthRate); } /* if */ } double InitializeBenefits(double temporary) { double x ; // at time 0: approximate historical benefits accrual (for all ages 25 to 99) pendingRetirementBenefit = temporary ; // this years initial benefits (from the previous age group) if (headOfHouseholdAge >= globalRetirementAge) { // at time 0: approximate historical benefits accrual (ages 65 to 99) retirementBenefit = pendingRetirementBenefit; temporary *= INITIALRETIREMENTADJUSTMENT; return(temporary) ; } /* if */ CalculateBenefits(1.0) ; // calculate next years benefits x = pendingRetirementBenefit ; // hold next years benefits -> pass to the next age group pendingRetirementBenefit = temporary ; // restore this year's initial benefits return(x) ; } protected: // accessible by subclass private: // accessible by this class only void Household::CalculateBenefits(double percentage) { double averageSalary,x, bend1t,bend2t,bend3t; // an approximation to the SS algorithm for determining benefits if ((headOfHouseholdAge >= EMPLOYMENTAGE) && (headOfHouseholdAge < BENEFITSAGE)) { // 27 to 61 x = salary ; if (x > expensesTaxBase) { x = expensesTaxBase; } /* if */ x *= percentage; // for modeling personal accounts stuff (normally 1.0) if (headOfHouseholdAge < INDEXINGAGE) { // 27-59 x /=nationalAverageWageIndex ; } /* else */ else if (headOfHouseholdAge == INDEXINGAGE) { // 60 pendingRetirementBenefit *= nationalAverageWageIndex; } /* elseif */ pendingRetirementBenefit += x; } /* if */ else if (headOfHouseholdAge == BENEFITSAGE) { // 62 averageSalary = pendingRetirementBenefit; averageSalary /= 35.0 * 12 ; // AIME bend1t = bend1 ; bend2t = bend2; bend3t = bend3; if (averageSalary < bend1t) { bend1t = averageSalary; } /* if */ if (averageSalary < bend2t) { bend2t = averageSalary; } /* if */ if (averageSalary < bend3t) { // for testing a fix to SS bend3t = averageSalary; } /* if */ #if PRIVATIZATIONFLAG if (percentage < 0.9999) { // privatized reduced benefits //printf("%s: %g\n",PrintName(),percentage); pendingRetirementBenefit = 0.74 * (bend1t) + 0.23 * (bend2t - bend1t) + 0.09 * (averageSalary - bend2t) ; // pia } /* if */ else { // traditional benefits pendingRetirementBenefit = 0.9 * (bend1t) + 0.32 * (bend2t - bend1t) + 0.15 * (averageSalary - bend2t) ; // pia } /* else */ #endif // The following line is for the third bend point test fix to SS // pendingRetirementBenefit = 0.9 * (bend1t) + 0.32 * (bend2t - bend1t) + 0.15 * (bend3t - bend2t) + 0.04 * (averageSalary - bend3t) ; // pia (third bend pointtest) // The following line is for the typical 2 bend point benefit calculation #if !PRIVATIZATIONFLAG pendingRetirementBenefit = 0.9 * (bend1t) + 0.32 * (bend2t - bend1t) + 0.15 * (averageSalary - bend2t) ; // pia #endif pendingRetirementBenefit *= 12.0; /* back to yearly */ } /* elseIf */ else if (headOfHouseholdAge > BENEFITSAGE) { // 62+ pendingRetirementBenefit *= (1.0 + costOfLivingAdjustment); } /* if */ } double CalculateNumberOfHouseholds() { double temporary; if (numberOfPeople < 1.0e-1) { fprintf(stderr,"error: numberOfPeople:%g %s\n",numberOfPeople,PrintName()); exit(1); } /* if */ temporary = currentPopulation / numberOfPeople; if (headOfHouseholdAge < ADULTAGE) { temporary = 0.0; } /* if */ return(temporary) ; } char *PrintName() { static char buffer[256]; sprintf(buffer,"%s%d",className[householdClass],headOfHouseholdAge); return(buffer) ; } int householdClass ; int headOfHouseholdAge ; double numberOfPeople; double numberOfEarners; double currentPopulation; double mortalityRate; double birthRate; double migrationValue; double salary; double payrollTax; double survivorBenefits; double disabilityBenefits ; double retirementBenefit ; double pendingRetirementBenefit; double totalBenefits; double cash; static double payrollTaxBase; static double expensesTaxBase; static double payrollTaxRate; static double costOfLivingAdjustment; static double bend1; static double bend2; static double bend3; static double wageGrowthRate; static double averageWageGrowthRate; static double mortalityRateDecrease; static double nationalAverageWageIndex; static int globalRetirementAge; }; int Household::globalRetirementAge = 0; double Household::payrollTaxBase = 0.0; double Household::expensesTaxBase = 0.0; double Household::payrollTaxRate = 0.0; double Household::costOfLivingAdjustment = 0.0; double Household::bend1 = 0.0; double Household::bend2 = 0.0; double Household::bend3 = 0.0; double Household::wageGrowthRate = 0.0; double Household::averageWageGrowthRate = 0.0; double Household::mortalityRateDecrease = 0.0; double Household::nationalAverageWageIndex = 0.0; class BucketClass { public: // accessible by all BucketClass(){} ; void UpdateBuckets (double trustFundRatio,int year,int holdSeed) { int i; int index = year - STARTINGYEAR; workingRatios[index] = trustFundRatio; if ((trustFundRatio < 0.0) || (year == (STOPPINGYEAR - 1))) { for (i = 0; i < index; i++) { totalRatios[index][i] += workingRatios[i]; // for average curve for this exhaustion point } /* iForLoop */ buckets[index]++; bucketSeeds[index] = holdSeed; totalBuckets++; } /* if */ } void PrintBuckets () { int i; int total, count, next, count10,count50,count90; // The buckets are used to save the exhaustion year (and a "seed" to restart the simulation if needed) during monte carlo simulations next = totalBuckets / 10; count = 10; count10 = count50 = count90 = 0; for (i = 0,total = 0; i < NUMBEROFBUCKETS; i++) { printf("%d: %d (seed: %d)\n",i + STARTINGYEAR,buckets[i],bucketSeeds[i]); total += buckets[i] ; if (total > next) { printf("percentile %d: %d (%d > %d)\n",count,i + STARTINGYEAR,total,next); if (count == 10) { count10 = i; } /* if */ if (count == 50) { count50 = i; } /* if */ if (count == 90) { count90 = i; } /* if */ next += MAXIMUMTRIES / 10 ; count += 10; } /* if */ } /* iForLoop */ for (i = 0; i < NUMBEROFBUCKETS; i++) { printf("{ %d\n",i + STARTINGYEAR); printf("exhaustion: %d\n", buckets[i]); printf("percentile10: %g\n",totalRatios[count10][i] / ((double )buckets[count10])); printf("percentile50: %g\n",totalRatios[count50][i] / ((double )buckets[count50])); printf("percentile90: %g\n",totalRatios[count90][i] / ((double )buckets[count90])); printf("}\n"); } /* iForLoop */ } void InitializeBuckets () { int i,j; totalBuckets = 0; for (i = 0; i < NUMBEROFBUCKETS; i++) { buckets[i] = 0; bucketSeeds[i] = 0; for (j = 0; j < NUMBEROFBUCKETS; j++) { totalRatios[i][j] = 0.0; } /* jForLoop */ } /* iForLoop */ } protected: // accessible by subclass private: // accessible by this class only double workingRatios[NUMBEROFBUCKETS]; double totalRatios[NUMBEROFBUCKETS][NUMBEROFBUCKETS]; int buckets[NUMBEROFBUCKETS]; int bucketSeeds[NUMBEROFBUCKETS]; int totalBuckets; }; class Economy { public: // accessible by all Economy(){} ; void PrintBucketsAll () { bucketValues.PrintBuckets(); } void InitializeBucketsAll () { bucketValues.InitializeBuckets(); } void Economy::InitializeEconomy (int tries,int year) { int classesIndex,ageIndex; #if PRIVATIZATIONFLAG privateAccounts.InitializeStudy(tries); #endif averageWageGrowthRate = EARNINGSGROWTHRATE ; federalGovernment.InitializeGovernment(year); if (tries == 0) { // malloc arrays only once!! households = new Household *[NUMBEROFCLASSES] ; for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { households[classesIndex] = new Household[NUMBEROFAGES]; } /* classesIndexForLoop */ } /* if */ for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { households[classesIndex][ageIndex].InitializeHousehold(classesIndex,ageIndex,year); } /* forLoop */ } /* ForLoop */ } void Economy::EvaluateEconomy () { int day,month,year,holdSeed,flag; double trustFundRatio; day = 30; month = 12; // SetSeed(1481999034); // enable this line to simulate a particular run derived from a monte carlo simulation #if ENABLESEED SetSeed(SIMULATIONSEEDVALUE); // enable this line to simulate a particular run derived from a monte carlo simulation #endif holdSeed = ReadSeed(); // save the seed for this run, so can resimulate it latter if desired. for (year = STARTINGYEAR, flag = 1; year < STOPPINGYEAR; year++) { // printf("\n************* YEAR: %d *********************\n",year); InitializeYear(year); trustFundRatio = YearlyOperatingCycle(); if (MAXIMUMTRIES == 1) { PrintYearlyEconomy(day,12,year); } /* if */ AdvanceYear(); if (MAXIMUMTRIES > 1) { if (flag) { bucketValues.UpdateBuckets (trustFundRatio, year, holdSeed) ; if (trustFundRatio < 0.0) { flag = 0; // break; // trust fund is negative, so abort } /* if */ } /* if */ } /* if */ } /* year forLoop */ } protected: // accessible by subclass private: // accessible by this class only void Economy::InitializeYear (int year) { int classesIndex,ageIndex,globalRetirementAge; double payrollBaseRate1, taxRate1, costOfLivingAdjustment,bend1,bend2,bend3,wageGrowthRate,trustFundInterestRate,mortalityRateDecrease,expensesBaseRate,nationalAverageWageIndex; double temporary; #if !MONTECARLOSIMULATION // for typical case simulations (default values) costOfLivingAdjustment = STARTCOSTOFLIVINGADJUSTMENT; wageGrowthRate = EARNINGSGROWTHRATE; trustFundInterestRate = ESTIMATEDINTERESTRATE; mortalityRateDecrease = ESTIMATEDMORTALITYRATEDECREASE; #endif #if MONTECARLOSIMULATION // for monte carlo simulations (the monte carlo algorithm) //costOfLivingAdjustment = exp(LOGSTARTCOSTOFLIVINGADJUSTMENT + (GaussianRandom() * LOGCOSTOFLIVINGSTANDARDDEVIATION)) ; costOfLivingAdjustment = STARTCOSTOFLIVINGADJUSTMENT + (GaussianRandom() * COSTOFLIVINGSTANDARDDEVIATION) ; // wageGrowthRate = exp(LOGEARNINGSGROWTHRATE + (GaussianRandom() * LOGEARNINGSGROWTHSTANDARDDEVIATION)); wageGrowthRate = EARNINGSGROWTHRATE + (GaussianRandom() * EARNINGSGROWTHSTANDARDDEVIATION); // printf("wageGrowthRate:%g\n",wageGrowthRate); trustFundInterestRate = exp(LOGESTIMATEDINTERESTRATE + (GaussianRandom() * LOGINTERESTRATESTANDARDDEVIATION)); if (trustFundInterestRate < 0.001) { // CHECK THAT LOGNORMAL IS WORKING! fprintf(stderr,"HACK1 !!!!\n"); } /* if */ if (trustFundInterestRate > 0.3) { // CHECK THAT LOGNORMAL IS WORKING! fprintf(stderr,"HACK2 !!!!\n"); } /* if */ mortalityRateDecrease = ESTIMATEDMORTALITYRATEDECREASE + (GaussianRandom() * MORTALITYRATESTANDARDDEVIATION); #endif federalGovernment.InitializeYear(year,costOfLivingAdjustment,trustFundInterestRate,averageWageGrowthRate); federalGovernment.ReadBase(payrollBaseRate1,taxRate1,bend1,bend2,bend3,expensesBaseRate,nationalAverageWageIndex,globalRetirementAge); #if PRIVATIZATIONFLAG privateAccounts.InitializeYear(year,averageWageGrowthRate); #endif Household::SetGlobalVariables(payrollBaseRate1,taxRate1,costOfLivingAdjustment,bend1,bend2,bend3,wageGrowthRate,averageWageGrowthRate,mortalityRateDecrease,expensesBaseRate,nationalAverageWageIndex,globalRetirementAge); if (year == STARTINGYEAR) { // InitializeBenefits for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { temporary = 0.0; for (ageIndex = EMPLOYMENTAGE; ageIndex < NUMBEROFAGES; ageIndex++) { temporary = households[classesIndex][ageIndex].InitializeBenefits(temporary); } /* forLoop */ } /* jForLoop */ } /* if */ for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { households[classesIndex][ageIndex].InitializeYear(year); } /* forLoop */ } /* jForLoop */ averageWageGrowthRate = wageGrowthRate; /* for monte carlo simulations, the SS averageWageGrowth variable is the previous years actual wageGrowth */ } double Economy::YearlyOperatingCycle () { int classesIndex,ageIndex; double trustFundRatio; double payrollTax1, benefits1, taxablePayroll1, retirementBenefits, survivorBenefits, disabilityBenefits; for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { households[classesIndex][ageIndex].YearlyOperatingCycle(&households[classesIndex][0], payrollTax1, benefits1, taxablePayroll1, retirementBenefits, survivorBenefits, disabilityBenefits); federalGovernment.UpdateSocialSecurity(payrollTax1, benefits1, taxablePayroll1, retirementBenefits, survivorBenefits, disabilityBenefits); } /* forLoop */ } /* jForLoop */ trustFundRatio = federalGovernment.YearlyOperatingCycle(); // note: place AFTER households return(trustFundRatio) ; } void Economy::AdvanceYear () { int classesIndex,ageIndex; /* births, mortality, aging */ for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { households[classesIndex][ageIndex].AdvanceYear(&households[classesIndex][0]); } /* forLoop */ } /* jForLoop */ } void Economy::PrintYearlyEconomy (int day,int month,int year) { PrintPopulationData( day, month, year); } void Economy::PrintPopulationData(int day,int month,int year) { static int tableIndex = 1; int classesIndex,ageIndex,globalRetirementAge; // print whatever you want to see, else comment it out, etc. double currentPopulation,numberOfHouseholds,totalPopulation,totalHouseholds,payrollBaseRate,expensesBaseRate; double grandtotalPopulation, grandtotalHouseholds, salary,totalSalary, grandSalary; double totalBenefits,socialSecurity,grandsocialSecurity,socialSecurityBenefits,grandsocialSecurityBenefits; double trust1, taxes1, benefits1,traditionalBaseRate,x,taxablePayroll; double grandtotalPopulation65,totalPopulation65,totalPopulationworking,grandtotalPopulationworking; grandtotalPopulation65 = grandtotalPopulationworking = grandsocialSecurityBenefits = grandSalary = grandsocialSecurity = grandtotalPopulation = grandtotalHouseholds = 0.0; globalRetirementAge = federalGovernment.ReadAge(); // printf("\nage population population65 popWorking households (%d/%d/%d)\n",month,day,year); for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { totalPopulation65 = totalPopulationworking = totalBenefits = totalSalary = totalPopulation = totalHouseholds = 0.0; // printf("%d: ",ageIndex); for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { households[classesIndex][ageIndex].ReadPopulation(currentPopulation,numberOfHouseholds,salary,socialSecurity,socialSecurityBenefits); totalPopulation += currentPopulation ; if (ageIndex >= globalRetirementAge) { totalPopulation65 += currentPopulation ; grandtotalPopulation65 += currentPopulation; } /* if */ if ((ageIndex >= ADULTAGE) && (ageIndex < globalRetirementAge)) { totalPopulationworking += currentPopulation ; grandtotalPopulationworking += currentPopulation; } /* if */ totalHouseholds += numberOfHouseholds; totalSalary += salary * numberOfHouseholds; grandsocialSecurity += socialSecurity; totalBenefits += socialSecurityBenefits; grandsocialSecurityBenefits += socialSecurityBenefits; // printf("%8.2f ",salary); } /* forLoop */ // printf("\n"); // printf("%03d: %g (%g) (%g) (%g) ($%g, %g avg) bene:%g\n",ageIndex,totalPopulation,totalPopulation65,totalPopulationworking,totalHouseholds,totalSalary,totalSalary / totalHouseholds,totalBenefits / totalHouseholds); grandtotalPopulation += totalPopulation ; grandtotalHouseholds += totalHouseholds; grandSalary += totalSalary; } /* jForLoop */ // printf("totalPopulation: %g (pop65:%g) (popWorking:%g) totalHouseholds: %g socialSecurity: %g socialSecurityBenefits: %g\n",grandtotalPopulation,grandtotalPopulation65,grandtotalPopulationworking,grandtotalHouseholds,grandsocialSecurity,grandsocialSecurityBenefits); #if 0 grandSalary = grandtotalPopulation = grandtotalHouseholds = 0.0; printf("\nclass population households (%d/%d/%d)\n",month,day,year); for (classesIndex = 0; classesIndex < NUMBEROFCLASSES; classesIndex++) { totalBenefits = totalSalary = totalPopulation = totalHouseholds = 0.0; for (ageIndex = 0; ageIndex < NUMBEROFAGES; ageIndex++) { households[classesIndex][ageIndex].ReadPopulation(currentPopulation,numberOfHouseholds,salary,socialSecurity,socialSecurityBenefits); totalPopulation += currentPopulation ; totalHouseholds += numberOfHouseholds; totalSalary += salary * numberOfHouseholds; totalBenefits += socialSecurityBenefits; } /* forLoop */ printf("%s: %g (%g) ($%g, %g avg) bene:%g\n",className[classesIndex],totalPopulation,totalHouseholds,totalSalary,totalSalary / totalHouseholds,totalBenefits / totalHouseholds); grandtotalPopulation += totalPopulation ; grandtotalHouseholds += totalHouseholds; grandSalary += totalSalary; } /* jForLoop */ #endif printf("{ %d\n",year); federalGovernment.ReadGovernment(trust1, taxes1, benefits1,payrollBaseRate,expensesBaseRate,traditionalBaseRate,taxablePayroll); // printf("trust: %g, taxesReceived: %g benefitsPaid: %g\n", trust1, taxes1, benefits1); // printf("{ %d\n",year); // printf("payrollBaseRate: %g\n",log(payrollBaseRate )); // printf("expensesBaseRate: %g\n", log(expensesBaseRate)); // printf("traditionalBaseRate: %g\n", log(traditionalBaseRate)); printf("trustFundRatio: %g\n", 100.0 * trust1 / benefits1); #if 0 printf("totalSalary: %g\n", grandSalary); printf("taxablePayroll:%g\n",taxablePayroll); printf("untaxablePayrollRatio:%g\n",taxablePayroll / grandSalary); printf("population: %g\n", grandtotalPopulation); printf("population65: %g\n", grandtotalPopulation65); printf("populationWorking: %g\n", grandtotalPopulationworking); x = 0.045 * (grandtotalPopulationworking + grandtotalPopulation65); // disabled + beneficiaries printf("popRatio(workers/65): %g\n", grandtotalPopulationworking / (grandtotalPopulation65 + x ) ); printf("households: %g\n", grandtotalHouseholds); printf("socialSecurityTrust: %g\n", trust1); printf("taxesReceived: %g\n", taxes1); printf("benefitsPaid: %g\n", benefits1); printf("payrollBaseRate: %g\n",payrollBaseRate ); printf("expensesBaseRate: %g\n", expensesBaseRate); printf("traditionalBaseRate: %g\n", traditionalBaseRate); printf("taxesPerWorker: %g\n",taxes1 / grandtotalPopulationworking); printf("benefitsPerRetiree:% g\n",benefits1 / (grandtotalPopulation65 + x )); printf("benefitsTaxesRatio:% g\n",(benefits1 / (grandtotalPopulation65 + x )) / (taxes1 / grandtotalPopulationworking) ); if (year > table4b1[tableIndex].year) { tableIndex++; } /* if */ printf("TincomeRate:%g\n", table4b1[tableIndex].incomeRate); printf("TcostRate:%g\n", table4b1[tableIndex].costRate); printf("TworkerRatio:%g\n", table4b1[tableIndex].workerRatio); printf("TpopulationWorkers:%g\n", table4b1[tableIndex].populationWorkers); printf("Tpopulation65:%g\n", table4b1[tableIndex].population65); printf("TincomeExcludingInterest:%g\n", table4b1[tableIndex].incomeExcludingInterest); printf("Tcost:%g\n", table4b1[tableIndex].cost); printf("TtrustFund:%g\n", table4b1[tableIndex].trustFund); #endif printf("}\n"); } Household **households; Government federalGovernment; double averageWageGrowthRate; BucketClass bucketValues; }; void test () /* this is only a test of the RNG */ { int i ; double x ; int j; int buckets[100]; for (i = 0; i < 100; i++) { buckets[i] = 0; } /* iForLoop */ for (i = 0; i < 10000; i++) { x = GaussianRandom() ; j = (int )(x * 10) + 50 ; if (j < 0) { j = 0; } /* if */ if (j >= 100) { j = 99; } /* if */ buckets[j]++; // printf("%g %g\n",RandomNumber(),GaussianRandom()); } /* iForLoop */ for (i = 0; i < 100; i++) { printf("%03d: %d\n",i,buckets[i]); } /* iForLoop */ exit(1); } void main( ) { Economy unitedStatesEconomy ; int tries; long count1,count2; time(&count1); InitializeRandom(); // test(); unitedStatesEconomy.InitializeBucketsAll(); for (tries = 0; tries < MAXIMUMTRIES; tries++) { // printf("\n************* TRIES: %d *********************\n",tries); unitedStatesEconomy.InitializeEconomy(tries,STARTINGYEAR); unitedStatesEconomy.EvaluateEconomy(); } /* tries forLoop */ if (MAXIMUMTRIES > 1) { #if PRIVATIZATIONFLAG privateAccounts.PrintStudyAll(MAXIMUMTRIES); #endif unitedStatesEconomy.PrintBucketsAll(); } /* if */ time(&count2); printf("\n; simulation time: %d seconds\n", count2 - count1); }