1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Quantitative Economics

472 387 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 472
Dung lượng 8,01 MB

Nội dung

QUANTITATIVE ECONOMICS Thomas Sargent and John Stachurski February 14, 2014 2 THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 1 Introduction 9 1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.2 What You Will Learn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.3 PDF or HTML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.4 Structure of the Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2 Programming in Python 11 2.1 About Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.2 Setting up Your Python Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.3 An Introductory Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.4 Python Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.5 Object Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.6 How it Works: Data, Variables and Names . . . . . . . . . . . . . . . . . . . . . . . . . 65 2.7 More Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 3 The Scientific Libraries 95 3.1 NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 3.2 SciPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 3.3 Matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 3.4 Pandas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 3.5 IPython Shell and Notebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 4 Introductory Applications 153 4.1 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 4.2 Finite Markov Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.3 Shortest Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 4.4 Schelling’s Segregation Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 4.5 LLN and CLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 4.6 Linear State Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 4.7 A First Look at the Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 4.8 Infinite Horizon Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 238 4.9 LQ Control Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 4.10 Rational Expectations Equilibrium . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 4.11 Asset Pricing in a Markov Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 284 CONTENTS 4 5 Advanced Applications 295 5.1 Continuous State Markov Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 5.2 Modeling Career Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 5.3 On-the-Job Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 5.4 Search with Offer Distribution Unknown . . . . . . . . . . . . . . . . . . . . . . . . . 324 5.5 Optimal Savings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 5.6 Robustness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 5.7 Linear Stochastic Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 5.8 Estimation of Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 5.9 Optimal Taxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 6 Solutions to Exercises 411 6.1 Exercises from An Introductory Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412 Solution to Exercise 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412 Solution to Exercise 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 6.2 Exercises from Python Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 Solution to Exercise 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 6.3 Exercises from Object Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . 416 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 6.4 Exercises from More Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 6.5 Exercises from NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 6.6 Exercises from SciPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 6.7 Exercises from Pandas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 6.8 Exercises from LLN and CLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 6.9 Exercises from Finite Markov Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 6.10 Exercises from Schelling’s Segregation Model . . . . . . . . . . . . . . . . . . . . . . . . 429 THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 CONTENTS 5 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 6.11 Exercises from Linear State Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 6.12 Exercises from A First Look at the Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . 434 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 6.13 Exercises from Shortest Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 6.14 Exercises from Infinite Horizon Dynamic Programming . . . . . . . . . . . . . . . . . . . 438 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 6.15 Exercises from LQ Control Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 6.16 Exercises from Rational Expectations Equilibrium . . . . . . . . . . . . . . . . . . . . . . 445 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 6.17 Exercises from Search with Offer Distribution Unknown . . . . . . . . . . . . . . . . . . 450 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 6.18 Exercises from Modeling Career Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 6.19 Exercises from On-the-Job Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 6.20 Exercises from Asset Pricing in a Markov Environment . . . . . . . . . . . . . . . . . . . 457 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 6.21 Exercises from Estimation of Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 6.22 Exercises from Continuous State Markov Chains . . . . . . . . . . . . . . . . . . . . . . 459 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 6.23 Exercises from Optimal Savings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Solution to Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 Solution to Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 Solution to Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 6.24 Exercises from Optimal Taxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 Solution to Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 7 FAQs / Useful Resources 465 7.1 FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 7.2 How do I install Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 7.3 How do I start Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 7.4 How can I get help on a Python command? . . . . . . . . . . . . . . . . . . . . . . . . 465 7.5 Where do I get all the Python programs from the lectures? . . . . . . . . . . . . . . . 465 7.6 What’s Git? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 7.7 Other Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 7.8 IPython Magics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 7.9 IPython Cell Magics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 7.10 Useful Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 8 References 467 CONTENTS 7 Note: You are currently viewing an automatically generated PDF version of our on- line lectures, which are located at This PDF is generated from a set of source files that are orientated towards the website and to HTML output. At this stage the presentation quality is a bit less consistent than the website, and some internal links might not work. THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 CONTENTS 8 THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 “Science is what we understand well enough to explain to a computer; art is everything else.” – Donald E. Knuth This website contains a sequence of lectures on economic modeling, focusing on the use of pro- gramming and computers for both problem solving and building intuition The primary programming language used in the lecture series is Python, a general purpose, open source programming language with excellent scientific libraries (We’ll tell you more about Python and why we chose it in the next lecture) At this stage, the level of the lectures varies from advanced undergraduate to graduate, although we intend to add more elementary applications in the near future The lectures are suitable for courses in quantitative methods and computational techniques, and also for self study and independent study groups To aid self study, all exercises have solutions Our solutions are not the last word on each exercise — instead they provide one approach that demonstrates good coding practices If you work through the majority of the course and do the exercises, you will learn • how to analyze a number of fundamental economic problems, from job search and neigh- borhood selection to optimal fiscal policy • the core of the Python programming language, including the main scientific libraries • good programming style • how to work with modern software development tools such as debuggers and version con- trol 1.3. PDF OR HTML? 10 • a number of mathematical topics central to economic modeling, such as – dynamic programming – finite and continuous Markov chains – filtering and state space models – Fourier transforms and spectral analysis – etc., etc. • related numerical methods – function approximation – numerical optimization – simulation based techniques and Monte Carlo – recursion – etc., etc. You can view these lectures on-line or download the PDF version (If you are reading this on-line, see the menu bar at the top of the page to download the PDF) If you decide to use the PDF, please be aware that 1. the PDF is automatically generated from source that is orientated towards the website and to HTML output, not PDF 2. the website will be change regularly, so each PDF will soon become out of date Nonetheless, we appreciate that PDF is sometimes more convenient for reading than a live website The first two parts of the course deal with the core Python language and the scientific libraries The third part of the course contains easier applications In these applications, coding strategies are discussed slowly and in depth The fourth part of the course is more advanced, and the lectures can be read selectively, according to your interests THOMAS SARGENT AND JOHN STACHURSKI February 14, 2014 [...]... data sets • CVXPY — convex optimization in Python Why not MATLAB? To some extent this question is inevitable, given that MATLAB is still the most common scripting language for numerical computing within economics MATLAB and Python are both high quality tools As for any other pair of tools — a shifting spanner versus a socket wrench, say — neither is “better” than the other Moreover, MATLAB and Python . orientated towards the website and to HTML output. At this stage the presentation quality is a bit less consistent than the website, and some internal links might not work. THOMAS SARGENT AND JOHN STACHURSKI. bar at the top of the page to download the PDF) If you decide to use the PDF, please be aware that 1. the PDF is automatically generated from source that is orientated towards the website and to. website The first two parts of the course deal with the core Python language and the scientific libraries The third part of the course contains easier applications In these applications, coding strategies

Ngày đăng: 09/04/2014, 18:54