<p>Here is a program on Cournot competition on Github:</p>
<p><a href="http://janboone.github.io/competition_policy_and_regulation/Collusion_Cournot/Collusion_Cournot.html" rel="nofollow noreferrer">http://janboone.github.io/competition_policy_and_regulation/Collusion_Cournot/Collusion_Cournot.html</a></p>
<p>It encompasses both numerical aspects and graphical aspects, and makes clear that <em><strong>SciPy</strong></em>, <em><strong>Numpy</strong></em> and <em><strong>Matplotlib</strong></em> are needed ( of course, what you need  depends on your specific model) .</p>
<p><em>SciPy</em> and <em>Numpy</em> are scientific  and numerical libraries of Python.
<em>Matplotlib</em> is the graphical library, and enables you to plot graphs and represent numerical solutions as graphs.</p>
<p>Changing parameters in the equations of the program you can plot the relevant solution as graphs, as in the following simulation of a Cournot model:</p>
<p><a href="https://www.kaggle.com/code/hrishitabapuram/cournot-model-simulation" rel="nofollow noreferrer">https://www.kaggle.com/code/hrishitabapuram/cournot-model-simulation</a></p>
<p>Below, some  examples of  programs for Cournot’s model I found, without graphical representations:</p>
<p><a href="https://data88e.org/textbook/content/07-game-theory/cournot.html" rel="nofollow noreferrer">https://data88e.org/textbook/content/07-game-theory/cournot.html</a></p>
<p>Here is another <strong>program on Github, that includes also the case of <em>n</em> companies:</strong></p>
<p><a href="https://ispanos.github.io/CournotGame/" rel="nofollow noreferrer">https://ispanos.github.io/CournotGame/</a></p>
<p>Adapting some of the program above to your needs, you can write down your simulation (of course, nothing ensures that the programs above are completely correct).</p>
<p>But, of course, the first step is to write down your equations.</p>
<p>Maybe the most complicated part is the graphical part, if you need it.
In this case you have to know a little <em>Matplotlib</em>, if you don’t already know it.</p>
<p>Have you a Python editor? I suppose you have, but I give a reference:</p>
<p>You can download <a href="https://www.anaconda.com/download" rel="nofollow noreferrer"><em><strong>Anaconda</strong></em></a>, a free software with several applications as Phyton and R, the name of the Python editor on Anaconda is <em>Spider</em>.</p>
<p>There are in it, of course, <em>Scipy</em>, <em>Numpy</em> and <em>Matplotlib</em>.</p>
<p>If you need a good reference as a guide for numerical and scientific Python, <em>Matplotlib</em> included, you can look at  Robert Johansson, <em>Numerical Phyton-Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib</em>, Apress, 2019.</p>
<p>But there is a lot of documentation for Python online, not very easy to search in, though, very wide.</p>
<p><em><strong>Post Scriptum.</strong></em> If you are a beginner in Phyton and you want to learn it, you need or a course or a book as guide for <em><strong>general</strong></em> Python (not scientific and numeric Python alone), documentation online drives you crazy.</p>
<p>I studied, some years ago,  Python on lectures notes, but they are not in English, and on  <a href="https://www.amazon.it/Think-Python-Like-Computer-Scientist/dp/1491939362/ref=sr_1_2?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;crid=1J4WMOV1NE0W1&amp;keywords=downey+python&amp;qid=1702310890&amp;sprefix=downey+python%2Caps%2C258&amp;sr=8-2" rel="nofollow noreferrer">Downey, <em>Think Phyton</em></a>, a wide-spread book, but I don't like it very much, there is a new book <a href="https://www.amazon.it/gp/product/3031351215/ref=ox_sc_act_image_1?smid=A11IL2PNWYJU7H&amp;psc=1" rel="nofollow noreferrer">Hunt, A Beginners Guide to Phyton 3</a>, I don't know it, but it is published by Springer and should be reliable.</p>

CC BY-SA 4.0
2023-12-11T15:50:56.007Z
2023-12-11T16:18:53.313Z
2023-12-11T16:18:53.313Z
BakerStreet
<p>Is there some guide or GitHub repository that shows how to program numerical version of IO models? I would like to learn how to simulate the general <span class="math-container">$n$</span>-firm Cournot competition model, but I can accept an answer that will point towards tutorials that do even just simple Cournot duopoly.</p>
<p>I do not have any specific assumptions on demand and cost function in mind. I want to see some toy examples I can use to learn how to do this. In case the answer tries to present example you can assume simple constant cost and downward sloping linear demand with some reasonable parameters.</p>

CC BY-SA 4.0
2023-12-11T13:03:55.950Z
Can you please clarify what you mean by general $n$-firm Cournot model? I mean what assumptions are there on the demand and cost functions regarding monotonicity and convexity?
Giskard
CC BY-SA 4.0
2023-12-11T15:16:52.087Z
@Giskard by that I mean that the model will work with any natural number n firms. Any standard downward sloping demand function will do. Costs can be linear. I just need some example of how to solve such model using python and then I can change parameters
csilvia
CC BY-SA 4.0
2023-12-11T15:20:51.000Z
Sorry, it is probably my ignorance, but I am not sure what you are looking for: some library with general IO functionality (not sure what this means), or a Python implementation of an algorithm that converges to an/the equilibrium? In the latter case it would strongly depend on the model assumption whether the algorithm works/is efficient?
Giskard
CC BY-SA 4.0
2023-12-11T15:42:46.927Z
@Giskard I am total novice in numerical methods I just want to see some example which with I can play and learn.
csilvia
CC BY-SA 4.0
2023-12-11T15:45:39.397Z
@Giskard also, I am looking for a guide or tutorial or GitHub, but if someone can provide some example in answer I now specified some assumptions.
csilvia
<industrial-organisation><python><numerical-methods><cournot>
Looking for guide to Industrial Organization numerical modeling in Python
csilvia
# Looking for guide to Industrial Organization numerical modeling in Python

(Asked by: username_0 on 2023-12-11)

Is there some guide or GitHub repository that shows how to program numerical version of IO models? I would like to learn how to simulate the general $n$-firm Cournot competition model, but I can accept an answer that will point towards tutorials that do even just simple Cournot duopoly.

I do not have any specific assumptions on demand and cost function in mind. I want to see some toy examples I can use to learn how to do this. In case the answer tries to present example you can assume simple constant cost and downward sloping linear demand with some reasonable parameters.

**Tags:** industrial-organisation, python, numerical-methods, cournot
> **Comments:**
> **username_1**: Can you please clarify what you mean by general $n$-firm Cournot model? I mean what assumptions are there on the demand and cost functions regarding monotonicity and convexity?  
> **username_0**: @Giskard by that I mean that the model will work with any natural number n firms. Any standard downward sloping demand function will do. Costs can be linear. I just need some example of how to solve such model using python and then I can change parameters  
> **username_1**: Sorry, it is probably my ignorance, but I am not sure what you are looking for: some library with general IO functionality (not sure what this means), or a Python implementation of an algorithm that converges to an/the equilibrium? In the latter case it would strongly depend on the model assumption whether the algorithm works/is efficient?  
> **username_0**: @Giskard I am total novice in numerical methods I just want to see some example which with I can play and learn.  
> **username_0**: @Giskard also, I am looking for a guide or tutorial or GitHub, but if someone can provide some example in answer I now specified some assumptions.  

---

## 1 answers

### Answer by username_2 on 2023-12-11. Score: 4 | Accepted answer

Here is a program on Cournot competition on Github:

<http://janboone.github.io/competition_policy_and_regulation/Collusion_Cournot/Collusion_Cournot.html>

It encompasses both numerical aspects and graphical aspects, and makes clear that ***SciPy***, ***Numpy*** and ***Matplotlib*** are needed ( of course, what you need depends on your specific model) .

*SciPy* and *Numpy* are scientific and numerical libraries of Python.
*Matplotlib* is the graphical library, and enables you to plot graphs and represent numerical solutions as graphs.

Changing parameters in the equations of the program you can plot the relevant solution as graphs, as in the following simulation of a Cournot model:

<https://www.kaggle.com/code/hrishitabapuram/cournot-model-simulation>

Below, some examples of programs for Cournot’s model I found, without graphical representations:

<https://data88e.org/textbook/content/07-game-theory/cournot.html>

Here is another **program on Github, that includes also the case of *n* companies:**

<https://ispanos.github.io/CournotGame/>

Adapting some of the program above to your needs, you can write down your simulation (of course, nothing ensures that the programs above are completely correct).

But, of course, the first step is to write down your equations.

Maybe the most complicated part is the graphical part, if you need it.
In this case you have to know a little *Matplotlib*, if you don’t already know it.

Have you a Python editor? I suppose you have, but I give a reference:

You can download [***Anaconda***](https://www.anaconda.com/download), a free software with several applications as Phyton and R, the name of the Python editor on Anaconda is *Spider*.

There are in it, of course, *Scipy*, *Numpy* and *Matplotlib*.

If you need a good reference as a guide for numerical and scientific Python, *Matplotlib* included, you can look at Robert Johansson, *Numerical Phyton-Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib*, Apress, 2019.

But there is a lot of documentation for Python online, not very easy to search in, though, very wide.

***Post Scriptum.*** If you are a beginner in Phyton and you want to learn it, you need or a course or a book as guide for ***general*** Python (not scientific and numeric Python alone), documentation online drives you crazy.

I studied, some years ago, Python on lectures notes, but they are not in English, and on [Downey, *Think Phyton*](https://www.amazon.it/Think-Python-Like-Computer-Scientist/dp/1491939362/ref=sr_1_2?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=1J4WMOV1NE0W1&keywords=downey+python&qid=1702310890&sprefix=downey+python%2Caps%2C258&sr=8-2), a wide-spread book, but I don't like it very much, there is a new book [Hunt, A Beginners Guide to Phyton 3](https://www.amazon.it/gp/product/3031351215/ref=ox_sc_act_image_1?smid=A11IL2PNWYJU7H&psc=1), I don't know it, but it is published by Springer and should be reliable.


---

