# Reference

Based on:

And additional work by Keen, Legge, Fishburn, and Standish.

# Theory

This summary ignores certain problems in aggregating cost curves for welfare comparisions between perfect competition and monopoly.

The model assumes that the market demand curve and the marginal cost curve for each firm are straight lines. The following tables define the parameters of these lines and show some theoretical solution values.

MARKET AND FIRM PARAMETERS
PARAMETER SYMBOL
Price Intercept of Market Demand Function a
Quantity Intercept of Market Demand Function a/b
Additive Inverse of Slope of Market Demand Function b
Number of Firms n
Price Intercept of Firm Marginal Cost Function c
Slope of Firm Marginal Cost Function d

EQUILIBRIUM VALUES
TOTAL QUANTITY
SUPPLIED TO MARKET
QUANTITY SUPPLIED
BY EACH FIRM
PRICE
Monopoly (a-c)/(2 b + d) (a-c)/(2 b + d) (a b + a d + b c)/(2 b + d)
Cournot n (a-c)/[(n + 1) b + d] (a-c)/[(n + 1) b + d] (a b + a d + n b c)/[(n + 1) b + d]
Perfect Competition (a-c)/b 0 c

# Initial Values

When running the simulation, you are given two choices for two settings for the initial values:
• Cournot or Monopoly
• Either the mean of each firm's initial quantity is set to the Cournot solution
• Or the mean of each firm's initial quantity is set to the quotient of the monopoly solution and the number of firms. (The mean quantity supplied to the market starts out at the monopoly solution for this choice.)
• Deterministic or Gaussian
• Either each firm's initial quantity is set exactly to the mean.
• Or each firm's initial quantity is set equal to a normally distributed quantity with specified mean and a standard deviation equal to the quotient of the mean and the square root of eight more than the number of firms.

# Control Parameters

When running the simulator you are given three choices for controlling the updating of the quantities produced by each firm:
• Simultaneous In each period, all firms are updated. The quantity a firm produces is updated exactly once each period.
• Historical Time Each period is divided into a number of subperiods. In each subperiod, the quantity produced by a randomly chosen firm is updated. (Note that the quantity produced by a given firm may be updated once, more than once, or not at all in a given period.) The quantity produced for the market is determined only at the end of each period.
• Sequential In each period, the quantity produced by only one firm is updated. The firm is chosen in a round robin fashion: the first firm is updated the first period, the second firm is updated the second period, and so on until the firms repeat.

# Source Code

The source.

The most important code fragment is:

• Keen Algorithm
```   private double firmAlgorithm( double prevQuantity, int firm )
{
double currentStep;
int    lastTime;
double currentQuantity;

// Find the most recent period in which the quantity produced by the
// firm was changed from the prior period.
boolean isFound = false;
lastTime = currentTime - 1;
for ( int lastTime2 = currentTime - 1;
( ! isFound ) && ( lastTime2 > 0 ); lastTime2-- ) {
isFound = ( firmQuantity[ firm ][ lastTime2 ]
!= firmQuantity[ firm ][ lastTime2 - 1 ] );
lastTime = lastTime2;
}
if ( isFound ) {
// Determine last change in quantity.
double deltaQuantity = firmQuantity[ firm ][ lastTime ]
- firmQuantity[ firm ][ lastTime - 1 ];
// Determine change in profit resulting from last variation in
// quantity.
double profit = marketPrice[ lastTime ] * firmQuantity[ firm ][ lastTime ]
- TotalCost( firmQuantity[ firm ][ lastTime ] );
double laggedProfit = marketPrice[ lastTime - 1 ]
* firmQuantity[ firm ][ lastTime - 1 ]
- TotalCost( firmQuantity[ firm ][ lastTime - 1 ] );
double deltaProfit = profit - laggedProfit;
// If last change increased profit, set current period's quantity change
// to be in same direction. Otherwise, set current period's quantity
// change in the opposite direction.
if ( deltaProfit > 0 ) {
if ( deltaQuantity > 0 ) {
currentStep = stepSize;
} else {
currentStep = - stepSize;
}
} else {
if ( deltaQuantity > 0 ) {
currentStep = - stepSize;
} else {
currentStep = stepSize;
}
}
// If the firm acts irrationally this period, reverse the direction of
// the current period's quantity change.
if ( generator.nextFloat() < irrationalityRate ) {
currentStep = - currentStep;
}
// Update the quantity the firm produces.
currentQuantity = prevQuantity + currentStep;
} else {
// This firm has never changed its quantity before. So increment
// the quantity produced by the firm in the previously-determined
// random direction.
if ( isFirstStepPositive[ firm ] ) {
currentQuantity = prevQuantity + stepSize;
} else {
currentQuantity = prevQuantity - stepSize;
}
}
// If the algorithm resulted in a negative level of production, reset
// the quantity produced by the firm to zero.
if ( currentQuantity < 0.0 ) {
currentQuantity = 0.0;
}
return currentQuantity;
}
```