% This programs was wrotten by Shengying Li, % ph.d. student of Stony Brook University. % lshengyi@cs.sunysb.edu % Date of release: May 13, 2004 % % % Copyright (c) 2004 by Shengying Li % % Permission is granted to use and distribute the program for research or educational usage. % You can copy or modificate the program as you want, once this permission notice is % preserved on all copies. % % Please read the readme file before you use it. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Read input file % load price of 50 stocks load stock.txt % load price of indices load index.txt % compute return value to stk and ind Srow0 = size(stock,1); Srow = Srow0-1; Scol = size(stock,2); Irow = Srow+1; Icol = size(index,2)+1; stockreturn = zeros(Srow, Scol); indexreturn = ones(Irow, Icol); for i=1:Srow for j=1:Scol stockreturn(i,j) = stock(i,j)/stock(i+1,j)-1; end end % Set the title indexreturn(1,1) = 0; for j=2:Icol indexreturn(1,j)=j-1; end for i=2:Irow for j=2:Icol indexreturn(i,j) = index(i-1,j-1)/index(i,j-1)-1; end end %Compute size column by IDSOX-IDLOX for i=2:Irow indexreturn(i,Icol-1)=indexreturn(i,Icol-1)-indexreturn(i,Icol); end Icol=Icol-1; % Initialize the out matrix Out=zeros(Scol,Icol+1); for Si=1:Scol Y = stockreturn(:,Si); Aold = indexreturn(:,1:Icol); Anew = Aold(2:Irow,:); %initial model X = Anew\Y; Ypredict = Anew*X; Ydev = Ypredict-Y; R2=1-(std(Ydev)/std(Y))^2; R2adj=1-(1-R2)*(Srow-1)/(Srow-Icol-1-1); % Fill the out matrix for i=1:Icol Out(Si,i)=X(i); end Out(Si, Icol+1)=R2adj; end % Output file save risksimple Out -ascii