//
// simu1.h Asset Allocation Header
//

struct termvals {
  double termstock;
  double termwealth;};
^
|
The new type termvals is designed to allow a function to return both the final
wealth in a portfolio simulation and the final stock price.

class aa {
  public:
    aa(double ttm=1.0,int nper=120,double r=.05,double mean=.15,double stddev=.2);
    int restart(double ttm,int nper,double r,double mean,double stddev);
        ^
        |
        Restart allows us to change the parameters specified by the constructor.

    termvals fixprops(double inrisky,double initstock=0.0,double initcash=100.0);
             ^
             |
             The function fixprops simulates a portfolio strategy of investing a
             fixed proportion inrisky of wealth in the risky asset and the rest
             (in ``cash'') at a fixed interest rate.

  private:
    int npers;
    double tinc, r1per, mean1per, std1persqrt12, wealth, stockpos, cash, stockP, stockret;
    double stocktotret();};

//
// simu1test.cc Asset Allocation test file
//
#include 
#include "simu1.h"

main() {
  int i;
  aa sim1;
  termvals y;
  for(i=0;i<100;i++) {
    y = sim1.fixprops(.5);
    cout << y.termstock << " " << y.termwealth << endl;}
    ^
    |
    This part is simpler than in previous assignments.  We are simply running
    the simulation 100 times and printing out the terminal stock price and wealth
    each time.  If the output can be copied and pasted to a spreadsheet, the test
    program is fine as is.  Otherwise, this should be sent to a file that will be
    imported by a spreadsheet.

  return(0);}

//
// simu1.cc Asset Allocation Simulation
//
#include 
#include 
#include 
#include "simu1.h"
#define unifrand() ((double) rand()/((double) RAND_MAX))
        ^
        |
        This macro simulates a uniform random variable.  Type declaration and
        the definition of RAND_MAX are in .

aa::aa(double ttm,int nper,double r,double mean,double stddev) {
  restart(ttm,nper,r,mean,stddev);}
  ^
  |
  The constructor simply calls restart, a function that defines or redefines the
  internal parameters

int aa::restart(double ttm,int nper,double r,double mean,double stddev) {
  npers = nper;
  tinc = ttm/(double) nper;
  r1per = 1.0 + r*tinc;
  mean1per = 1.0 + mean*tinc;
  ^
  |
  In the risk-neutral probabilities, the mean return is the riskless rate.
  We want to work in actual probabilities to simulate actual performance.

  std1persqrt12 = sqrt((double) 12)*stddev*sqrt(tinc);
  ^
  |
  The square root of 12 is the reciprocal of the standard deviation of
  a random variable that is uniform on [0,1].  It is computed here to avoid
  computing it each time through the loop.

//  cout << " " << npers << " " << tinc << " " << r1per << " "
//    << mean1per << " " << std1persqrt12 << endl;
    ^
    |
    I used this and subsequent commented-out print statements during
    debugging.  (Similar print statements in previous programs were
    commented out before distribution.)  These print statements allow
    me to step through the programs and isolate errors.

  return(0);}

termvals aa::fixprops(double inrisky,double initstock,double initcash) {
  int i;
  termvals x;
           ^
           |
           a place to store the results before returning

  stockpos = initstock;
  cash = initcash;
  stockP = 100.0;
  ^
  |
  initializing the stock position, cash position, and stock price

//  cout << npers << endl;
  for(i=0;i