Skip to main content

A package for algorithmic competition simulations.

Project description

Algocomp

Algocomp is a Python package for simulating competition between pricing algorithms across market structures.

Install

$ pip install algocomp

Duopoly Simulation

All duopoly simulations take the following inputs regardless of functional form.

Mandatory Arguments

  • costs: List of marginal costs for each firm
  • qualities List of product qualities for each firm ($a_i$)
  • algorithm Algorithm to use ('pso' or 'q-learning')
  • seed Random seed
  • plot Boolean flag to plot results
  • shock Boolean flag for HILP shock

Optional Arguments - PSO

  • num_particles Number of particles per firm (Default: 5)
  • num_iterations Number of iterations (Default: 1000)
  • w0 Initial inertia weight (Default: 0.025)
  • self_confidence Own particle confidence (Default: 1.75)
  • social_confidence Own firm confidence (Default: 1.75)
  • v_min Minimum particle velocity (Default: -0.3)
  • v_max Maximum particle velocity (Default: 0.3)
  • memory_size Size of particle memory in iterations (Default: 5)
  • hilp_iteration Iteration when the HILP shock occurs (Default: 500)
  • shock_size Price increase (Default: 0.5)

Optional Arguments - Q Learning

  • max_steps Number of iterations (Default: 1000000)
  • grid_lower_bound Lower bound on price space (Default: Nash - 0.5)
  • grid_upper_bound Upper bound on price space (Default: Nash + 0.5)
  • num_possible_actions Number of discrete prices (Default: 15)
  • learning_rate (Default: 0.15)
  • discount_factor (Default: 0.95)
  • beta Exploration rate (Default: 0.00001)

logit_duopoly

Duopoly implementation of logit shares $s_i = \frac{e^{\frac{a_i-p_i}{\mu}}}{e^{\frac{a_0}{\mu}}+\sum_{j=1}^{2}e^{\frac{a_j-p_j}{\mu}}}$

logit_duopoly(costs, qualities, outside_quality, mu, algorithm, seed, plot, shock, ...)
  • outside_quality Quality of the outside good ($a_0$)
  • mu Horizontal differentiation parameter

hotelling_duopoly

Duopoly implementation of hotelling demand from utility $U_{ij} = a_i - p_i - \theta | x_j - k_i |$

hotelling_duopoly(costs, qualities, theta, algorithm, seed, plot, shock, ...)
  • theta Horizontal differentiation parameter

linear_duopoly

Duopoly implementation of a linear inverse demand function $p_i = a_i - bq_i - dq_j$

linear_duopoly(costs, qualities, b, d, algorithm, seed, plot, shock, ...)
  • b Own quantity effect
  • d Cross quantity effect

Multi-firm Simulation

Implementation of the PSO algorithm for logit demand with $N$ firms $s_i = \frac{e^{\frac{a_i-p_i}{\mu}}}{e^{\frac{a_0}{\mu}}+\sum_{j=1}^{N}e^{\frac{a_j-p_j}{\mu}}}$

logit_pso(costs, qualities, outside_quality, mu, num_firms, shock, seed, plot, ...)

The arguments are as in logit_duopoly(), with the addition of num_firms

Examples

logit_duopoly

logit_duopoly([1,1], [2,2], 0, 0.25, 'q', 456, True, True, grid_lower_bound = 1.45, grid_upper_bound = 1.95)
Output:
Firm 1 Q-learning: 1.7357, Nash: 1.4729
Firm 2 Q-learning: 1.7714, Nash: 1.4729

alt text

hotelling_duopoly

hotelling_duopoly([1,1], [2,2], 1, 'pso', 1, False, False)
Output:
Firm 1 PSO: 2.0000, Nash: 2.0000
Firm 2 PSO: 2.0000, Nash: 2.0000

linear_duopoly

linear_duopoly([1,2], [1.5,3], 1, 0.85, 'pso', 1, False, True)
Output:
Firm 1 PSO: 0.9355, Nash: 0.9355
Firm 2 PSO: 2.2601, Nash: 2.2601

logit_pso

logit_pso([1,1,1,1], [2,2,2,2], 0, 0.01, 4, True, 1, True)
Output:
Firm 1 PSO: 1.2133, Nash: 1.0133
Firm 2 PSO: 1.2133, Nash: 1.0133
Firm 3 PSO: 1.2133, Nash: 1.0133
Firm 4 PSO: 1.2133, Nash: 1.0133

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algocomp-1.0.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

algocomp-1.0.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file algocomp-1.0.2.tar.gz.

File metadata

  • Download URL: algocomp-1.0.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for algocomp-1.0.2.tar.gz
Algorithm Hash digest
SHA256 42b4a808864f4e58bbdc061e72c9bf1833e3afc2deeaa2a10139c435cdba1069
MD5 7fffe6ccba1f825796c9e5e2c033984a
BLAKE2b-256 cd8827f9ac6283bd0ec718c51dbba5320b303d22705273a9d0382cb2f79847c3

See more details on using hashes here.

File details

Details for the file algocomp-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: algocomp-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for algocomp-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9036cb183fc3cfacab83bc4906f7bb1fc6dd21ae0a33544e68eb867acad6b03
MD5 a0c598a1fdc1634ebf7f0668b7ed66a6
BLAKE2b-256 e3db5d2a82d16f1a648c32dc4d4c2008eb209ca41225dace45a9b4e02d754f0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page