DEV Community

Vyas Barath Krishnan
Vyas Barath Krishnan

Posted on

I spent 8 weeks building a Nash Equilibrium calculator from scratch in Python

Hey everyone,

I am someone who has been wanting to apply computer science into economics and mathematics and hence I decided to build a Nash Equilibrium calculator of sorts using Python and other libraries in Python like numpy and scipy.optimize.

The solver calculates all pure and mixed nash equilibria using the support enumeration algorithm. It also uses linear programming, which I did through the HiGHS solver, for the iterated elimination of strictly dominated strategies. I also built a small sub feature where the tool calculates game values for zero sum games using the Von Neumann Minimax theorem by identifying the Pareto optimal outcomes and hence calculating the social welfare loss. To make it visually easy to read, I used the rich library to build a terminal UI that color-codes the matrices.

This project took me almost 8 weeks to complete and I had to force myself to not use AI at all and hence the code might be a bit wonky.

Nonetheless, would be great if y'all could check it out and as always, open to any and all comments for improvement regarding the code or the math.

Here is the repo on GitHub, please go check it out: Github Link

Top comments (0)