Demo models‎ > ‎MacroABM‎ > ‎

The Consumption Good Firm class (CFirm)

1 Entities

The CFirm class represents a Consumption Good producing Firm.  As discussed in The Class Hierarchy of 'Agents', the CFirm class is derived from (i.e. is a subclass of) the Firm class, which itself is derived from the Agent class.  The relationship with the Firm class can be seen at the start of the class declaration, where the keyword extends is used to show that the CFirm class is derived from the Firm class:
public class CFirm extends Firm {
In the MacroABM model, CFirm is an Entity class, as specified by the @Entity annotation.  This implies that the class is linked to a table in the database with the same name, and that all fields which are not annotated as @Transient are persisted in the database, when the simulation output is dumped to the output database. Entity classes must specify a PanelEntityKey (annotated as @Id), which is a three-dimensional object which identifies the agent id, the simulation time and the simulation run. These three keys uniquely identify each record in the database:
private PanelEntityKey key;

The Object Relational Mapping (ORM) embedded in JAS-mine, which handles the representation of Java objects to the database, expects that the field names in the database are the same as the property names in the Java class.  Indeed, when exporting data to .csv files instead of the output database, the data is labelled using the name of the field as it appears in the code.

Class fields that are not simple types such as numerical values, strings or booleans cannot easily be represented in the output database.  Examples include Java objects such as the CFirm class' BalanceSheetCFirm object, which is thus annotated @Transient, which indicates to JAS-mine to ignore this field when exporting data to the output database or .csv file.  If the user wanted to store information about the balance sheet, the solution would be to define the BalanceSheetCFirm object as an Entity class itself, thus allowing its simple field types of numerical values, strings or booleans to be recorded in the same way as the CFirm.

2 The EventListener interface

Although not explicitly defined as implementing the EventListener interface, the CFirm class inherits this property from its superclass Agent, whose class declaration begins in the following way:

public abstract class Agent implements EventListener

This means that the CFirm objects are able to be activated by the scheduler with the onEvent() method.  The calls that a CFirm is able to respond to, are enumerated in a specific Enum called Processes (see Box 1).

public enum Processes {



public void onEvent(Enum<?> type) {

        switch ((Processes) type) {
        case Update:
        case ChooseSupplier:

        case InitialExpenditures:
            // Adaptative expectations
            this.expectedDemand = demand[0];

            /* Compute the desired level of production and investment, regardless of the firms' capital and financial                 resources
            /* The production function is of the Leontieff form. Thus the firm cannot produce more than the capital he                 possesses
            if(desiredProduction > capitalStock){
                this.desiredProduction = capitalStock;
            this.desiredProductionStar = desiredProduction;


Box 1. The CFirm implements the EventListener interface.

These enum Processes are usually added to the schedule in the MacroModel class' buildSchedule() method, with lines such as:

modelEventGroup.addCollectionEvent(cFirms, CFirm.Processes.Update);
modelEventGroup.addCollectionEvent(cFirms, CFirm.Processes.ChooseSupplier);
This means that the Process represented by the enums 'Update' and 'ChooseSupplier' are added as Events to the EventGroup, which is scheduled to fire at each time-step.  The addCollectionEvent() method is used, because the Update and ChooseSupplier events are to be applied to a collection of objects, in this case the set of cFirms, which is the first argument of the method.  This results in the Update and ChooseSupplier events being fired by each CFirm object in the cFirms set, so in effect every CFirm object performs the code for the relevant case in the switch code in Box 1 (i.e. run update() and chooseSupplier() methods respectively).

The significant methods of the CFirm class, often ones that are called via the EventListener implementation, are discussed in the next section.

3 Methods

We discuss the processes of the EventListener interface in Box 1, and highlight the important methods of the CFirm class.

3.1 Choose Supplier

The ChooseSupplier process calls the chooseSupplier() method.  A consumption-good firm always needs a supplier. If it doesn't have one, then in the chooseSupplier() method it picks one at random.  Consumption-good firms then compare the brochures they have received from the potential KFirm suppliers, and choose the supplier that is most competitive.  The chosen KFirm supplier is then informed that this CFirm will be a client (in the event that the CFirm desires to invest in new machinery) in the current time-step.

3.2 Initial Expenditures

As part of determining their expenditure during the current time-step, CFirms use adaptive expectations in estimating expected demand; they assume expected demand will equal their actual demand in the previous time-step.

Compute the desired level of production and investment, regardless of the CFirm's capital and financial resources.    If the expected demand is lower than the stock of capital, then the firm does not want to produce. When the desired production quantity is 0, we follow the Dosi et al. implementation: the firm is dead and will have to exit at the end of the period. In particular, it cannot sell its inventories.
The unit cost of production is an average of the firm's machine productivity.  If a firm does not need its entire set of machines to produce its desired quantity, it selects only its most productive ones by calling the machineSelection() method. At the aggregate level, this represents an average cost reduction of 5%.

Investments are multiples of the 'capital dimension', i.e. machine size in terms of capital.  We follow Dosi et al. implementation and round down investments when needed. Investments are made of two components: (a) expansionary investment, which is the difference between the desired level of capital and the actual level of capital, and (b) substitutionary investment, which arise to replace machines scrapped because they are either too old or less productive that the current vintage being produced.

A hidden assumption from Dosi et al. (2013) that we follow is that the production function is of the Leontieff form, thus the firm cannot produce more than the capital it possesses.

3.3 Investment Decisions

This is considered in the APrioriAdjustments process.  CFirms have to check whether their current plans are achievable with their current resources. These are made up of their internal funds and potential loans, bounded above by their borrowing capacity.  Firms have preferences: (i) production should be funded before investment, (ii) (cheaper) internal funds should be used before (expensive) external ones, i.e. bank loans. 

The Model class' GUI parameter myopicDebtRepayment allows the user to choose between two ways in which CFirms can consider repaying their debt to the bank: either (a) with myopic adjustment or (b) in a pseudo rational way.  A complete description of the difference between the two types of adjustments is provided in the code documentation.

(a) Myopic Case: aPrioriFeasibilityMyopic():

In the myopic adjustments case, CFirms have access to a credit line. As such, firms do not take into consideration that they have to repay a share of their debt at the end of the period.

The CFirm deducts from its liquid assets the cost of production.  The firm then verifies whether it can achieve its desired investments, using loans if necessary. If it cannot afford its desired investments even after taking into consideration the maximum possible amount of loan available, it scales down its plans.

(b) Psuedo Rational adjustments case:

(i) In the aPrioriFeasibilityPseudoRational() method, CFirms do not have access to lines of credit.  Instead, CFirms have to take into account their expected liquid assets at the end of the period.
(ii) Afterwards, the method expectedPayment() checks whether CFirms, given their feasible plans, expect to be able to repay the debt due at the end of the period.  Utility methods from the APrioriAdjustments class are called during the calculations.

3.4 Expenditures

In a similar way to the investment decisions taken during the APrioriAdjustments process, once CFirms know their loan amount, they adjust differently depending on whether they (potentially) have access to a line of credit or not, as specified by the user with the GUI parameter myopicDebtRepayment.

(a) Myopic case: myopicExpendituresUpdate():

If the myopic debt repayment procedure has been chosen by the user, the CFirms' myopicExpendituresUpdate() method is called by the Bank object during its credit allocation process.

In this version, consumption-good firms have access to a line of credit. They can thus
    (i) consume only a part of the loan that the bank offers them,
    (ii) repay their debt (accumulation of line of credit) whenever they want.
There is a difference between the Dosi et al. code of the model and our version: when credit demand = 0, our version allows the firm to repay entirely its debt.  Also, CFirms try to reach intermediary level of investments in our version, which is not the case in the Dosi et al. code.

(b) Pseuedo Rational adjustments case:

In the pseudo rational case, the CFirm class' ExpendituresUpdate process calls the pseudoRationalExpendituresUpdate() method.  In this pseudo rational case, CFirms once more take into account their expected liquid asset at the end of the period.  This is because all expenditures funded through internal funds will reduce the firms' liquid assets, and therefore its end-of-the-period assets.

CFirms have received their loans, and therefore know exactly how much they have to spend on production and investment. If (i) the credit demand was nil, or (ii) if the loan is equal to credit demand, no further adjustments are needed and the desired quantities turn into actual quantities.  Otherwise, when the firm has been credit rationed, i.e. loan < credit demand, then it has to undertake subsequent adjustments.  These 'a posteriori adjustments' are very similar to the a priori adjustments of the investment decisions.  The only difference is that now, if the firm fails to adjust, it cannot de-leverage as it has already received the loan.  Note, the pseudoRationalExpendituresUpdate() calls the CFirm class methods feasibilityNilLoan() and feasibilityPositiveLoan(), and also utility methods from the APosterioriAdjustments class as part of these calculations.

3.5 Investment Order

The InvestmentOrder process calls the investmentOrder() method, where CFirms compute their total investment and send their orders to their supplier.

3.6 Labor Market

This simply updates the labor demand of each CFirm for the current time-step.  However, the Model class schedules the labor market to update, taking into account the labor demand of both CFirms and KFirms, and performing labor rationing in cases where labor demand exceeds labor supply.  In the case of labor rationing, the CFirm class' laborRationing() method is called, which scales down labor demand and production by applying a reduction factor to the original demand and production.

3.7 Machine Scrapping

The MachineScrapping process calls the machineScrapping() method.  In this method, CFirms consider getting rid of undesireable machines from its stock.  The sources of scrapping are twofold:
             (a) machines that are 'too old',
             (b) machines that are less productive than the current vintage of machine.
In both cases, a firm will decide to scrap a particular vintage only if it has resources to replace it.

3.8 Production

The Production process calls the production() method.  In this method, the CFirm produces a quantity of consumption goods that it adds to its inventories.  As for investment, the financial structure of the CFirm determines the source of the expenditures.  Note that some external resources may remain after paying for production, due to labor rationing.  In the myopic debt repayment case (as specified by the GUI parameter myopicDebtRepayment, see also 3.3 and 3.4), the firm is assumed to have access to a credit line, and therefore repays this amount to the bank.

3.9 Accounting

The Accounting process calls the accounting() method.  This method updates the various fields related to the accounts of the CFirm, such as the CFirm's sales, gross operating surplus, stock of inventories and profit.  In addition, the method updates the Bank fields with the debt interest and deposits of each CFirm.  Finally, the debt and liquid assets are updated, but in two different ways depending on whether the myopic debt repayments or pseudo rational cases (as specified by the GUI parameter myopicDebtRepayment, see also 3.3 and 3.4) are selected by the user.  In the pseudo rational case, the assetPseudoRational() method is called. 

The Accounting process also handles the transfer of taxes of any profits from the CFirm sector to the government.

Previous: The Capital Good Firm class (KFirm)       Next: The Bank class