Expected Return Regressions
Note: This page contains the data source links and source code used in my “Market Valuation” post.
Data: The data used to run the regressions and generate the plots in the Market Valuation post comes from Robert Shiller’s website. To create the “ie_data.csv” file used by the Octave script, download the latest “ie_data.xls” file from Shiller’s website and save the “Data” sheet as a csv file with filename “ie_data.csv”.
Octave Code: The Octave code used to run the regressions and generate the plots is pasted below. The “pause” statements after each “plot” command cause the script to run slowly, but they were necessary to prevent lockup of the plot windows when running the script in Octave version 3.2.4 on Windows XP. If you are running newer version of Octave, or running on a different platform, these pause statements can probably be removed.
clear all; % Clear all data in Octave session close all; % Close all open plot windows % Load data from csv file pe10data = csvread('ie_data.csv'); pe10price = pe10data(8:end,8); pe10dividends = pe10data(8:end,9); pe10earnings = pe10data(8:end,10); pe10ratio = pe10data(128:end,11); % Remove zeros from end of pe10dividend series and pe10ratio series pe10dividends = pe10dividends(pe10dividends>0); pe10ratio = pe10ratio(pe10ratio>0); % Monthly Return pe10pricebegin=pe10price(1:length(pe10dividends)); pe10div = pe10dividends(1:end); pe10priceend=pe10price(2:length(pe10dividends)+1); monthlyreturns = (pe10div/12 + pe10priceend)./pe10pricebegin; % Annual Return for full years fullyears = floor(length(monthlyreturns)/12); annualret = prod(reshape(monthlyreturns(1:fullyears*12),12,fullyears)); % Arithmetic Average Annual Return arith_annual = mean(annualret-1) % Geometric Average Annual Return geo_annual = (prod(annualret))^(1/fullyears)-1 % Calculate Ten Year Returns % Start at month 121 when PE10 ratio is first available for i = 121:(length(monthlyreturns)-120) returnsample = monthlyreturns(i:i+120); an10yr(i-120)=12*(mean(returnsample)-1); end % Calculate Twenty Year Returns % Start at month 121 when PE10 ratio is first available for i = 121:(length(monthlyreturns)-240) returnsample = monthlyreturns(i:i+240); an20yr(i-120) = 12*(mean(returnsample)-1); end % 10 year regression, the beta10 variable has the regression coefficients T = length(pe10dividends)-240; rhv = [ones(T,1) pe10ratio(1:length(pe10dividends)-240)]; [beta10 sigma10 r10]=ols(an10yr',rhv) % 20 year regression, the beta20 variable has the regression coefficients T = length(pe10dividends)-360; rhv = [ones(T,1) pe10ratio(1:length(pe10dividends)-360)]; [beta20 sigma20 r20]=ols(an20yr',rhv); % Coordinates for 10yr Regression line x1_10 = min(pe10ratio(1:length(pe10dividends)-240)) x2_10 = max(pe10ratio(1:length(pe10dividends)-240)) y1_10 = beta10(1) + x1_10*beta10(2) y2_10 = beta10(1) + x2_10*beta10(2) % Coordinates for 20yr Regression line x1_20 = min(pe10ratio(1:length(pe10dividends)-360)) x2_20 = max(pe10ratio(1:length(pe10dividends)-360)) y1_20 = beta20(1) + x1_20*beta20(2) y2_20 = beta20(1) + x2_20*beta20(2) % Plot 10-year Regression plot(pe10ratio(1:length(an10yr)),an10yr,'o-'); pause(5); title('10 Year Annual Returns on 10yr CAPE Ratio','fontsize',20) ylabel('20 Year Annual Returns','fontsize',20) xlabel('10yr CAPE Ratio','fontsize',20) line([x1_10 x2_10],[y1_10 y2_10],'linewidth',3,'color','r') line(xlim,[0 0],'color','black','linewidth',2) equation = strcat('Return = ',num2str(beta10(1)),num2str(beta10(2)),'*CAPE') text(5,-0.075,equation,'fontsize',20) % Plot 20 year regression figure; plot(pe10ratio(1:length(an20yr)),an20yr,'o-'); pause(5); title('20 Year Annual Returns on 10yr CAPE Ratio','fontsize',20) ylabel('20 Year Annual Returns','fontsize',20) xlabel('10yr CAPE Ratio','fontsize',20) line([x1_20 x2_20],[y1_20 y2_20],'linewidth',3,'color','r') line(xlim,[0 0],'color','black','linewidth',2) equation = strcat('Return = ',num2str(beta20(1)),num2str(beta20(2)),'*CAPE') text(5,-0.025,equation,'fontsize',20) % Plot time series of PE10 figure; xstep = (1:length(pe10ratio))/12; date = 1881 + xstep; pe_running_mean = cumsum(pe10ratio)./(1:length(pe10ratio))'; plot(date,pe10ratio,date,pe_running_mean) pause(5); title('CAPE Ratio and Running Average CAPE Ratio','fontsize',20) legend('CAPE Ratio','CAPE Running Average') ylabel('CAPE Ratio','fontsize',20) xlabel('Year','fontsize',20) axis([min(date)-5 max(date)+5])