/***************************************************************************/ /* */ /* Title: GMM.GPG */ /* */ /* Written: John H. Cochrane */ /* by: University of Chicago Graduate School of Business */ /* 1101 E. 58th Street, Rosenwald 205c */ /* Chicago, Ill 60637 */ /* ph#: (312) 702-3059 */ /* e-mail: john.cochrane@gsb.uchicago.edu */ /* */ /* Purpose: Main program for doing gmm with investment returns as factors. */ /* Sets up the proper 'switches' and datasets and passes them to */ /* doitc.g for estimation of factor premiums. */ /* */ /* Pending Modifications: */ /* - Should 1 x z be a factor? */ /* */ /* -move to term premium as instrument with prelminary regressions to verify power -add investment as instrument? */ /* market + lagged market? */ /* lagged RI in m ? lead RI in m? */ /* do unconditional crr as extra */ /* */ /* */ /* Overall structure: This proc loads data, sets switches, decides which assets instruments and model (factors) to use. Then it calls DOITC.G. DOITC.G runs GMM 1st and iterated, calling FINDJTC.G which returns gT' W gT given parameters. DOITC.G then outputs parameters, calcluates se.'s and other test statistics. _globals can be accessed anywhere, becareful with these! Regular globals should only be used by gmm.gpg and doitc. note: old .prt graphs are changed to .tkf. You can look at .prt's to see if there are changes */ /******************************************************************************/ /* ------------------------------------------------ */ /* Part I: (1) GAUSS library calls */ /* (2) reset globals on graphics, optmum */ /* (3) identify data path */ /* ------------------------------------------------ */ library pgraph,optmum,gmm; #include optmum.ext; optset; graphset; output file=gmm.out on; outwidth 250; load path = c:\j\newprod\data; save path = c:\j\newprod\data; /* ------------------------------------------------ */ /* Part II:how it runs switches */ /* ------------------------------------------------ */ terse = 1; /* 0 causes lots of printout; 1 causes less. */ nwlag = 1; /* newey west lags in test statistics. can be vector. */ step2 = 0; /* choices 1: do second-stage or iterated gmm */ /* 0: only first-stage gmm done */ ergrf = 1|1|1; /* choices 3x1 vector: (1,1)=0 or 1: view 1st stage estimates */ /* E(r) v. pred E(r) (2,1)=0 or 1: view 2st stage estimates */ /* (3,1)=0 or 1: view graph on screen */ /* you can set (3,1) to zero to make .tkf files automatically */ makgrf = 1; /* if yes, makes graphs and saves to tekfiles */ teknam = "test"; /* name of .tkf files to store graphs. e.g. makes test1.tkf */ /* and test2.tkf. */ invrcode = 1; /* choices: 1: nonres (gin) + res (gir) */ /* 2: nonres (gis+gipd) + res (gir) */ /* 3: nonres(gin) + res(gir) + consdur(gcd) */ /* 4: nonres(gis+gipd)+res(gir)+consdur(gcd) */ xtrcode = 1; /* choices: 1: no extra factors */ /* 2: market return */ /* 3: chen,roll,ross factors */ /* 4: consumption growth^gamma */ /* 5: consumption growth as pure factor */ /* 6: gin and gir alone, no investment return */ xtronly = 0; /* choices: 0: standard; inv rets + extra factors if any */ /* 1: use only extra factors. */ instcode = 1; /* choices: 1: const */ /* 2: const, def, d/p rescaled to mean,sd */ /* (only to get old stuff, use 3 in end */ /* 3: const, default, d/p scaled by hand */ /* 4: const, term, d/p scaled by hand */ factcode = 0; /* choices: 0: use unscaled factors only */ /* 1: add scaled factors */ scalextr = 1; /* choices: 0: do not scale extra factors also */ /* 1: scale extra factors as well as ri */ momcode = 0; /* choices: 0: do unconditional moments */ /* 1: use scaled returns */ whichdec = 1|2|5|10; /* which deciles to use for scaled returns? (nonscaled usesall*/ /* 1|2|3|4|5|6|7|8|9|10 does all */ pri = 1; /* choices: 1: price investment returns */ /* 0: don't price investment returns */ method = 1; /* choice on moments, b calculation. */ /* 1: Include E(m) or e(mrf) as a moment, factor levels */ /* 2: Old way. demean factors, m=1+b'(f-Ef) */ /* 3: prespecify b0 = 1 */ /* 4: just like 1; calculated by trans to cov Rf */ scalcon = 0; /* include scaled constants as factors ? */ lamS = 1; /* spectral density options. for weighting mx */ /* 1: leave unchanged */ /* 0-1: emphasize diagonal. lam*original + (1-lam)*diagonal */ /* -1 - 0: (e.g. -1/100) eliminate eigs less than lam*largest*/ /* <= -1: (e.g. -4) keep only -lam largest eigenvals */ lamW = 1; /* same options, for s matrix */ jntb = 0; /* do joint b tests ? (make sure selects set right) */ jntbc2 = 0; /* do joint b chi2 difference tests? (takes much time) */ selectv = 0; selectd = 0; slabel = 0; dlabel = 0; /* joint b tests. rows of selectv */ /* pick parameter indices to set to zero (usually 2+which b)*/ /* zeros in selectv will be removed by doitc. selectd is the*/ /* same for chi2 diff tests on joint b. s and dlabel apply */ /* labels to the test outputs */ bigrun = 1; /* redo everything */ /* IGNORES most above settings of switches; hard-wired */ doall = 0; /* temporary switch. allows you to go through bigrun but only */ /* do one of them */ /* --------------- */ /* optmum switches */ /* --------------- */ __output = 0 ; /* choices 2: display optmum iterations to screen */ /* 0: no optmum iterations on screen */ /* _opgdprc = &gradwbc; */ /* proc to take derivative of jt. is set in doitc */ @_opalgr = 2; @/* algorithm for optmum */ @_opshess = 1; @ /* 1: start w. hessian; 0: start w. I */ @_opstep = 1; @ /* 1: 1 2: STepbt 3: brent 4: half */ @_grdh = 1e-4; @ @_opgdmd = 0; @ _opgtol = 1e-4; /* tolerance for convergence. Default 1e-5 */ _opgdprc = 0; /* use proc or analytical gradients? Warning: proc only works*/ /* for mpk search; no consumption models. In general, numeric*/ /* seems to work just about as well. */ /* Warning: since switch to second moments (no demeaning factors) convergence is tricky sinc b inverts second moment matrix. findjt is written with QR algorithm for stability but still either analytical or numerical gradients are not accurate to many places, and optmum uses grad < 1e-5 as test for convergence. If it is wandering around without converging, this is the problem. */ @_opgdprc = &gradwbc;@ clearg alpha,delta,mpk,w; /* --------------------- */ /* Part III. load data */ /* --------------------- */ load avdecret,avvwret,avewret,avustret; /* old codes load GPI82, gin82, gis82,gipd82,gir82,gcd82; */ load GPI82=gpiq, gin82=ginq, gis82=gisq, gipd82=gipdq, gir82=girq, gcd82=gcdq; load qterm,qdef,qvwdp,qewdp; load MP,DEI,UI,UPR,UTS; load gcn82=gcnq,gcs82=gcsq,gpop; cns = (gcn82+gcs82)./gpop; /* ------------------------------------------ */ /* Part V. Single GMM Run or Multiple GMM Run */ /* ------------------------------------------ */ /* A. Single GMM Run (bigrun=0) */ if not bigrun ; gosub gothru; endif; /* graph effect of lambda on jt stats--simple system */ if 0; clearg jt; ergrf = 0|0|0; lamv = 1.0|0.995|0.99|0.97|0.95|0.9|0.75|0.5|0.25|0; jtv = zeros(rows(lamv),1); lindx = 1; do while lindx <= rows(lamv); lams0 = lamv[lindx]; gosub gothru; jtv[lindx] = jt; lindx = lindx + 1; endo; graphset; _plctrl = 1; _pltype = 6; xy(lamv,jtv); format /RD 12,4; lamv~jtv; endif; /* B. Multiple GMM Run (bigrun = 1) */ /* WARNING: MULTI-RUNS ARE ORDERED. All switches are not reset; only changes are made. DO NOT re-order multi-runs. To do only one of these, either set above switches with bigrun=0, or use doall=0 and add an if 1 to the one you want to run */ if bigrun; /* ------------------------------- */ /* common setup for all variations */ /* ------------------------------- */ makgrf = 1; /* 1: make graphs, save. 0: no make, no save*/ if makgrf; ergrf = 1|1|0; /* change to 1 1 0 if you don't want to watch */ else; ergrf = 0|0|0; endif; nwlag = 1; step2 = 1; invrcode = 1; cur_invr = invrcode; xtrcode = 1; xtronly = 0; pri = 1; method = 1; scalcon = 0; lamS = 1; lamW = 1; "=================================================="; " INVESTMENT MODEL "; " unconditional returns, no scaled factors "; "=================================================="; instcode = 1; factcode = 0; momcode = 0; jntb = 1; jntbc2 = 0; selectv = {3 4 5, 0 4 5, 0 0 4, 0 0 5}; slabel = "allb"|"no con"|"nonr"|"resid"; selectd = {0 4 5, 0 0 4, 0 0 5}; dlabel = "no con"|"nonr"|"resid"; teknam = "ri"; if doall; gosub gothru; endif; "=================================================="; " INVESTMENT MODEL "; " CONditional returns, no scaled factors "; "=================================================="; instcode = 4; factcode = 0 ; momcode = 1; teknam = "ricm"; if doall; gosub gothru; endif; "=================================================="; " INVESTMENT MODEL "; " CONditional returns, SCALED factors "; "=================================================="; factcode = 1; /* b numbering: 1 2 3 4 5 6 7 3 4 5 6 7 8 9 con nr r nr*t r*t nr*dp r*dp */ selectv = {3 4 5 6 7 8 9, 0 4 5 6 7 8 9, 0 0 0 0 0 4 5, 0 0 0 6 7 8 9, 0 0 0 0 4 6 8, 0 0 0 0 5 7 8}; slabel = "allb"|"no con"|"unsc"|"scaled"|"nonr"|"resid"; selectd = {0 4 5 6 7 8 9, 0 0 0 0 0 4 5, 0 0 0 6 7 8 9, 0 0 0 0 4 6 8, 0 0 0 0 5 7 8}; jntbc2 = 0; dlabel = "no con"|"unsc"|"scaled"|"nonr"|"resid"; teknam = "risfcm"; if doall or 1; gosub gothru; if makgrf; gosub grafmom; endif; endif; /* ====================================================================== */ /* 2. COMPARISONS W/ CAPM: Estimating using investment model + capm index */ /* as factors to determine which prices the returns */ /* ====================================================================== */ "==========================================================="; " CAPM ALONE" ; "==========================================================="; "======================================================"; " CAPM alone, unconditional returns, unscaled factor "; "======================================================"; /* unconditional CAPM alone */ instcode = 1; factcode = 0; momcode = 0; xtrcode = 2; xtronly = 1; jntb = 0; jntbc2 = 0; pri = 0; teknam = "cap"; if doall ; gosub gothru; endif; "======================================================"; " CAPM alone, CONditional returns, unscaled factor "; "======================================================"; instcode = 4; factcode = 0 ; momcode = 1; teknam = "capcm"; if doall ; gosub gothru; endif; "================================================"; " CAPM, CONditional returns, SCALED factor "; "================================================"; factcode = 1; scalextr = 1; /* b numbering: 1 2 3 4 con rm rm*t rm*dp */ selectv = {1 2 3 4, 0 2 3 4, 0 0 0 2, 0 0 3 4}; slabel = "allb"|"no con"|"unsc"|"scaled"; selectd = { 0 0 0 2, 0 0 3 4}; dlabel = "unsc"|"scaled"; jntb = 1; jntbc2 = 1; teknam = "capsfcm"; if doall ; gosub gothru; endif; "======================================================"; " INVESTMENT VS. CAPM "; "======================================================"; "=============================================================="; "Investment vs. CAPM, Unconditional returns, No scaled factors "; "=============================================================="; instcode = 1; factcode = 0; momcode = 0; xtronly = 0; pri = 1; /* b numbering: 1 2 3 4 3 4 5 6 con nr r rm */ selectv = {3 4 5 6, 0 4 5 6, 0 0 4 5, 0 0 0 6}; slabel = "allb"|"no con"|"ri=0"|"rm=0"; selectd = { 0 0 4 5, 0 0 0 6}; dlabel = "ri=0"|"rm=0"; teknam = "rivw"; if doall ; gosub gothru; endif; "=============================================================="; "Investment vs. CAPM, CONditional returns, UNscaled both factors "; "=============================================================="; instcode = 4; momcode = 1; factcode = 0; teknam = "ricapcm"; if doall; gosub gothru; endif; "=============================================================="; "Investment vs. CAPM, CONditional returns, SCALED factors "; "=============================================================="; instcode = 4; momcode = 1; factcode = 1; /* b numbering: 1 2 3 4 5 6 7 8 9 10 3 4 5 6 7 8 9 10 11 12 con nr r rm NRxT RxT RmxT NRxDP RxDP RmxDP*/ selectv = {3 4 5 6 7 8 9 10 11 12, 0 4 5 6 7 8 9 10 11 12, 0 0 0 0 4 5 7 8 10 11, 0 0 0 0 0 0 0 6 9 12}; slabel = "allb"|"no con"|"ri=0"|"rm=0"; selectd = {0 0 4 5 7 8 10 11, 0 0 0 0 0 6 9 12}; dlabel = "ri=0"|"rm=0"; teknam = "ricapsc"; if doall ; gosub gothru; endif; "====================================================================="; "Investment vs. CAPM, CONditional returns, SCALED RI, NON scaled Rm "; "===================================================================="; instcode = 4; momcode = 1; factcode = 1; scalextr = 0; /* b numbering: 1 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 con nr r rm NRxT RxT NRxDP RxDP */ selectv = {3 4 5 6 7 8 9 10, 0 4 5 6 7 8 9 10, 0 0 4 5 7 8 9 10, 0 0 0 0 0 0 0 6}; slabel = "allb"|"no con"|"ri=0"|"rm=0"; selectd = {0 0 4 5 7 8 9 10, 0 0 0 0 0 0 0 6}; dlabel = "ri=0"|"rm=0"; teknam = "ricpnsc"; if doall ; gosub gothru; endif; /* ======================================================= */ /* CRR Model */ /* ======================================================= */ "============================================================================="; " CRR ALONE "; "============================================================================="; "===================================================="; " CRR; unconditional returns, no scaled factors "; "===================================================="; instcode = 1; xtrcode = 3; momcode = 0; factcode = 0; xtronly = 1; jntb = 1; selectv = 2~3~4~5~6; let slabel = "no con"; jntbc2 = 0; pri = 0; teknam = "crr"; if doall ; gosub gothru; endif; "===================================================="; " CRR; CONditional returns, no scaled factors "; "===================================================="; instcode = 4; momcode = 1; factcode = 0; teknam = "crrcm"; if doall ; gosub gothru; endif; "===================================================="; " CRR; CONditional returns, SCAled factors "; "===================================================="; instcode = 4; factcode = 1; scalextr = 1; teknam = "crrsfcm"; "Too many parameters; model not tested"; /* if doall ; gosub gothru; endif; */ "============================================================================="; " INVESTMENT VS. CRR "; "============================================================================="; "=============================================================="; "Investment vs. CRR, Unconditional returns, No scaled factors "; "=============================================================="; instcode = 1; factcode = 0; momcode = 0; xtronly = 0; pri = 1; /* b numbering: 1 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 con nr r cr1 cr2 cr3 cr4 cr5 */ selectv = {3 4 5 6 7 8 9 10, 0 4 5 6 7 8 9 10, 0 0 0 0 0 0 4 5, 0 0 0 6 7 8 9 10}; slabel = "allb"|"no con"|"ri=0"|"crr=0"; selectd = {0 0 0 4 5, 6 7 8 9 10}; dlabel = "ri=0"|"crr=0"; jntb = 1; jntbc2 = 1; teknam = "ricr"; if doall ; gosub gothru; endif; "=============================================================="; "Investment vs. CRR, CONditional returns, No scaled factors "; "=============================================================="; instcode = 4; factcode = 0; momcode = 1; teknam = "ricrcm"; if doall ; gosub gothru; endif; "======================================================="; "Investment vs. CRR, CONditional returns, SCALED Factors"; "======================================================="; instcode = 4; momcode = 1; factcode = 1; scalextr = 1; /* b numbering: 1 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 con nr r cr1 cr2 cr3 cr4 cr5 9 10 11 12 13 14 15 11 12 13 14 15 16 17 nrxT rxT cr1xT cr2xT cr3xT cr4xT cr5xT 16 17 18 19 20 21 22 18 19 20 21 22 23 24 nrxDP rxDP cr1xDP cr2xDP cr3xDP cr4xDP cr5xDP */ selectv = {3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24, 0 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 5 11 12 18 19, 0 0 0 0 0 0 0 6 7 8 9 10 13 14 15 16 17 20 21 22 23 24}; slabel = "allb"|"no con"|"ri=0"|"crr=0"; selectd = { 0 0 0 0 0 0 0 0 0 4 5 11 12 18 19, 6 7 8 9 10 13 14 15 16 17 20 21 22 23 24}; dlabel = "ri=0"|"crr=0"; teknam = "ricrsc"; if doall and (rows(whichdec) >= 5); gosub gothru; endif; if rows(whichdec) < 5; "Not enough assets to do this test. increase whichdec"; endif; "====================================================================="; "Investment vs. CRR, CONditional returns, SCALED RI, NON scaled CRR "; "===================================================================="; scalextr = 0; /* b numbering: 1 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 con nr r cr1 cr2 cr3 cr4 cr5 9 10 11 12 11 12 13 14 nrxT rxT nrxDP rxDP */ selectv = {3 4 5 6 7 8 9 10 11 12 , 0 4 5 6 7 8 9 10 11 12 , 0 0 0 0 4 5 11 12 13 14, 0 0 0 0 0 6 7 8 9 10 }; slabel = "allb"|"no con"|"ri=0"|"crr=0"; selectd = { 4 5 11 12 13 14, 0 6 7 8 9 10 }; dlabel = "ri=0"|"crr=0"; teknam = "ricrnsc"; if doall ; gosub gothru; endif; "====================================================================="; " Consumption model by itself -- unconditional moments "; "====================================================================="; xtrcode = 4; xtronly = 1; instcode = 1; factcode = 0; momcode = 0; pri = 0; teknam = "c"; jntb = 0; jntbc2 = 0; if doall ; gosub gothru; endif; "====================================================================="; " Consumption model by itself -- CONditional moments "; "====================================================================="; instcode = 4; momcode = 1; teknam = "ccm"; if doall ; gosub gothru; endif; "====================================================================="; " Investment vs. consumption UNConditional, NONscaled " ; "====================================================================="; instcode = 1; factcode = 0; momcode = 0; xtronly = 0; scalxtr = 0; pri = 1; teknam = "ivsc"; jntb = 1; jntbc2 = 1; /* b numbering: b: 1 2 3 4 v: 4 5 6 7 con nr r c */ selectv = {4 5 6 7, 0 5 6 7, 0 0 5 6, 0 0 0 7 }; slabel = "all b"|"no con"|"ri=0"|"bc=0"; selectd = {0 0 5 6, 0 0 0 7 }; dlabel = "ri=0"|"bc=0"; if doall ; gosub gothru; endif; "====================================================================="; " Investment vs. consumption Conditional, NONscaled Ri, no scale c" ; "====================================================================="; instcode = 4; factcode = 0; momcode = 1; teknam = "ivccm"; if doall ; gosub gothru; endif; "====================================================================="; " Investment vs. consumption Conditional, Scaled Ri, no scale c" ; "====================================================================="; instcode = 4; factcode = 1; momcode = 1; teknam = "ivcsfcm"; /* b numbering: 1 2 3 4 5 6 7 8 4 5 6 7 8 9 10 11 con nr r c nrxT rxT nrxDP rxDP*/ selectv = {4 5 6 7 8 9 10 11, 0 5 6 7 8 9 10 11, 0 0 5 6 8 9 10 11, 0 0 0 0 0 0 0 7 }; slabel = "all b"|"no con"|"ri=0"|"bc=0"; selectd = {0 0 5 6 8 9 10 11, 0 0 0 0 0 0 0 7 }; dlabel = "ri=0"|"bc=0"; if doall ; gosub gothru; endif; "==========================================================="; " Consumption GROWTH, NOT marginal utility "; "==========================================================="; "===================================================================="; " Consumption growth alone, unconditional returns, unscaled factor "; "===================================================================="; instcode = 1; factcode = 0; momcode = 0; xtrcode = 5; xtronly = 1; jntb = 0; jntbc2 = 0; pri = 0; teknam = "cg"; if doall ; gosub gothru; endif; "===================================================================="; " Consumption Growth alone, CONditional returns, unscaled factor "; "===================================================================="; instcode = 4; factcode = 0 ; momcode = 1; teknam = "cgcm"; if doall ; gosub gothru; endif; "=============================================================="; " Consumption Growth, CONditional returns, SCALED factor "; "=============================================================="; factcode = 1; scalextr = 1; /* b numbering: 1 2 3 4 con cg cgxT cgxDP */ selectv = {1 2 3 4, 0 2 3 4, 0 0 0 2, 0 0 3 4 }; slabel = "allb"|"no con"|"unsc"|"scaled"; selectd = { 0 0 2, 0 3 4 }; dlabel = "unsc"|"scaled"; jntb = 1; jntbc2 = 1; teknam = "cgsfcm"; if doall ; gosub gothru; endif; "======================================================================="; " Ivestment vs. consumption growth, UNconditional returns UNscaled factors"; "======================================================================="; instcode = 1; momcode = 0; factcode = 0; xtronly = 0; scalxtr = 0; pri = 1; /* b numbering: con nr r cg 1 2 3 4 */ selectv = { 4 5, 0 5 }; slabel = "ri=0"|"cg=0"; selectd = selectv ; dlabel = slabel; teknam = "ricg"; if doall ; gosub gothru; endif; "======================================================================="; " Ivestment vs. consumption growth, CONditional returns UNscaled factors"; "======================================================================="; instcode = 4; momcode = 1; factcode = 0; xtronly = 0; scalxtr = 0; pri = 1; /* b numbering: con nr r cg 1 2 3 4 */ selectv = { 4 5, 0 5 }; slabel = "ri=0"|"cg=0"; selectd = selectv ; dlabel = slabel; teknam = "ricgcm"; if doall ; gosub gothru; endif; "======================================================================="; "Investment vs. Consumption growth, CONditional returns, SCALED factors "; "======================================================================="; instcode = 4; momcode = 1; factcode = 1; xtronly = 0; scalxtr = 1; pri = 1; /* b numbering: 1 2 3 4 5 6 7 8 9 10 3 4 5 6 7 8 9 10 11 12 con nr r cg NRxT RxT cgxT NRxDP RxDP cgxDP*/ selectv = {3 4 5 6 7 8 9 10 11 12, 0 4 5 6 7 8 9 10 11 12, 0 0 0 0 4 5 7 8 10 11, 0 0 0 0 0 0 0 6 9 12}; slabel = "allb"|"no con"|"ri=0"|"cg=0"; selectd = {0 0 4 5 7 8 10 11, 0 0 0 0 0 6 9 12}; dlabel = "ri=0"|"cg=0"; teknam = "ricgsc"; if doall ; gosub gothru; endif; "====================================================================="; "Investment vs. Cons GROWTH, CONditional returns, SCALED RI, NON scaled Rm "; "===================================================================="; instcode = 4; momcode = 1; factcode = 1; scalextr = 0; /* b numbering: 1 2 3 4 5 6 7 8 3 4 5 6 7 8 9 10 con nr r cg NRxT RxT NRxDP RxDP */ selectv = {3 4 5 6 7 8 9 10, 0 4 5 6 7 8 9 10, 0 0 4 5 7 8 9 10, 0 0 0 0 0 0 0 6}; slabel = "allb"|"no con"|"ri=0"|"cg=0"; selectd = {0 0 4 5 7 8 9 10, 0 0 0 0 0 0 0 6}; dlabel = "ri=0"|"cg=0"; teknam = "ricgnsc"; if doall ; gosub gothru; endif; "==========================================================="; " INVESTMENT GROWTH, NOT RETURNS"; "==========================================================="; "===================================================================="; " Investment growth alone, unconditional returns, unscaled factor "; "===================================================================="; instcode = 1; factcode = 0; momcode = 0; xtrcode = 6; xtronly = 1; jntb = 0; jntbc2 = 0; pri = 0; teknam = "ig"; if doall ; gosub gothru; endif; "======================================================"; " INV Growth alone, CONditional returns, unscaled factor "; "======================================================"; instcode = 4; factcode = 0 ; momcode = 1; teknam = "igcm"; if doall ; gosub gothru; endif; "================================================"; " INV Growth, CONditional returns, SCALED factor "; "================================================"; factcode = 1; scalextr = 1; /* b numbering: 1 2 3 4 5 6 7 con nr r ntxT rxT nrxDP r*dp */ selectv = {1 2 3 4 5 6 7, 0 2 3 4 5 6 7, 0 0 0 0 0 2 3, 0 0 0 4 5 6 7 }; slabel = "allb"|"no con"|"unsc"|"scaled"; selectd = { 0 0 0 2 3, 0 4 5 6 7}; dlabel = "unsc"|"scaled"; jntb = 1; jntbc2 = 1; teknam = "igsfcm"; if doall ; gosub gothru; endif; /* Listing of graphs: .tkf corresponds to portolio dataset; .ind */ /* correspons to individual stock dataset */ /* ri basic investment return ri2st 2nd stage gmm ricm conditional moments risf scaled factors risfcm scaled factors and conditional moments rivw basic ri + capm rivwcm ri + capm conditional moments rivwsf ri + capm uc moments, scaled factors rivwsfcm ri + capm cond moments, scaled factors ricr basic ri + CRR ricrcm ri + CRR, conditional moments ricrsf ri + CRR scaled factors ricrsfcm ri + CRR, scaled factors and conditional moments c basic consumption ccm conditional consumption */ endif; output off; end; /* ------------------------------------------ */ /* Part VI. Subroutines */ /* ------------------------------------------ */ /* ------------------------------------------------------------------------ */ /* A. GOTHRU: set up dataset - returns and factors - and calls doitc proc */ /* ------------------------------------------------------------------------ */ gothru: "----------------------------------------------------------------------"; ""; if not terse; "Algorithm used" _opalgr; endif; /* -------------------------------------------------------------------- */ /* 1. set up asset returns, instruments, investment, and extra factors */ /* -------------------------------------------------------------------- */ rf = avustret; if momcode == 0; rassetx = avdecret - avustret; "Assets = 10 deciles - UST, plus any investment returns" ; endif; if momcode == 1; rassetx = avdecret[.,whichdec] - avustret; "Assets = deciles" whichdec " - UST, plus any investment returns" ; endif; if instcode == 1; inst = 0; "No instruments"; endif; if instcode == 2; inst = qdef~qewdp; inst = 1 + .2*(inst-meanc(inst)')./(stdc(inst)'); "instruments = const, def spread, ewdp, rescaled to mean 1 sd .2"; endif; if instcode == 3; inst = qdef~(1+40*(qewdp-0.04)); "instruments = const, default spread, ewd/p, rescaled by hand"; endif; if instcode == 4; inst = qterm~(1+100*(qewdp-0.04)); "instruments = const, term spread, ewd/p, rescaled by hand"; endif; if invrcode == 1; invest = gin82~gir82; let invlbl = "nonres" "resid"; "investment series: " $invlbl'; endif; if invrcode == 2; invest = gipd82~gis82~gir82; let invlbl = "pdureqp" "strctr" "resid"; endif; if invrcode == 3; invest = gin82~gir82~gcd82; let invlbl = "nonres" "resid" "consdur"; endif; if invrcode == 4; invest = gipd82~gis82~gir82~gcd82; let invlbl = "pdureqp" "strctr" "resid" "consdur"; endif; if xtrcode == 1; xtrfact = 0; let xtrlbl = " " ; endif; if xtrcode == 2; xtrfact = avvwret; /* avvwret-rf? */ let xtrlbl = "VW ret"; @rassetx = rassetx~(avvwret-rf);@ "extra factor = " $xtrlbl ", NOT added to tested asset returns"; "remember to try avvwret-rf too "; endif; if xtrcode == 3; xtrfact = MP~DEI~UI~UPR~UTS; let xtrlbl = "MP" "DEI" "UI" "UPR" "UTS"; "extra factor = chen roll ross. UPR, UTS not added to tested returns"; endif; if xtrcode == 4; xtrfact = (gcn82+gcs82)./gpop; xtrfact = xtrfact[2:rows(xtrfact)]./xtrfact[1:rows(xtrfact)-1]; let xtrlbl = "Cons^g"; endif; if xtrcode == 5; xtrfact = (gcn82+gcs82)./gpop; xtrfact = xtrfact[2:rows(xtrfact)]./xtrfact[1:rows(xtrfact)-1]; let xtrlbl = "Cons"; endif; if xtrcode == 6; xtrfact = gin82~gir82; xtrfact = xtrfact[2:rows(xtrfact),.]./xtrfact[1:rows(xtrfact)-1,.]; let xtrlbl = "Invr,nr"; endif; /* ----------------------------------- */ /* 2. set parameters to initial values */ /* ----------------------------------- */ gosub resetp; /* --------------------------------------------------------------- */ /* 3. shorten series if you're going to use instruments, set howto */ /* --------------------------------------------------------------- */ if inst /= 0; /* need twice lagged inst: */ inst = inst[1:rows(inst)-2,.]; /* inst from 47:1 to 90:2, */ invest = invest[2:rows(invest),.]; /* others from 47:3 to 90:4 */ rassetx = rassetx[2:rows(rassetx),.]; rf = rf[2:rows(rf),.]; if xtrcode /= 1; xtrfact = xtrfact[2:rows(xtrfact),.]; endif; endif; @-@ selpar = 0|0|1; howto = 0|0|0|0|0|0|0; howto[1] = 1; /* estimate b until told otherwise */ if (factcode == 0) and (xtrcode == 1); /* nonscaled, no xtra */ howto[2] = 2; howto[4] = 0; endif; if (factcode == 0) and maxc(xtrcode .== 2|3|5|6); howto[2] = 3; /* nonscaled, vw or crr */ howto[4] = 0; endif; if (factcode == 1) and (xtrcode == 1) ; /* scaled, no xtra */ howto[2] = 2; howto[4] = 1; endif; if (factcode == 1) and maxc(xtrcode .== 2|3|5|6); /* scaled, cw or crr*/ howto[2] = 3; howto[4] = 1; endif; if (factcode == 0) and (xtrcode == 4); /* nonscaled, Ri + cons */ howto[2] = 7; endif; if (factcode == 1) and (xtrcode == 4); /* scaled, Ri + cons */ howto[2] = 8; endif; if xtronly; howto[2] = 10; /* xtr only. this overrid */ endif; /* es above. */ /* consumption cases */ if xtrcode == 4; if xtronly; howto[2] = 6; selpar = 0|0|0; endif; if (not xtronly) and (factcode == 0); howto[2] = 7; endif; if (not xtronly) and (factcode == 1); howto[2] = 8; endif; endif; howto[3] = momcode; if pri == 1; howto[5] = 0 ; /* price investment returns ? */ endif; if pri == 0; howto[5] = 1; /* don't price investment returns*/ endif; if howto[4] == 1 and (not scalextr); /* honor request not to scale extra*/ howto[4] = 2; endif; if scalcon; howto[6] = 1; endif; howto[7] = method; /* ------------------------------ */ /* 4. do GMM to find parameters */ /* ------------------------------ */ gosub doitc; /* old argument list: (alpha,delta,mpk,selpar,howto,invest,rassetx,xtrfact,inst, rf,nwlag,step2,ergrf,invlbl,xtrlbl,xtrcode, _preder,_erx,grphcode); */ return; /* ---------------------------------------------------- */ /* B. RESETP: get starting values for alpha, delta, mpk */ /* ---------------------------------------------------- */ resetp: alpha = 3; /* original starting values */ delta = .2/4; /* .15? */ mpk = 0.055052484828| 0.064221951559; if rows(alpha) == 1; alpha = alpha*ones(cols(invest),1); endif; if rows(delta) == 1; delta = delta*ones(cols(invest),1); endif; if rows(mpk) == 1; mpk = mpk *ones(cols(invest),1); endif; return; /* ----------------------- */ /* Grafmom: graphs moments */ /* ----------------------- */ /* very illuminating. shows that high precision 2nd stage estimates come from W matrices in which all attention is focussed on RI */ grafmom: {va,ve} = eighv(w); "eigenvalues of W matrix" ; format /RD 6,2; va'; "eigenvector corresp. to largest eigenvalue" ; format /RD 6,2; ve[.,rows(ve)]'; graphset; if not ergrf[3]; _Pscreen = 0; /* just for production runs */ endif; title("Eigenvalues of W matrix"); _ptek = "eigw.tkf"; _Plctrl = 1; xy(seqa(1,1,rows(va)),rev(va)); graphset; if not ergrf[3]; _Pscreen = 0; /* just for production runs */ endif; _plctrl = 1; _ptek = "wts1.tkf"; title("Portfolio weights: largest eigenvector of weighting matrix"); /* make x-axis labels */ if momcode == 0; decsel = seqa(1,1,10); else; decsel = whichdec; endif; let lab = "T-Bill"; j = 1; do while j <= rows(decsel); lab = lab| ("D" $+ ftos(decsel[j],"%*.*lf",1,0)); j = j+1; endo; lab = lab|"NR"|"R" ; j = 1; do while j <= rows(decsel); lab = lab| ("D" $+ ftos(decsel[j],"%*.*lf",1,0) $+ "xTP"); j = j+1; endo; lab = lab|"NRxTP"|"RxTP"; j = 1; do while j <= rows(decsel); lab = lab| ("D" $+ ftos(decsel[j],"%*.*lf",1,0) $+ "xDP"); j = j+1; endo; lab = lab|"NRxDP"|"RxDP"; xlabel("Moment"); ylabel("Weight"); lab3 = " " .*. ones(rows(lab),1); asclabel(lab3,0); lab2 = "-T-Bill"; i = 2; do while i <= rows(lab); lab2 = lab2 $+ "\000-" $+ lab[i]; i = i+1; endo; _pmsgstr = lab2; _pmsgctl = seqa(1.3,1,rows(ve))~(ones(rows(lab),1)*(-4~0.1~90~1~10~0)); xtics(0,rows(ve)+1,1,0); wts = ve[.,rows(ve)]; _pticout = 1; _pbartyp = 0~10; bar(seqa(1,1,rows(ve)),wts/sumc(wts)); @ xy(seqa(1,1,rows(ve)),wts/sumc(wts)); @ title("Portfolio weights: second largest eigenvector of weighting matrix"); wts = ve[.,rows(ve)-1]; _pmsgctl = seqa(1.3,1,rows(ve))~(ones(rows(lab),1)*(-2~0.1~90~1~10~0)); ytics(-2,2,1,0); _ptek = "wts2.tkf"; bar(seqa(1,1,rows(ve)),wts/sumc(wts)); title("Portfolio weights: third largest eigenvector of weighting matrix"); wts = ve[.,rows(ve)-2]; _pmsgctl = seqa(1.3,1,rows(ve))~(ones(rows(lab),1)*(-4~0.1~90~1~10~0)); ytics(-4,4,1,0); _ptek = "wts3.tkf"; bar(seqa(1,1,rows(ve)),wts/sumc(wts)); return; /* ------------------------------------------- */ /* doit subroutine included in a separate file */ /* ------------------------------------------- */ #include doitc.g;