{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

oxdk_day5b - Advanced Programming in Quantitative Economics...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Advanced Programming in Quantitative Economics Introduction, structure, and advanced programming techniques 17 – 21 August 2009, Aarhus, Denmark Charles Bos [email protected] VU University Amsterdam Tinbergen Institute Advanced Programming in Quantitative Economics – p. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Day 5 - Afternoon 13.00L Efficiency and remaining topics Alternative algorithms Matrices Own code vs C-code Others 14.30P Finding the difference Concatenation Loop vs AR(p) vs ARFIMA package 15.30- Handing out exam, final remarks Advanced Programming in Quantitative Economics – p. 2
Background image of page 2
Speed Use matrices, avoid loops Use the const argument qualifier Use built-in functions Optimise inner loop Avoid using ‘hat’ matrices/outer products over large dimensions Matrices are stored by row Link in C or Fortran code Advanced Programming in Quantitative Economics – p. 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Speed: Loops vs matrices Avoid loops like the plague. Most of the time there is a matrix alternative, like for constructing dummies: speed loop2.ox #include <oxstd.h> #include <packages/oxutils/oxutils.h> main() { decl iN, iR, vY, vDY, i, r; iN= 10000; iR= 1000; vY= rann(iN, 1); vDY= zeros(vY); TrackTime("Loop"); for (r= 0; r < iR; ++r) for (i= 0; i < iN; ++i) if (vY[i] > 0) vDY[i]= 1; else vDY[i]= -1; TrackTime("Matrix"); for (r= 0; r < iR; ++r) vDY= vY .> 0 .? 1 .: -1; TrackTime(-1); TrackReport(); } Advanced Programming in Quantitative Economics – p. 4
Background image of page 4
Speed: const speed const.ox SomeFuncConst(const mX) { // Do nothing } SomeFuncNotConst(mX) { // Do nothing } main() { decl iN, iK, iR, iRr, mX, r; ... mX= rann(iN, iK); for (r= 0; r < iR; ++r) SomeFuncNotConst(mX); for (r= 0; r < iR; ++r) SomeFuncConst(mX); } Advanced Programming in Quantitative Economics – p. 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Speed: Built-in functions speed builtin.ox #include <oxstd.h> #include <packages/oxutils/oxutils.h> MyOlsc(const vY, const mX, const avBeta) { avBeta[0]= invert(mX’mX) * mX’vY; return !ismissing(avBeta[0]); } main() { decl iN, iK, iR, vY, mX, vBeta, r; // Generate regression data ... for (r= 0; r < iR; ++r) MyOlsc(vY, mX, &vBeta); for (r= 0; r < iR * iRr; ++r) ols2c(vY, mX, &vBeta); } Advanced Programming in Quantitative Economics – p. 6
Background image of page 6
Speed: Inner/optimise Target: Compute SSR= y for a series of q different vectors of β ’s: speed outer.ox ... mBeta= vBeta + ranu(iK, iQ); mE= vY - mX * mBeta; TrackTime("Outer"); for (r= 0; r < iR; ++r) vE2= diagonal(mE’mE); TrackTime("Inner - matrix"); for (r= 0; r < iR; ++r) vE2= sumc(mE .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}