%----------------------------------------------------------------------------- */ % subroutine doit3 loads data, handles estimation and prints estimates for model with betas */ % % called by mlest3 % % % ----------------------------------------------------------------------------- */ % organization output tables. Table1: nonstock results. Table2: results with stock. % a tables are standard errors. % numbers are columns of the respective quantity rowlbl{tablerow} = headtxt; header1 = {'$\gamma$'; '$\delta$'; '$\sigma$'; '$E ln R$'; '$\sigma ln R$'; 'ER'; '$\sigma R$'; '$\alpha$'; '$\beta$'; 'k'; 'a'; 'b';' $\pi$'}; t1gam = 1; t1delt = 2; t1sig = 3; t1ElnR = 4; t1slnr = 5; t1ER = 6; t1sR = 7; t1alphd = 8; t1beta = 9; t1k = 10; t1a = 11; t1b = 12; t1pim = 13; header1a = {'$\sigma(\gamma)$'; '$\sigma(\delta)$';'$\sigma(\sigma)$';'$\sigma(k)$';'$\sigma(a)$';'$\sigma(b)$ '; '$\sigma(\pi)$'}; t1sgam = 1; t1sdelt = 2; t1ssig = 3; t1sk = 4; t1sa = 5; t1sb = 6; t1spim = 7; table0rowlbl = {'N';'Out of bus.';'Ipo';'Acquired';'Another round';'Private +registered';'c';'d'}; % echo assumptions to output disp('***************************************************************************************************'); disp('Doit3: starting new run'); RECORD = []; % reinitialize for new run. if bankhand == 0; disp('Using bankrupt dates as is'); elseif bankhand == 1; disp('If bankrupt, interpreting as before end of sample'); elseif bankhand == 2; disp('If bankrupt, interpreting as before reported date'); end; if stockind == 0; disp('No stocks. gamma is mean.'); elseif stockind == 1; disp('Index = S&P500'); elseif stockind == 2; disp('Index = nasdaq'); elseif stockind == 3; disp('Index = nasdaq small'); elseif stockind == 4; disp('Index = zeros for debugging.'); end; if rndcode == 0; disp('merging all rounds together'); else; disp('Results for round'); disp(rndcode); end; if subsample == 1; disp('ignoring all data after 1997'); elseif subsample == 2; disp('treating all still going at end of sample as bankrupt'); end; if indcode == 0; disp('All industries together'); end; if indcode == 1; % keep industry results separate!*/ disp('Results for health industry'); disp('Includes Biopharmaceuticals, Healthcare, Medical Devices, Medical IS'); disp(' and Other Medical. ') ; end; if indcode == 2; % keep industry results separate!*/ disp('Results for information indsustry'); disp('Includes Communications, Electronics, Information Serivces, Other IT, '); disp('Semiconductors and software.') ; end; if indcode == 3; % keep industry results separate!*/ disp('Results for retail and cons/bus prod/services industry'); disp('Includes Consumer Products, Consumer Services, Retailers'); end; if indcode == 4; % keep industry results separate!*/ disp('Results for other industry'); end; if roundret == 1; disp('Using round to round returns. Only last round gets ipo return'); else; disp('Using round to IPO/Acquisition returns. Returns overlap for same company!'); end; if dok ==1; disp('Doing model with k, bankruptcy'); end; if dok == 0; disp('Doing model without k, no bankruptcy'); end; disp('minage parameter'); disp(minage); if del60; disp('treating as missing date all rounds that take less than 60 days to another round, ipo, or acquisition'); else; disp('using all rounds, even those that take less than 60 days'); end; if deltop4 == 1; disp('deleting 4 huge returns'); else; disp('keeping all returns, even 4 huge'); end; % specify initial parameter values. To be fair, start from same values */ if 1; gam0 = 0.01; delt0 = 1.5; sig0 = 0.9; k0 = 0.10; a0 = 1; b0 = 3; pim0 = 0.01; end; if stockind == 0; delt0 = 0; end; lvgrid = (valbot:valstep:valrng)';% initialize grid for values */ % ---------------------- */ % load data and clean it */ % ---------------------- */ if stockind > 0; % 0 is code for no stock index. % load monthly S&P and Tbill data */ load sp500.txt; z = sp500; spdate = z(:,1) + z(:,2)/12; % decimal date. end of month so */ % 12/31/97 = 1998. this is ok. */ spind = z(:,3); % create return series */ begindx = find(spdate==1987); endindx = find(spdate==2000.5); dates = (begindx:12*h:endindx)'; logspret = log(spind(dates(2:rows(dates)))./spind(dates(1:rows(dates)-1))); % the first element of logspret is now the return from dec 31 87 to % march 31 87, etc. This has only been checked for h=0.25, quarterly!*/ % load nasdaq data */ load nasdaq.prn; z = nasdaq; % create quarterly returns starting Q1 1987, */ % select Dec31, mar31, etc. */ dates = (12:3:rows(z))'; nd1 = z(dates, 3); % small nasdaq index */ nas = z(dates, 4); % nasdaq total return */ nind = z(dates, 9); % economagic nasdaq index */ clear z; T = rows(nd1); nd1 = nd1(2:T)./nd1(1:T-1); nas = nas(2:T)./nas(1:T-1); nind = nind(2:T)./nind(1:T-1); nd1(T-3:T-1) = nind(T-3:T-1); nas(T-3:T-1) = nind(T-3:T-1); % pad out crsp with index. */ if stockind == 1; disp('Using S&P500 for betas'); elseif stockind == 2; disp('Using Nasdaq for betas'); logspret = log(nas); elseif stockind == 3; disp('Using Nasdaq small for betas'); logspret = log(nd1); elseif stockind == 4; disp('Using zeros for betas'); logspret = 0*logspret; elseif stockind == 5; load jcdecew; logspret = log(jcdecew(:,1)); % use equally weighted, < 2 million -- the most extreme. Tried :,2 EW 5 Million and was almost same. end; % load t bill data */ load tb3ms.txt; z = tb3ms; tbdat = floor(z(:,1)); % convert from e.g. 1987.02 to 1987+1/12 */ tbdat = tbdat + ((z(:,1)-tbdat)*100-1)/12; tbrat = z(:,2); clear z; indxs = (1:3:rows(tbrat))'; indxs = find(indxs < rows(tbrat)); logrf = log(1+tbrat(indxs)/400); % use first month of the quarter to get % tbrat for the whole quarter, convert to % gross quarterly rate of return */ % Tbrat is now conformable to logspret */ % Jan 87 is first; compares to 1st q stock*/ logrf = logrf(1:54); % cuts off jun 2000 rf, since no 3d q data*/ % for other stuff -- rf is forward looking*/ if stockind == 4; logrf = 0*logrf; end; end; % ends if stockind > 0 if stockind == 0; logrf = NaN; % these series are not used; initializing them will keep program calls from bombing. logspret = NaN; end; % load venture one data */ load returns.txt; x = returns; clear returns; xlbl = ' co num ind num seg num rnd dat amnt rsd val post xit dat xit typ xit val gros ret '; % % cmpnyn = x(:,1); % company number */ % indnum = x(:,2); % industry number */ % segnum = x(:,3); % segment number */ % rnddat = x(:,4); % round date */ % raised = x(:,5); % amount raised */ % postvl = x(:,6); % value post financing */ % xitdat = x(:,7); % date of exit, ipo, aquisition, etc. */ % xittyp = x(:,8); % exit type. 1 = ipo 2=acquisition 3=out of bus % 4 = private 5 = registered ipo, not complete*/ % 6 is added below to code for another round, and return refers to round to round return % -99 unknown % xitval = x(:,9); % value after exit */ % rturns = x(:,10);% gross return */ % flagpct= x(:,11); % 1 if investors own >100 <0 of firm */ % postipo= x(:,12); % 1 if a round occurs after ipo */ % ipo60 = x(:,13); % 1 if ipo occurs within 60 days */ % xdlabel = ' co. no. ind no. seg no. round date amt raised post value exit date exit typ post value gross ret '; if quick; disp('Using 250 data points only to study logic'); x = x(1:250,:); end; % select for round and industry % and/or compute round-to-round return, only use IPO return for final round % This must come before any reordering!! if (roundret == 1)|(rndcode > 0); % determine round by seeing if last company is same as this one */ roundno = zeros(rows(x),1); roundno(1) = 1; i = 2; while i <= rows(x); if x(i,1) == x(i-1,1); % same company */ roundno(i) = roundno(i-1)+1; if ddate(x(i,4)) < ddate(x(i-1,4)); disp('Doit3 Error: an earlier round appears after a later round. look at x(i) i='); disp(i); end; else; roundno(i) = 1; end; % compute round to round returns if this is a second or higher round if roundret & (roundno(i) > 1); % Return to investors of previous round: % (Post(2) value - (2) amount raised) = total value at (2) to all investors of round 1, previous rounds % (Amount raised (1) / Post(1) value) = fraction of firm owned by round 1 investors after round 1 % (Post(2) value - (2) amount raised) * (Amount raised(1) / Post(1) value) = total value at (2) to round 1 investors % (Post(2) value - (2) amount raised) * (Amount raised(1) / Post(1) value) / ((1) amount raised) = gross return to 1 investors % or, more directly % (Post(2) value - (2) amount raised) / Post(1) value = gross return to 1 investors (and all others in that period) if (x(i,6) >0)&(x(i,5)>0)&(x(i-1,6)>0); x(i-1,10) = (x(i,6) - x(i,5))/x(i-1,6); % Assing round to round return to last round elseif (x(i,6)>0)&(x(i,5)>0)&(x(i,6) == x(i,5)); % value pre = value post in this round, so last round got nothing x(i-1,10) = 0; else; x(i-1,10) = -99; % numbers were wrong, so we know there was another round, but can't do return end; % date of exit for investors of previous round x(i-1,7) = x(i,4); % last round's date of exit = this round date % exit type for previous round x(i-1,8) = 6; % NEW CODE: 6 = there is another round % exit value for previous round -- this should not be used, but just in case x(i-1,9) = x(i,6); end; i = i+1; end; % select data for this round only if so desired if rndcode > 0; x = x(roundno == rndcode,:); if isempty(x); disp('No data points with rounds ='); disp(rndcode); end; end; end; if indcode > 0; % select industry */ x = x(find(x(:,2) == indcode),:); if isempty(x); disp('doit3 ERROR: missing values in x. Is industry code ok?'); end; end; % select end of sample treatment, if any. if subsample == 1; % code to ignore all data post 1997 x = x(find(ddate(x(:,4)) < 1997),:); % only keep rounds started before 1997. x( find(ddate(x(:,7)) >= 1997),8) = 4; % all exits post 1997 reassigned to still private x( find(ddate(x(:,7)) >= 1997),9) = NaN; % make sure you don't use value, return numbers for post 1997 exits x( find(ddate(x(:,7)) >= 1997),10) = NaN; end; if subsample == 2; % change everyone still private at end of sample to bankrupt at end of sample x(find(x(:,8) == 4), 7) = 20000630; % change all private codes to out of business at end of sample x(find(x(:,8) == 4), 8) = 3; % change all private codes to out of business codes x(find(x(:,8) == 5), 7) = 20000630; % change all private codes to out of business at end of sample x(find(x(:,8) == 5), 8) = 3; % change all private codes to out of business codes end; disp('There are data points in this estimation before cleaning = '); disp(rows(x)); if rows(x) > 0; xlbl = 1:1:10; % label for printing out data rows */ % ----------------------------------- */ % generic filters and trans3formations */ % ----------------------------------- */ x(:,10) = x(:,10).*(x(:,8) ~= 3) ; % assign zero return to all out of business rounds -- kept for security, but not used*/ disp('elminated observations with unknown fate:'); disp(sum(x(:,8)==-99)); x = x(find(x(:,8)~=-99),:); disp('Eliminated observations with >100% or <0% shareholder value'); disp(sum(x(:,11)==1)); x = x(find(x(:,11)~=1),:); if del60; disp('treating as missing date observations with new event < 60 days past investment round'); indx = find((x(:,7)~=-99)&(x(:,4)~=-99)&(ddate(x(:,7))-ddate(x(:,4))) <= 2/12); disp(rows(indx)); x(indx,7) = -99; test = find( (x(:,7)~=-99)&(x(:,4)~=-99)&(x(:,13)==1)); if rows(test) >0; disp('doit3 error -- disagreement between x(13) and direct test'); end; end; % NOTE: if not del60, some observations have end dates equal or even before round date; % others have 2 week or less dates. Sim must take care of this disp('Eliminated observations with missing round date'); disp(sum(x(:,4)==-99)); x = x(find(x(:,4)~=-99),:); disp('Note. Beta procedure -- cannot handle missing round date, so eliminating those.'); disp('Eliminating observations that start '); disp(' in second quarter 2000. Need one quarter lag for probability.'); disp(sum(ddate(x(:,4)) >= 2000.25)); x = x(ddate(x(:,4)) < 2000.25,:); disp('If out date is before or equal to begin date, treat out date as missing. This affects'); indx = find((x(:,7) ~=-99) & (ddate(x(:,7)) <= ddate(x(:,4)))); disp(rows(indx)); x(indx,7) = -99*ones(rows(indx),1); disp('Relabeling all ipo, acquisition or new round with zero return as out of business. This affects'); indx = find( (x(:,10)==0) & (x(:,8)~=3) ); disp(rows(indx)); x(indx,8)=3*ones(rows(indx),1); if deltop4 == 1; ; disp('deleting observations with > 300x returns.'); disp(rows(x(x(:,10)>300,:))); %disp(x(x(:,10)>200,:)); to see what you're doing here x = x(x(:,10)<=300,:); % these are hand checked and all are data errors. ALways delete. end; annualogret = zeros(rows(x),1); for i=1:rows(x); if (x(i,7)>0)&(x(i,10)>0); annualogret(i) = log(x(i,10))/(ddate(x(i,7))-ddate(x(i,4))); end; end; % uncomment to see huge annualized returns %[trash indx] = sort(annualogret); %disp( [ x(indx(end-20:end),1:10) annualogret(indx(end-20:end))]); disp('deleting observations with log annualized return greater than 15'); indx = find(annualogret > 15); disp(rows(indx)); x(indx,:) = []; % should elminiate 3536: Juniper. Hand check showed it's a bad data point Nx = rows(x); for trial = 1:bootstrap; if bootstrap > 1; disp('*************** bootstrap trial number ***************'); disp(trial); end; if trial> 1; % first trial is base case x = x(floor(Nx*rand(Nx,1))+1,:); % bootstrap observations disp('reshuffling x'); end; disp('Remaining data:'); disp(rows(x)); table0(1,tablerow) = rows(x); % table is organized prime x = sortrows([ddate(x(:,4)) x],1); % sort observations by initial date so observations can */ x=x(:,2:cols(x)); % share a simulation with stock returns in it*/ fi = sum(x(:,8)==1)/rows(x)*100; fa = sum(x(:,8)==2)/rows(x)*100; fb = sum(x(:,8)==3)/rows(x)*100; freg = sum((x(:,8)==5))/rows(x)*100; fp = sum(x(:,8)==4)/rows(x)*100; fsr = sum(x(:,8)==6)/rows(x)*100; fu = 100-(fi+fa+fb++freg+fp+fsr); fu2 = sum(x(:,8)==-99)/rows(x)*100; disp('Note: following refers to round, not company. Round may end in another round, though company eventually goes public'); disp('Percent bankrupt'); disp(fb); disp('Percent ipo'); disp(fi) disp('Percent acquired'); disp(fa); disp('Percent with subsequent round'); disp(fsr); disp('Percent Private'); disp(fp); disp('Percent Ipo registered'); disp(freg); disp('Percent fate unknown'); disp([fu fu2]); table0(2, tablerow) = fb; table0(3, tablerow) = fi; table0(4, tablerow) = fa; table0(5, tablerow) = fsr; table0(6, tablerow) = fp+freg; % ignore ipo registered info% % --------------------------------------------------- % assign parameters that come from data directly */ % --------------------------------------------------- % This must match selection criteria in findlk3 c = sum((x(:,8)==3) & (x(:,7)~= -99)... % & (ddate(x(:,7)) > (ddate(x(:,4))+minage))... )/sum((x(:,8) == 3)); disp('Percent of bankrupt have good data. Using this parameter in simulation'); disp('Note: good means round date and exit date not -99'); disp(100*c); d = sum( ((x(:,8) == 1) | (x(:,8) ==2) |(x(:,8) == 5)| (x(:,8) == 6) ) &... % ip, acquired, ipo registered, another round ((x(:,7)~=-99))&... %(ddate(x(:,7)) > (ddate(x(:,4))+minage)) &... % good initial round date, good exit date (x(:,10) > 0)... )/... sum( ((x(:,8) == 1) | (x(:,8) == 2) | (x(:,8) == 5) | (x(:,8) == 6) )... ); disp('Percent of new valuation (ipo,acquired,new round) that have good data. Using this parameter in simulation.'); disp('Note: good means final date not -99, return not missing or 0'); disp(100*d); STOP; % ----------------------- % minimize likelyhood */ % ----------------------- if 1; xc = xcase(x,minage,lvgrid,bankhand,stockind,dok); % does as much of findlk as you can without parameters which = ones(7,1); % which of gamma, delta, sigma, k, a, b, pim to include in tpars. if dok == 0; which(4) = 0; %no k end; if nopi == 1; which(7) = 0; % no pim pim0 = 0; end; if stockind == 0; which(2) = 0; % no delta end; if imposea == 1; which(1) = 0; % no gamma. NOTE: which(1)=0 is the code to all following programs to impose alpha = 0. If you want to use it for something else, reprogram! end; tpar0 = trans3(gam0,delt0,sig0,k0,a0,b0,pim0,which); % initial values % case with no stock is handled by forcing delta = 0. % OLD CODE from when k was a step function and likelyhood was % discontinuous in k, hence needed to keep k on grid. New approach has % liklyhood continuous in k so this is not needed. % This still may be needed if you go back to jc search or fminsearch. % Current code only tested with fminunc. % % if stockind == 0; % where is k in transformed parameter vector? If no beta, then k moves up one % kindx = 3; % else; % kindx = 4; % end; % tpar0(kindx) = snaptogrid(tpar0(kindx),lvgrid); % forces k halfway between gridpoints. objective is a sawtooth function of k with peaks at gridpoints % % to handle this, k is always evaluated halfway between gridpoints. % % dx = trans3(gam0+0.01,delt0+0.05,sig0+0.05,k0,a0+0.1,b0+0.1,top,bot,stockind,dok)-tpar0; % dx size for derivatives. Note large to deal with nonsmooth objective % % with stockind = 0 % dx(kindx) = 2*(lvgrid(2)-lvgrid(1)); % force k derivative to be two gridpoints wide % % xtol = trans3(gam0+0.01,delt0+0.05,sig0+0.05,k0+0.01,a0+0.2,b0+0.5,top,bot,stockind,dok)-tpar0; % xtol(kindx) = 2.2*(lvgrid(2)-lvgrid(1)); % % tolerance value for convergence should be larger than dx! % xtol = max([xtol'; 2*dx'])'; % make sure tolearnce is larger than two dx steps. Keeps you from batting around dx at a time. Reduce dx instead. % These options have not been tested recently. Currently, only fminunc % is up to date % % if 0; % jc search % [tparfin,lklyfin,hessb,grd] = hessmin('findlk3',tpar0,dx,xtol,kindx,lvgrid,stockind,... % hessmin is the call to the minimizer % x,logrf,logspret,minage,c,d,h,lvgrid,maxT,top,bot,bankhand,stockind); % these are the variables to varargin, passed to findlk3 % end; % if 0; % matlab grid search this works ok, but requires the larger tolerances not to take forever, and then gives hessians with negative eigenvalues. % if max(tpar0 == 0); % disp('doit3 warning: an initial value is zero. better to send nonzero guesses to fminsearch.'); % end; % options = optimset('Display','iter','TolX',0.05,'TolFun',.001); % [tparfin,lklyfin,exitflag,outputstr] = fminsearch(@findlk3,tpar0,options,... % x,xc,logrf,logspret,minage,c,d,h,lvgrid,maxT,top,bot,bankhand,stockind,dok); % lklyfin = lklyfin; % [hessb, grd] = hesscalc('findlk3',tparfin,dx,... % x,xc,logrf,logspret,minage,c,d,h,lvgrid,maxT,top,bot,bankhand,stockind,dok); % hessb = hessb; % grd = grd; % end; if 1; % matlab derivative search. options = optimset('Display','iter','LargeScale','off',... 'MaxFunEvals',2000,'MaxIter',1000,'TolX',0.001,'TolFun',0.01); % selected default values (see optimget('fminunc')) % Diagnostics: 'off' % DiffMaxChange: 0.1 % DiffMinChange: 1e-008 note 'DiffMinChange',.001, led to % infinite loop with 1E-32 stepsize but large gradient % Display: 'final' % LargeScale: 'on' % MaxFunEvals: '100*numberofvariables' % MaxIter: 400 % TolFun: 1e-006 % TolPCG: 0.1 % TolX: 1e-006 % TypicalX: 'ones(numberofvariables,1)' [tparfin,lklyfin,exitflag,outputstr,grd,hessb] = fminunc(@findlk3,tpar0,options,... x,xc,logrf,logspret,minage,c,d,h,lvgrid,maxT,which,bankhand,stockind,dok); end; [gam,delt,sig,k,a,b,pim] = back3(tparfin,which); if which(1) == 0; % this is used as code to impose alpha = 0; if stockind == 0; gam = log(1+(15/400))-1/2*sig^2 ; % this will force ER = 15% annually elseif stockind == 1; mlogrf = mean(logrf); mum = mean(logspret); sigm = std(logspret) gam = -log( exp(delt*(mum-mlogrf)+1/2*delt^2*sigm^2+1/2*sig^2)*... (1+(exp(delt*sigm^2)-1)*(exp(-(mum-mlogrf)-1/2*sigm^2)-1)/(exp(sigm^2)-1))); % this reverse engineers the formula use to calculate alpha so it will be 0 else; disp('doit3 error, alpha 0 and stock > 1'); end; end; disp('initial and final parameters'); disp([gam0 delt0 sig0 k0 a0 b0 pim0]); disp([gam delt sig k a b pim]); % ----------------------- */ % compute standard errors */ % ----------------------- */ % now invert hessian, compute standard errors */ if det(hessb) == 0; disp('hessb is singular. Will bomb. Try using generalized inverse'); else; hessbi = inv(hessb); end; ste = diag(hessbi); if max(ste<0); disp('Error. ste has negative standard errors. Using abs '); end; ste = abs(ste).^0.5; % pad out standard error vector for parameters that aren't estimated stebig = NaN*zeros(7,1); cntr = 1; for i = 1:7; if which(i) == 1; stebig(i) = ste(cntr); cntr = cntr+1; end; end; ste = stebig; % adjust for the fact that likelyhood is a function of transformed params */ midgrad = dpdt3(gam,delt,sig,k,a,b,pim); % d parameter / d transformed par*/ testsave = TEST; % just done to print out most influential observation disp('looking for most influential observations'); TEST = 2; format bank; lkly0 = findlk3(tparfin,x,xc,logrf,logspret,minage,c,d,h,lvgrid,maxT,which,bankhand,stockind,dok); % findlk3 does the printing when TEST=2 TEST = testsave; end; % -------------- */ % REPORT RESULTS */ % -------------- */ disp(' Table . Maximum Likelyhood estimates'); disp(' A. Parameter Estimates and Standard Errors'); disp('Parameter estimate std err'); if stockind == 0; disp(' mu % '); disp([100*gam/h 100*midgrad(1)*(ste(1))/h]); table1(tablerow,t1gam) = 100*gam/h ; table1a(tablerow,t1sgam) = 100*midgrad(1)*(ste(1))/h; table1(tablerow,t1delt) = 0; table1a(tablerow,t1sdelt) = -99; end; if stockind > 0; disp(' gamma % '); disp([100*gam/h 100*midgrad(1)*(ste(1))/h]); disp(' delta '); disp([delt midgrad(2)*(ste(2))]); table1(tablerow,t1gam) = 100*gam/h; table1a(tablerow,t1sgam) = 100*midgrad(1)*(ste(1))/h ; table1(tablerow,t1delt)= delt; table1a(tablerow,t1sdelt) = midgrad(2)*(ste(2)); end; disp(' sig % '); disp([100*sig/h^0.5 100*midgrad(3)*(ste(3))/h^0.5]); table1(tablerow,t1sig) = 100*sig/h^0.5 ; table1a(tablerow,t1ssig) = 100*midgrad(3)*(ste(3))/h^0.5; if dok == 1; disp(' k % '); disp([100*k 100*midgrad(4)*(ste(4))]); table1(tablerow,t1k) = 100*k; table1a(tablerow,t1sk) = 100*midgrad(4)*(ste(4)); end; disp(' a '); disp([a midgrad(5)*(ste(5))]); disp(' b '); disp([b midgrad(6)*(ste(6))]); disp('pim * 100'); disp([ 100*pim 100*midgrad(7)*(ste(7))]); disp(' c '); disp(c); disp(' d '); disp(d); table1(tablerow,t1a) = a; table1(tablerow,t1b) = b; table1(tablerow,t1pim) = 100*pim; table1a(tablerow,t1sa) = midgrad(5)*(ste(5)); table1a(tablerow,t1sb) = midgrad(6)*(ste(6)); table1a(tablerow,t1spim) = 100*midgrad(7)*ste(7); table0(7,tablerow) = 100*c; table0(8,tablerow) = 100*d; disp('log likelyhood'); disp(-lklyfin); disp('gamma and sigma are reported on an annualized basis - 4*gamma and 2*sigma. pim is times 100'); if stockind == 0; disp('Implied mean and sd of return levels'); ER = 400*(exp(gam+1/2*sig^2)-1); disp(ER); disp(200*((ER/400+1)*(exp(sig^2)-1)^0.5)); table1(tablerow,t1ER) = ER; table1(tablerow,t1sR) = 200*((ER/400+1)*(exp(sig^2)-1)^0.5); table1(tablerow,t1ElnR) = 400*gam; table1(tablerow,t1slnr) = 200*sig; table1(tablerow,t1alphd) = -99; table1(tablerow,t1beta) = -99; end; if stockind > 0; disp('Implied Er sigr ER alpha and beta'); mlogrf = mean(logrf); mum = mean(logspret); sigm = std(logspret) disp('Using parameters (annualized percentages) ElogRf, ElogRm, sigmalogRm '); disp([400*mlogrf 400*mum 200*sigm]); disp(' beta is at a quarterly frequency, alpha is annualized'); Elnr = gam + mlogrf + delt*(mum - mlogrf); % mean and sd of quarterly log returns. siglnr = (delt^2*sigm^2 + sig^2)^0.5; disp('Implied mean and sd of log returns (annualized)'); disp([400*Elnr 200*siglnr]); table1(tablerow,t1ElnR) = 400*Elnr; table1(tablerow,t1slnr) = 200*siglnr; ER = 400*(exp(Elnr+1/2*siglnr^2)-1); disp('Implied mean and sd of return levels (annualized)'); disp([ ER 200*((ER/400+1)*(exp(siglnr^2)-1)^0.5)]); table1(tablerow,t1ER) = ER; table1(tablerow,t1sR) = 200*((ER/400+1)*(exp(siglnr^2)-1)^0.5); % used to check formula for gamma to give alpha = 0. % gamstar = -log( exp(delt*(mum-mlogrf)+1/2*delt^2*sigm^2+1/2*sig^2)*... % (1+(exp(delt*sigm^2)-1)*(exp(-(mum-mlogrf)-1/2*sigm^2)-1)/(exp(sigm^2)-1))); % % betstar = exp(gamstar+(delt-1)*(mum-mlogrf)+1/2*sig^2+1/2*(delt^2-1)*sigm^2)*... % (exp(delt*sigm^2)-1)/(exp(sigm^2)-1); % alphstar = exp(mlogrf)*((exp(gamstar+delt*(mum-mlogrf)+1/2*delt^2*sigm^2+1/2*sig^2)-1)... % -betstar*(exp(mum-mlogrf+1/2*sigm^2)-1)); if sigm>0; bet = exp(gam+(delt-1)*(mum-mlogrf)+1/2*sig^2+1/2*(delt^2-1)*sigm^2)*... (exp(delt*sigm^2)-1)/(exp(sigm^2)-1); alph = exp(mlogrf)*((exp(gam+delt*(mum-mlogrf)+1/2*delt^2*sigm^2+1/2*sig^2)-1)... -bet*(exp(mum-mlogrf+1/2*sigm^2)-1)); disp('alpha') ; disp(400*alph); disp('beta '); disp(bet); table1(tablerow,t1alphd) = 400*alph; table1(tablerow,t1beta) = bet; end; alph = gam + 1/2*delt*(delt-1)*sigm^2 + 1/2*sig^2; disp('Continuous time alpha (q) (a) (in percent) '); disp([100*alph 400*alph]); disp('correlation matrix of estimated parameters'); disp(hessbi./(diag(hessbi)*diag(hessbi)').^0.5); end; save mlest3; % save whole shebang for debugging disp('NOTE: Doit3 is incrementing tablerow'); tablerow = tablerow+1; % for next call to doit3; end; % ends bootstrap iteration end; % ends if rows(x)>0