0% found this document useful (0 votes)
3 views10 pages

Tools for Computational Economics

1-Tools Lecture Notes in Pyton

Uploaded by

Ivo Magalhães
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Tools for Computational Economics

1-Tools Lecture Notes in Pyton

Uploaded by

Ivo Magalhães
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tools

J.A. Matos, P.B. Vasconcelos

Numerical Methods for Economics


Master in Economics (FEP)

Contents
1 Installation 2
1.1 Software Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Install locally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Programming languages 4
2.1 Languages for Computational Economics/Finance . . . . . . . . . . . . . . . . 4
2.2 Interacting with the computer language . . . . . . . . . . . . . . . . . . . . . . 4

3 Jupyter 5
3.1 Notebooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Markdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Support for multiple languages . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

4 Motivation: Economic examples 7


4.1 Supply and demand model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Consumer and producer surplus . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 Lorenz curve and Gini coefficient . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.4 Cobb-Douglas production function . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Installation 2

1 Installation
1.1 Software Licenses
Licenses

• All software used in this course has a free software, open source, license. [Link]
org/osd

• That means that we are able to install this software in as many computers and operating
systems that we wish.

• In particular this means that you are encouraged to install this software on your own computer
and do not need to rely on the software installed in the University computers.

• Please try it and explore all the associated material available from the class.

1.2 Install locally


Install locally in a computer
There are different ways to install Python and Jupyter ( or R), some of the Tools referred in this
course:

1. Anaconda distribution:
[Link]

initially developed for Python but now also works with R.

2. Using the installers for the different Operating Systems:


a) Python: [Link]
b) R: [Link]

3. Rstudio editor:
[Link]

initially developed for R but now also works with Python.

1.3 Usage
Work locally or online
QuantEconon [Link] has several references for Economics and Finance stu-
dents.
In the Python programming course you can find several alternatives to install/use all the tools
studied:

• Install a Python distributions (e.g. Anaconda) locally;

Numerical Methods for Economics Master in Economics


1 Installation 3

• Use services on the cloud, like Google Colab, that allow to start working directly but do not
have the same flexibility.
[Link]

Put it in practice
Note
The best way to learn a programming language is, in a sense, like learning a new human foreign
language: is to practice it regularly.

Numerical Methods for Economics Master in Economics


2 Programming languages 4

2 Programming languages
2.1 Languages for Computational Economics/Finance
Programming languages
There are several computer languages that are used to solve problems in Computational Eco-
nomics/Finance, that are either well established or promising:

• Python;

• R;

• Julia;

• Matlab/Octave.

All of these are well established programming languages:

• they are implemented as Free/Open Source Software (the exception is Matlab);

• they are mature languages with very large communities (Julia is the youngest);

• that are well supported on a broad range of Operating Systems.

Comparison
Each language has different strengths and is able to inter-operate with the other so that is why in
this course we will deal with both.

• [Link]

• [Link]
answer/DataCamp-5?pa_story=MTE2NDI5MjU2MzY1MjcxNzE0M3wyMTExMDYyMzQ5ODA4MTl8MA**

2.2 Interacting with the computer language


Interfaces
In order to use the languages there are several interfaces that can be used:

Jupyter is a project and community whose goal is to "develop open-source software, open-standards,
and services for interactive computing across dozens of programming languages".

Spyder Python editor and development environment.

Rstudio R, and Python, editor and development environment.

IDE other editors like VScode, ... or some specific GUI (Graphical User Interface).

Numerical Methods for Economics Master in Economics


3 Jupyter 5

3 Jupyter
3.1 Notebooks
Notebook
Jupyter is a working environment that works with documents called notebooks that are struc-
tured using units called cells.
Each input cell can be of one the following types:

• Code;

• Markdown.

When we execute some code a corresponding output cell is displayed.

3.2 Markdown
Markdown
Markdown is a lightweight markup language for creating formatted text using a plain-text editor.
The idea is that the text that we insert represents what can be seen. In the next example we see
what we write in left (edit mode) and how it is displayed on the right (presentation mode):
This is a list of items:
This is a list of items:
* 1
• 1
* 2
• 2
* 3
• 3

Markdown cells on Jupyter


We can switch between the two modes:

• Shift + Enter changes the cell to presentation mode;

• Double clicking on each cell changes to edit mode.

[Link]

Appropriate use of help

• Learning a new language is always a challenging task.

• The best way to do it is to take an hands on approach, i.e., learning by doing.

• It is usual to commit several errors when starting. To simplify this process take advantage
of both the inline help and of the graphical interfaces that give you a quick way to access the
documentation.

Numerical Methods for Economics Master in Economics


3 Jupyter 6

3.3 Support for multiple languages


Languages

• Each notebook has, usually, a computer language associated.

• In this course we will use mainly Python with some of the examples presented in Matlab/Oc-
tave, R or Julia.

• In order to simplify the exploration and development of code, something required while
studying new data, by default the code cells will print the value of the last line if not included
in an assignment.
– This is a unique characteristic of notebooks and it does not apply to the computer
languages (in general).

3.4 Limitations
Warning
Notebooks are a practical way to organize code and text but:

"With great power there must also come great responsibility"—or simply "With great
power comes great responsibility"—alternatively known as the Peter Parker principle,
is a proverb popularized by the Spider-Man comic books written by Stan Lee.

Like all the tools they are not adequate to all task, as usual informed common sense is a requirement
for a good professional.

Numerical Methods for Economics Master in Economics


4 Motivation: Economic examples 7

4 Motivation: Economic examples


Aim

• In order to illustrate the use of notebooks and Python to solve Economics and Finance prob-
lems next we present some examples.

• The examples are very simple, on purpose, to illustrate how we can use Python to solve
simple problems that will be made more complex in the next modules.

• Notice that this is not, necessarily, the way as we will be able to solve these examples later.
We will learn with each attempt and use better/easier ways to solve as we explore further
concepts and tools.

4.1 Supply and demand model


Example
Tasks

1. Consider the following supply and demand curves: p = c + dq and p = a − bq for a = 10,
b = 0.7, c = 2 and d = 0.5.
a) Draw the equations;
b) Compute the equilibrium point;
c) Represent it graphically.

2. Consider the existence of taxes t at the model: p + t = a − bq and p = c + dq:


a) What is the new equilibrium quantity (take t = 1)?
b) What is the equilibrium price paid by consumers and the price perceived by producers?
c) What is the tax collected by the government?

Supply and demand curve

Numerical Methods for Economics Master in Economics


4 Motivation: Economic examples 8

Supply and demand model


10

p 6

0
0 2 4 6 8 10 12 14
q

4.2 Consumer and producer surplus


Example
Tasks
Consider the previous model.

1. Compute the consumer surplus


Z qe
(D(q) − pe )dq.
0

2. Compute the producer surplus


Z qe
(pe − S(q))dq.
0

4.3 Lorenz curve and Gini coefficient


Lorenz curve
Definition

Numerical Methods for Economics Master in Economics


4 Motivation: Economic examples 9

The Lorenz curve represents the income distri-


bution: percentage (y%) of the total income
owned by the bottom x% of households

Gini coefficient
Definition
The Gini coefficient is the ratio of the area between the line of perfect equality and the observed
Lorenz curve to the area between the line of perfect equality and the line of perfect inequality:
ratio G = A/(A + B), where A and B are the areas of regions as marked in the diagram.
Since the total area of the triangle is 1/2 then G = 2A
The higher is the coefficient, the more unequal the distribution is.

Practical example
Tasks
Determine the Gini coefficient and the Lorenz curve of a set of 10 firms selling turnips:
Firm Sold units (millions) per year
A 25
B 4
C 3
D 12
E 17
F 30
G 20
H 17
I 12
J 10
Total 150

4.4 Cobb-Douglas production function


Example
Tasks
Consider the Cobb-Douglas production function Y = ALα K β where Y stands for production,
L labor, K capital and the exponents α and β are, resp., labor and capital elasticity. For each case
draw the production function, assuming A = 1, as well as some isoquants (indifference curves).

Numerical Methods for Economics Master in Economics


4 Motivation: Economic examples 10

1. decreasing returns to scale, α = 0.15 and β = 0.25

2. constant returns to scale, α = β = 0.5

3. increasing returns to scale, α = 0.5 and β = 0.75

Numerical Methods for Economics Master in Economics

You might also like