Package: bneqpri
bneqpriPython code for computing Bertrand-Nash equilibrium prices with "mixed" logit models. The implemented method is the fixed-point iteration derived and discussed in the papersFixed-Point Approaches to Computing Bertrand-Nash Equilibrium Prices Under Mixed-Logit Demand(Operations Research, 2011) andFinite purchasing power and computations of Bertrand–Nash equilibrium prices(Computational Optimization and Applications, 2015); there's also a super verbose working paper on thearxiv. You can get the whole gist from the first paper, the second introduces finer grained details related to treatment of "budgets" in the choice model (under regularity conditions). The basic idea is that there is aparticularfixed-point equation for simultaneous stationarity (thenecessaryconditions for equilibrium prices) that is provably norm-coercive and generates steps that are never orthogonal to the combined-gradient. Iterating such steps appears to be a strong alternative to Newton-type methods as discussed at some length in the papers, although there is no convergence proof.DependenciesUsing this repo requirespython3andnumpy.InstallationThis project is onpypiand thus you can usepip:$ pip install bneqpriIf you want to build from the repo, do$ python setup.py sdist bdist_wheel
$ pip install --find-links ./dist/Command-Line Usage$ python -m bneqpri --help
usage: __main__.py [-h] [--format {sequential,indexed}] [--firms FIRMS]
                   [--products PRODUCTS] [--individuals INDIVIDUALS]
                   [--linear-utility] [--initial-prices INITIAL_PRICES]
                   [--prices PRICES] [--ftol FTOL] [--iters ITERS] [-q]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Bertrand-Nash Equilibrium Prices Solver (with Finite Purchasing Power / Budgets)

Method from: 

Morrow, W.R. & Skerlos, S.J. Fixed-Point Approaches to Computing Bertrand-Nash Equilibrium 
Prices Under Mixed-Logit Demand. Operations Research 59(2) (2011).
https://doi.org/10.1287/opre.1100.0894)

Morrow, W.R. Finite purchasing power and computations of Bertrand–Nash equilibrium prices.
Computational Optimization and Applications 62, 477–515 (2015). 
https://doi.org/10.1007/s10589-015-9743-7           

Note this software is provided AS-IS under the GPL v2.0 License. Contact the author
with any questions. Copyright 2020+ W. Ross Morrow. 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

optional arguments:
  -h, --help            show this help message and exit
  --format {sequential,indexed}
                        Format input files are written in. Sequential presumes firms' products 
                        are listed sequentially, indexed means the header for product and individual file has _
                        indices describing the firm and product for the column. NOT YET IMPLEMENTED.
  --firms FIRMS         File describing the number of firms and the number of products they each offer
  --products PRODUCTS   File describing the number of products and their unit costs
  --individuals INDIVIDUALS
                        File describing the number of individuals, their budgets, price sensitivities, and utilities
  --linear-utility      Presume the utility is linear in the price coefficient, instead of using budgets
  --initial-prices INITIAL_PRICES
                        File with initial prices to use when starting iterations
  --prices PRICES       File with the computed prices, written upon solve
  --ftol FTOL           Solve tolerance, will terminate when |p-c-z(p)| < ftol
  --iters ITERS         Maximum number of iterations
  -q, --quiet           Don't print information to the consoleQuick StartRun by specifying threecsvfiles, describing the firm structure, the products (costs only now), and the utilities.The firm file should be a single-linecsvfile (not including header) with the number of firmsF, followed by the number of products offered by each firm. E.g,3 , 3 , 5 , 4for 3 firms, the first of which offers 3 products, the second 5, and the third 4. Spaces are ignored. The firm file thus hasF+1columns.The product file is another single-linecsvfile (not including header) and should contain the number of productsJ, followed by the costs for each of theJproducts.Jmust equal the sum of the number of products offered by each firm in the firm file. E.g.,12 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3The products file thus hasJ+1columns.Notethat this code presumes the products are ordered by firm. In our example above, we've chosen unit costs such that firm 1's 3 products all cost "1" to make, firm 2's "2", and firm 3's "3". Note that the monetary units are irrelevant as long as they are consistent with utilities and budgets, and prices are computed in whatever units costs are in.Models with Finite Purchasing Power / BudgetsThe utilities file is the most complicated, having as many rows as the number of individualsI(not including header) and2+Jcolumns. In each rowi, which corresponds to an individuali, the first column should be the budget for that individualb[i], the second the price sensitivitya[i], and the remainingJcolumns have the total non-price utility of all the part-worths of the features for each product in columns2for product 1,2+1for product 2, etc comprising a matrixV[i,j]of product utilities (except price). Again, products are ordered sequentially by firms.The utility function for choices used here is, for now, presumed to beU[i,j](p) = a[i] log( b[i] - p ) + V[i,j]when there is a budget. There is an outside good with unit value; any non unit value should be absorbed into the non-price utility. A word of warning, the price sensitivitymust bepositive for all individuals andprobablyneeds to be larger than one for all individuals.Linear UtilityWe also include an implementation and command line flag (--linear-utility) for linear utility modelsU[i,j](p) = a[i] p + V[i,j]Note that herea[i]should be negative and you should not specify theb[i]column in the utilities file (thus it will have only1+Jcolumns, not2+J).ExamplesExample files of each are provided in theexampledirectory here, and you can run them all as follows:$ bash examples.sh 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:37.144882 :: Modeling 1000 individuals, 10 firms, 144 products, linear utility no budget
2020-10-02T20:26:37.687914 :: Solved in 34/1000 steps, 0.542978048324585 seconds
2020-10-02T20:26:37.687948 :: fixed-point satisfaction |p-c-z| = 7.961977299686396e-09
2020-10-02T20:26:37.688401 :: (probable) equilibium prices written to examples/linear/1000-10-144/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:37.918779 :: Modeling 1000 individuals, 5 firms, 79 products, linear utility no budget
2020-10-02T20:26:38.287736 :: Solved in 28/1000 steps, 0.36890220642089844 seconds
2020-10-02T20:26:38.287766 :: fixed-point satisfaction |p-c-z| = 8.772539583645766e-09
2020-10-02T20:26:38.288218 :: (probable) equilibium prices written to examples/linear/1000-5-79/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:38.465683 :: Modeling 50 individuals, 3 firms, 53 products, linear utility no budget
2020-10-02T20:26:38.532921 :: Solved in 44/1000 steps, 0.06718897819519043 seconds
2020-10-02T20:26:38.532958 :: fixed-point satisfaction |p-c-z| = 6.891536230568818e-09
2020-10-02T20:26:38.533299 :: (probable) equilibium prices written to examples/linear/50-3-53/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:38.730063 :: Modeling 500 individuals, 3 firms, 40 products, linear utility no budget
2020-10-02T20:26:39.188571 :: Solved in 78/1000 steps, 0.4584488868713379 seconds
2020-10-02T20:26:39.188606 :: fixed-point satisfaction |p-c-z| = 8.38127345303974e-09
2020-10-02T20:26:39.188918 :: (probable) equilibium prices written to examples/linear/500-3-40/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:39.457582 :: Modeling 1000 individuals, 10 firms, 148 products, nonlinear utility with budget
2020-10-02T20:26:51.156455 :: Solved in 32/1000 steps, 11.698816061019897 seconds
2020-10-02T20:26:51.156493 :: fixed-point satisfaction |p-c-z| = 8.289176345321891e-09
2020-10-02T20:26:51.156979 :: (probable) equilibium prices written to examples/budgets/1000-10-148/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:26:51.393449 :: Modeling 1000 individuals, 5 firms, 68 products, nonlinear utility with budget
2020-10-02T20:27:03.496671 :: Solved in 73/1000 steps, 12.103170156478882 seconds
2020-10-02T20:27:03.496717 :: fixed-point satisfaction |p-c-z| = 9.146744250898564e-09
2020-10-02T20:27:03.497178 :: (probable) equilibium prices written to examples/budgets/1000-5-68/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:27:03.689047 :: Modeling 50 individuals, 3 firms, 41 products, nonlinear utility with budget
2020-10-02T20:27:03.818524 :: Solved in 20/1000 steps, 0.12943220138549805 seconds
2020-10-02T20:27:03.818557 :: fixed-point satisfaction |p-c-z| = 5.774188682750037e-09
2020-10-02T20:27:03.818899 :: (probable) equilibium prices written to examples/budgets/50-3-41/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

2020-10-02T20:27:04.019609 :: Modeling 500 individuals, 3 firms, 44 products, nonlinear utility with budget
2020-10-02T20:27:08.500028 :: Solved in 78/1000 steps, 4.48035192489624 seconds
2020-10-02T20:27:08.500067 :: fixed-point satisfaction |p-c-z| = 8.66341531846615e-09
2020-10-02T20:27:08.500400 :: (probable) equilibium prices written to examples/budgets/500-3-44/prices.csv

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -DetailsDetailed README content TBDTBDTons more testsImplement second-order sufficiency check for computed pricesFigure out whynumpysyntax isn't computingG'mterms correctlyContactW. Ross MorrowCopyright 2020+