Skip to main content
Python Packages for Economics: Model and Simulation
·

About

In these instructions, we introduce five Python Packages for Economics: Nashpy, QuantEcon, Game Theory Explorer, Gambit, and Mesa. All five packages are useful for modeling and simulations. Both Nashpy and QuantEcon can solve simple game theory problems. To be specific, Nashpy is a Python library used for the computation of equilibria in 2 player strategic form games (Nashpy, 2017) while QuantEcon offers additional computational tools for economics, econometrics, and decision making (QuantEcon, n.d.). Game Theory Explorer (GTE) and Gambit are used for simulating and solving extensive games. GTE is an online graphical user interface for small and medium-size games while Gambit provides more complete functions. Mesa is a framework provided by Python that aims to do agent-based modeling.

In the first four sections, we introduce each software by providing the references, license information, and required citations. In the last section, we present a case study for each software. 

Resources:

Github Repository: [URL]

Illustrator in Whimsical Folder: [URL]

PubPub Page: [URL]

Table of Contents

I. Nashpy

[Documentation]

1. Introduction

2. License

3. Required Citation

4. Example

II. QuantEcon

[Documentation][Website]

1. Introduction

2. License

3. Required Citation

4. Example

III. Game Theory Explorer

[Documentation][Website][Apps in the Cloud]

1. Introduction:

2. License

3. Required Citation:

4. Examples:

IV.Gambit

[Website]

1. Introduction

2. License

3. Required Citation

4. Example

V. Mesa

[Documentation] [Github]

1. Introduction

2. License

3. Required Citation

4. Example

VI. Case Studies

Normal Form Game [Part I]

Extensive Form Game [Part II]

Evolutionary Game [Part III]

In these instructions, we introduce five Python Packages for Economics: Nashpy, QuantEcon, Game Theory Explorer, Gambit, and Mesa. All five packages are useful for modeling and simulations.

Both Nashpy and QuantEcon can solve simple game theory problems. To be specific, Nashpy is a Python library used for the computation of equilibria in 2 player strategic form games (Nashpy, 2017) while QuantEcon offers additional computational tools for economics, econometrics, and decision making (QuantEcon, n.d.). Game Theory Explorer (GTE) and Gambit are used for simulating and solving extensive games. GTE is an online graphical user interface for small and medium-size games while Gambit provides more complete functions. Mesa is a framework provided by Python that aims to do agent-based modeling.

In the first four sections, we introduce each software by providing the references, license information, and required citations. In the last section, we present a case study for each software.

Whimsical Folder for Illustrators: [URL]

Github Repository

I. Nashpy

[Documentation]

1. Introduction

[Nashpy] is a Python library for the computation of equilibria in 2 player strategic form games (Nashpy, 2017). Check [This document] for instructions.

Figure 1: The functionings of Nashpy

[Source: Created by whimsical]

2. License

Nashpy is Free/Open Source software, released under the terms of the MIT License.

3. Required Citation

Vincent Knight (2021). Nashpy: a python library for the computation of equilibria of 2 player strategic games, Version 0.0.28. https://github.com/drvinceknight/Nashpy

4. Example

In this [Colab Notebook 1: NashPy], we demonstrate how to solve the Nash Equilibrium of three classic games using Nashpy: the prisoner’s dilemma, matching pennies, and the battle of sex in Nashpy.

II. QuantEcon

[Documentation][Website]

1. Introduction

[QuantEcon] is a project dedicated to the development of open-source computational tools for economics, econometrics, and decision making (QuantEcon, n.d.). Check [this document] to learn how to access QuantEcon via Python.

Figure 2.1:QuantEcon overview

[Source: Created by whimsical]

2. License

QuantEcon is Free/Open Source software, released under the terms of the BSD-3-Clause License.

3. Required Citation

Thomas J. Sargent and John Stachurski (2021), Quantitative Economics (Python), Version 0.5.1. https://quantecon.org/quantecon-py/

4. Example

Chart 2.2. Represents the pipeline to solve for Nash Equilibrium (NE) of Battle of Sexes in QuantEcon. In this [Colab Notebook 2: Nashpy vs QuantEcon], we compare Nashpy and QuantEcon packages for solving matrix games in a concrete example.

Figure 2.2:QuantEcon Examples - Battle of Sexes

[Source: Created by whimsical]

III. Game Theory Explorer

[Documentation][Website][Apps in the Cloud]

1. Introduction:

Game theory Explorer (GTE) software allows researchers to create games in extensive form and to compute equilibria accordingly, and provides an intuitive representation of the Game Tree (Savani et al., 2014). Check [this document] to learn more about GTE.

2. License

GTE is Free/Open Source software, released under the GNU General Public Licence.

3. Required Citation:

Rahul Savani and Bernhard von Stengel (2015), Game Theory Explorer – Software for the Applied Game Theorist. Computational Management Science 12, 5-33.

4. Examples:

Figure 3 demonstrate how we create the game tree successfully and solve for the equilibrium

Figure 3: Chart for Game Theory Explorer example

[Source: Created by whimsical]

IV.Gambit

[Website]

1. Introduction

Gambit is an open-source collection of tools for doing computation in game theory. It provides a graphical interface to help get an intuition about simple games and command-line tools and Python scripting API to support practical applications (Gambit, 2017). However, the Python API is sometimes not stable and the graphical interface is more recommended. Check [official website] to get started with Gambit.

Figure 4: Gambit overview

[Source: Created by whimsical]

2. License

Gambit is Free/Open Source software, released under the terms of the GNU General Public License.

3. Required Citation

McKelvey, Richard D., McLennan, Andrew M., and Turocy, Theodore L. (2014). Gambit: Software Tools for Game Theory, Version 16.0.1. http://www.gambit-project.org.

4. Example

Here we provide an example of solving an imperfect information game with Gambit. The game is constructed as shown in Figure 5. Notice that in the game tree we constructed below is asymmetric and has an information set, which means it is an imperfect information game. By using GTE, we are not able to solve this kind of imperfect information and asymmetric game, while Gambit allows us to achieve that. You can download the Gambit graphical interface via [this link]. Check [this document] to learn how to use the interface.

Figure 5: Construct and solve imperfect information game with Gambit

V. Mesa

[Documentation] [Github]

1. Introduction

Mesa is a modular framework for building, analyzing, and visualizing agent-based models. Agent-based models are computer simulations which involve multiple entities acting and interacting with one another based on their programmed behavior (Mesa, 2021). Check [this document] to learn more about Mesa.

Figure 6: Mesa Overview

[Source: Created by whimsical]

2. License

Mesa is Free/Open Source software, released under the terms of Apache2 license.

3. Required Citation

Kazil, Jackie, Masad, David, Crooks and Andrew (2020). Utilizing Python for Agent-Based Modeling: The Mesa Framework. https://github.com/projectmesa/mesa

4. Example

In the [Colab Notebook 3: Mesa], we used Mesa to simulate an evolutionary game in the paper entitled “Evolutionary Game for Mining Pool Selection in Blockchain Networks.” This paper studies “the dynamics of mining pool selection in a blockchain network, where mining pools may choose arbitrary block mining strategies” (Liu et. al, 2018). We simulate the two pool cases and visualize the miners’ dynamic switching between these two pools. Figure 7 presents the pseudo-code.

Figure 7.1: Mesa Example 1: Pseudo Code

Figure 7.2: Mesa example 2: the Pipeline

[Source: Created by whimsical]

VI. Case Studies

In this section, we provide a case study for each software mentioned in the first four sections by presenting sample code assignments that utilize the four software packages for solving game theory problems. The assignments consist of three parts: Part I: Normal Form Game; Part II: Extensive Form Game; Part II: Evolutionary Game. We provide sample questions and answers in two separate Colab notebooks ([Colab Notebook 4.1: Case Study Questions],[Colab Notebook 4.2: Case Study Answer]).

Normal Form Game [Part I]

In this part, we provide problem sets for solving two normal form games, one classical game Battle of sexes (Noam Nisan et. al, 2007, p.7 ), one related to Blockchain application The miners’ dilemma (Ittay, 2015). Students are asked to use NashPy and QuantEcon to get pure equilibrium strategies and mixed equilibrium strategies.

Extensive Form Game [Part II]

In this part, we provide problem sets for solving two extensive form games, one classical Game of moving (Noam Nisan et. al, 2007, pp. 67-68), one related to the Blockchain Finite Blockchain game (Ewerhart et al. 2020). Students are asked to use Game Theory Explorer (GTE) to solve the extensive form game with perfect information and Gambit to solve the extensive form game with imperfect information.

Evolutionary Game [Part III]

In this part, we provide problem sets for solving two evolutionary games, one classical The evolutionary equilibrium of block withholding attack, (Cheng et. al, 2021), and the other related to blockchain Mining Pool Selection (Liu et. al, 2018). Students are asked to use Mesa to do agent-based modeling to simulate these two evolutionary games.

Comments
0
comment
No comments here
Why not start the discussion?