/***************************************************************** * FINANCE 7200 FALL 1997 * * HOMEWORK ASSIGNMENT #1 * * Dave Gross * * * * This program: * * 1. Loads CRSP stock return data from the file "daily.out". * * 2. Creates an n-stock by t-day data matrix. * * 3. Computes the COMPOUND RETURN for each stock. * * 4. Computes the GEOMETRIC AVERAGE RETURN for each stock. * * 5. Computes the ARITHMETIC AVERAGE RETURN for each stock. * * 6. Computes the EQUALLY-WEIGHTED PORTFOLIO RETURN for * * the n stocks assuming daily rebalancing of the portfolio. * * 7. Prints the results to the file "pset102.out". * *****************************************************************/ new; format 12,4; @ Assigns output format @ output file=pset102.out reset; @ Assigns output file @ /********************************************************************* * 1. LOAD THE DATA * * * * n=number of stocks * * t=number of daily returns * * * * The "load" statement reads a n*t-row, 5-column input matrix "im". * * Each row represents a daily entry for each stock. * * * * Note: The data set must be contained in the same directory as * * the program or the address must be changed. * * * * Note: Gauss reads the "date" field as two seperate columns so the * * return data is in the 5th column of the input matrix. * *********************************************************************/ n=20; @ Number of stocks @ t=22; @ Number of days @ a=n*t; @ Number of rows in input matrix "im" @ z=zeros(n,t); @ Defines place holders for data matrix "z" @ @ Each of the n rows is a stock @ @ Each of the t columns is a day @ load im[n*t,5]=daily.out; @ loads (n*t)x5 input matrix "im" @ @ from daily.out @ /********************************************************************** * 2. CREATE THE DATA MATRIX * * * * This program is coded to analyze an n x t data matrix "z". * * Each of the n rows represents a stock. * * Each of the t columns represents a day. * * * * Note: Gauss uses "(n,t)" to DEFINE a n-row, t-column matrix * * "[i,j]" to ADDRESS the element in row i, column j * **********************************************************************/ z=zeros(n,t); @ Defines place holders for data matrix "z" @ @ Each of the n rows is a stock @ @ Each of the t columns is a day @ r=1; @ "r" is row counter for input matrix @ i=1; @ "i" is stock counter @ do while i<=n; j=1; @ "j" is day counter @ do while j<=t; z[i,j]=im[r,5]; @ Assigns each succesive return in the @ @ input matrix "im[r,5]" to the appropriate @ @ place holder in the data matrix "z[i,j]" @ r=r+1; @ Adds one to the row counter for the input matrix "im" @ j=j+1; @ Adds one to the day counter (one column in the data matrix "z") @ endo; @ End of day loop @ i=i+1; @ Adds one to the stock counter (one row in the data matrix "z") @ endo; @ End of the stock loop @ /************************************************* * 3. COMPOUND RETURN (compret) * * * * compret = {[1+R(1)]*[1+R(2)]*...*[1+R(t)]}-1 * *************************************************/ x=z+1; @ Add ones to each daily return @ compret=ones(n,1); @ Define compound return vector @ i=1; @ Stock counter @ do while i<=n; j=1; @ Day counter @ do while j<=t; compret[i,1]=compret[i,1]*x[i,j]; @ Multiply returns @ j=j+1; endo; @ End day loop @ i=i+1; endo; @ End stock loop @ compret=compret-1; @ Subtract 1 to yeild a "return" @ /***************************************************** * 4. GEOMETRIC AVERAGE RETURN (garet) * * * * garet = {[1+R(1)]*[1+R(2)]*...*[1+R(t)]}^(1/t)-1 * * * * Note: garet = {(compret+1)^(1/t)}-1 * *****************************************************/ garet=ones(n,1); i=1; do while i<=n; garet[i,1]= ((compret[i,1]+1)^(1/t))-1; i=i+1; endo; /************************************************* * 5. ARITHMETIC AVERAGE RETURN (aaret) * * * * aaret = [R(1)+R(2)+...+R(t)]/t * * * * Note: The Gauss command "meanc" returns * * the means of the columns of a matrix * *************************************************/ zp=z'; @ Transpose 20x22 data matrix to 22x20 matrix @ @ since Gauss does not have a "mean row" command @ @ but does have a "mean column" command (meanc) @ aaret=zeros(n,1); @ Define Arithmetic return vector @ aaret=meanc(zp); @ Sets each row in the the column vector "aaret" @ @ equal to the mean of the corresponding column @ @ of the transposed data matrix "zp" @ /************************************************************************* * 6. EQUALY-WEIGHTED PORTFOLIO RETURN WITH REBALANCING * * * * The portfolio is composed of an equal amount of each stock. * * The portfolio's daily return is the mean of the return of each stock.* * * * The portfolio compounded return is calculated as above. * *************************************************************************/ temp1=meanc(z); @ Creates a tx1 row vector with each element equal to the @ @ mean of the coresponding column of the data matrix (z). @ @ This yields the equally-weighted daily portfolio return. @ port=temp1'; @ Transposes the column vector "temp1" to a row vector @ portx=port+1; @ Adds one to each daily return @ @ Note: the preceeding 3 lines of code could be written: @ @ port=1+meanc(z)' @ portret=1; @ Define portfoio return variable @ j=1; @ Day counter @ do while j<=t; portret=portret*portx[1,j]; @ Multiply returns @ j=j+1; endo; @ End day loop @ portret=portret-1; /****************************************** * 7. PRINT RESULTS * * * * compound returns (compret) * * geometric average returns (garet) * * arithmetic average return (aaret) * * portfoilio compounded return (portret) * * * * Print the results using a "do-loop" * * counter to identify the stocks * ******************************************/ print " Stock# Compound Geometric Arithmetic"; i=1; do while i<=n; i~compret[i,1]~garet[i,1]~aaret[i,1]; i=i+1; endo; print; @ Prints a blank line @ print; print "Equally-Weighted Portfolio Return:"; portret; end;