oxdk_day5b - A d v a n c e d P r o g r a m m i n g i n Q u...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A d v a n c e d P r o g r a m m i n g i n Q u a n t i t a t i v e E c o n o m i c s Introduction, structure, and advanced programming techniques 17 – 21 August 2009, Aarhus, Denmark Charles Bos cbos@feweb.vu.nl VU University Amsterdam Tinbergen Institute Advanced Programming in Quantitative Economics – p. 1 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 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 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 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 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 Speed: Inner/optimise Target: Compute SSR= y − Xβ for a series of q different vectors of β ’s: speed outer.ox ......
View Full Document

Page1 / 23

oxdk_day5b - A d v a n c e d P r o g r a m m i n g i n Q u...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online