Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 580

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 583

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 586

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 589

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 592

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673
{"id":109,"date":"2010-12-30T17:01:50","date_gmt":"2010-12-30T17:01:50","guid":{"rendered":"http:\/\/www.calculatinginvestor.com\/"},"modified":"2011-03-24T15:07:48","modified_gmt":"2011-03-24T20:07:48","slug":"expected-return-regressions","status":"publish","type":"page","link":"https:\/\/www.calculatinginvestor.com\/octave-code\/expected-return-regressions\/","title":{"rendered":"Expected Return Regressions"},"content":{"rendered":"

Note: <\/em><\/strong>This page contains the data source links and source code used in my \u201cMarket Valuation<\/a>\u201d post.<\/em><\/p>\n

Data:<\/em><\/strong>\u00a0 The data used to run the regressions and generate the plots in the Market Valuation post comes from Robert Shiller’s website<\/a>.\u00a0 To create the “ie_data.csv” file used by the Octave script, download the latest\u00a0“ie_data.xls” file from Shiller’s website and save the “Data” sheet as a csv file with filename “ie_data.csv”.<\/p>\n

Octave Code:<\/strong>\u00a0 The Octave code used to run the regressions and generate the plots is pasted below.\u00a0 The “pause” statements after each “plot” command\u00a0cause 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.\u00a0 If you are running newer version of Octave, or running on a different platform, these pause statements can probably be removed.<\/p>\n

\r\nclear all;   % Clear all data in Octave session\r\nclose all;   % Close all open plot windows\r\n\r\n% Load data from csv file\r\npe10data = csvread('ie_data.csv');\r\npe10price = pe10data(8:end,8);\r\npe10dividends = pe10data(8:end,9);\r\npe10earnings = pe10data(8:end,10);\r\npe10ratio = pe10data(128:end,11);\r\n\r\n% Remove zeros from end of pe10dividend series and pe10ratio series\r\npe10dividends = pe10dividends(pe10dividends>0);\r\npe10ratio = pe10ratio(pe10ratio>0);\r\n\r\n% Monthly Return\r\npe10pricebegin=pe10price(1:length(pe10dividends));\r\npe10div = pe10dividends(1:end);\r\npe10priceend=pe10price(2:length(pe10dividends)+1);\r\nmonthlyreturns = (pe10div\/12 + pe10priceend).\/pe10pricebegin;\r\n\r\n% Annual Return for full years\r\nfullyears = floor(length(monthlyreturns)\/12);\r\nannualret = prod(reshape(monthlyreturns(1:fullyears*12),12,fullyears));\r\n\r\n% Arithmetic Average Annual Return\r\narith_annual = mean(annualret-1)\r\n\r\n% Geometric Average Annual Return\r\ngeo_annual = (prod(annualret))^(1\/fullyears)-1\r\n\r\n% Calculate Ten Year Returns\r\n% Start at month 121 when PE10 ratio is first available\r\nfor i = 121:(length(monthlyreturns)-120)\r\n    returnsample = monthlyreturns(i:i+120);\r\n    an10yr(i-120)=12*(mean(returnsample)-1);\r\nend\r\n\r\n% Calculate Twenty Year Returns\r\n% Start at month 121 when PE10 ratio is first available\r\nfor i = 121:(length(monthlyreturns)-240)\r\n    returnsample = monthlyreturns(i:i+240);\r\n    an20yr(i-120) = 12*(mean(returnsample)-1);\r\nend\r\n\r\n% 10 year regression, the beta10 variable has the regression coefficients\r\nT = length(pe10dividends)-240;\r\nrhv = [ones(T,1) pe10ratio(1:length(pe10dividends)-240)];\r\n[beta10 sigma10 r10]=ols(an10yr',rhv)\r\n\r\n% 20 year regression, the beta20 variable has the regression coefficients\r\nT = length(pe10dividends)-360;\r\nrhv = [ones(T,1) pe10ratio(1:length(pe10dividends)-360)];\r\n[beta20 sigma20 r20]=ols(an20yr',rhv);\r\n\r\n% Coordinates for 10yr Regression line\r\nx1_10 = min(pe10ratio(1:length(pe10dividends)-240))\r\nx2_10 = max(pe10ratio(1:length(pe10dividends)-240))\r\ny1_10 = beta10(1) + x1_10*beta10(2)\r\ny2_10 = beta10(1) + x2_10*beta10(2)\r\n\r\n% Coordinates for 20yr Regression line\r\nx1_20 = min(pe10ratio(1:length(pe10dividends)-360))\r\nx2_20 = max(pe10ratio(1:length(pe10dividends)-360))\r\ny1_20 = beta20(1) + x1_20*beta20(2)\r\ny2_20 = beta20(1) + x2_20*beta20(2)\r\n\r\n% Plot 10-year Regression\r\nplot(pe10ratio(1:length(an10yr)),an10yr,'o-');\r\npause(5);\r\ntitle('10 Year Annual Returns on 10yr CAPE Ratio','fontsize',20)\r\nylabel('20 Year Annual Returns','fontsize',20)\r\nxlabel('10yr CAPE Ratio','fontsize',20)\r\nline([x1_10 x2_10],[y1_10 y2_10],'linewidth',3,'color','r')\r\nline(xlim,[0 0],'color','black','linewidth',2)\r\nequation = strcat('Return = ',num2str(beta10(1)),num2str(beta10(2)),'*CAPE')\r\ntext(5,-0.075,equation,'fontsize',20)\r\n\r\n% Plot 20 year regression\r\nfigure;\r\nplot(pe10ratio(1:length(an20yr)),an20yr,'o-');\r\npause(5);\r\ntitle('20 Year Annual Returns on 10yr CAPE Ratio','fontsize',20)\r\nylabel('20 Year Annual Returns','fontsize',20)\r\nxlabel('10yr CAPE Ratio','fontsize',20)\r\nline([x1_20 x2_20],[y1_20 y2_20],'linewidth',3,'color','r')\r\nline(xlim,[0 0],'color','black','linewidth',2)\r\nequation = strcat('Return = ',num2str(beta20(1)),num2str(beta20(2)),'*CAPE')\r\ntext(5,-0.025,equation,'fontsize',20)\r\n\r\n% Plot time series of PE10\r\nfigure;\r\nxstep = (1:length(pe10ratio))\/12;\r\ndate = 1881 + xstep;\r\npe_running_mean = cumsum(pe10ratio).\/(1:length(pe10ratio))';\r\nplot(date,pe10ratio,date,pe_running_mean)\r\npause(5);\r\ntitle('CAPE Ratio and Running Average CAPE Ratio','fontsize',20)\r\nlegend('CAPE Ratio','CAPE Running Average')\r\nylabel('CAPE Ratio','fontsize',20)\r\nxlabel('Year','fontsize',20)\r\naxis([min(date)-5 max(date)+5])\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Note: This page contains the data source links and source code used in my \u201cMarket Valuation\u201d post. Data:\u00a0 The data used to run the regressions and generate the plots in the Market Valuation post comes from Robert Shiller’s website.\u00a0 To create the “ie_data.csv” file used by the Octave script, download the latest\u00a0“ie_data.xls” file from Shiller’s […]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":145,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/pages\/109"}],"collection":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":28,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/pages\/109\/revisions"}],"predecessor-version":[{"id":2168,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/pages\/109\/revisions\/2168"}],"up":[{"embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/pages\/145"}],"wp:attachment":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/media?parent=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}