Friday, December 23, 2011

Computational economics Lecture 1


Introduction

This is a graduate-level lecture series on computational economics
It covers topics from my text Economic Dynamics: Theory and Computation
  • But with more detail on programming techniques
  • Can be read independently

Why CompEcon?

These days, all quantitative work in economics and finance involves calculations on a computer
  • Solving models (optimization, etc.)
  • Estimation, data manipulation
  • Simulation
  • Visualization of results
Some simple calculations can be done with point and click (Eviews) or spreadsheets
Let's leave this for the undergraduates
Serious computation requires programming---this course will show you how

What Does this Course Teach?

Programming, starting from zero
  • Expressions, conditions, loops, etc.
  • Data types (numbers, lists, etc.)
  • Program structure (functions, objects, modules, etc.)
Numerical methods
  • Working with arrays
  • Linear algebra
  • Numerical integration and numerical optimization
  • Random number generation, etc.
Algorithms for solving common economic models
  • Dynamic programming, simulation, computing equilibria

Which Language to Choose?

Many good options for numerical work, but which one to choose?

High level versus low level languages

Time to complete programming project:
total time = writing and debugging time + run time
Ideal language would minimize both terms on RHS
But there is a trade-off here
  • To minimize the first term: optimize for humans
  • To minimize the second term: optimize for computers
Lower level languages are optimized for computers
  • C/C++, Fortran, etc.
Higher level languages are optimized for humans
  • Python, MATLAB, Octave, Gauss, R, Perl, Ruby, Visual Basic, etc.
To help understand differences, let's write a program which prints "Hello world"
In C (lower level lang) it might look like this
#include <stdio.h>
int main(void) 
{
     printf("Hello world\n");
     return 0;
}
In Python (higher level lang) it looks like this
print "Hello world"
Observe that the lower level language is more verbose
  • Takes time to learn, write
  • Writing boilerplate is error prone
  • More details to address (declaring variables, memory allocation/deallocation, etc.)
But they have advantages
  • Run faster
  • Closer to the hardware, giving more control

Trends

How is the popularity of various languages changing over time?


Overall, the trend is towards higher level languages
  • Computers are getting faster, so let's ask them to take care of messy details
Modern scientific programming paradigm:
  • First write in higher level language
  • Then port individual pieces of code to faster language as needed

Python

The primary language of the course will be Python
Python is a general purpose, high level language
  • Used extensively by high-tech companies
    • Google--especially YouTube
    • Industrial Light and Magic, etc.
  • Popular in scientific community
    • Used by NASA, CERN, etc.
    • Meteorology, computational biology, chemistry, machine learning and AI, etc.
  • Lots of exciting new developments
Other advantages of Python
  • Excellent design
    • Good to learn programming concepts
  • Popular
    • Lots of good documentation, existing code, libraries
  • Open source
    • Free to download
    • Can read and modify source code in libraries
  • Excellent numerical and graphical libraries

Text Editing

It's worth saying something at this stage about how to write program code
Computer code is written in a text file
  • To edit a text file we need a text editor
  • Hence need text editor to write code
    • Not Word or other word processor
      • Yes you can save as a text file
      • But it's not suitable for writing code
If you want to be proficient with computers,
  • Choose a good text editor
  • Learn how to use it efficiently
  • Use it for everything you can
    • All kinds of programming (Python, C, etc.)
    • Writing emails
    • Writing LaTeX files and HTML
Some free text editors
  • Geany: (Cross-platform, easy to use)
  • Notepad++: (Windows only, as far as I know)
  • Emacs: (UNIX, old school, rocks)
  • Vim: (Ditto, my personal favorite)
Note: most Python distributions contain a simple text editor
  • For Python newbies, this is a good way to start
  • But if you keep programming, remember to graduate to a real text editor

Operating Systems

Windows or Mac are fine, but you might want to try UNIX/Linux
  • Not so good for multimedia or games
  • But great for scientific programming
    • Excellent programming tools
    • Designed for power users
  • And free
The most popular distribution is Ubuntu
You can run it from a memory stick and see if you like it

Finally

Some resources for the course:

Reference Texts

  • Python Programming, John Zelle, Franklin, Beedle and Associates (2004)
  • Applied Computational Economics and Finance, Miranda and Fackler, MIT Press (2002)
  • Computational Economics, Kendrick, Mercado and Amman, Princeton UP (2007)

0 comments: