Agent-Based Modeling of a Multiagent Multilayer Endogenous Financial Network and Numerical Simulations

Based on a realistic correlated behavior mechanism and a connected balance sheet relationship among ﬁrms, banks, households, and the government, we construct a multiagent multilayer endogenous ﬁnancial network that includes an interbank network, an investment network, a deposit network, a business credit network, and a loan network. During the construction process, behaviors are endogenized such that an endogenous ﬁnancial network is constructed. The simulation results show that the interbank network, the investment network, and the business credit network all obey the power-law distribution; the deposit network and the loan network exhibit a tendency for large banks to have larger degree distributions and small banks to have smaller degree distributions.


Introduction
With the continuous development of the modern financial industry, the financial market has become increasingly sophisticated, gradually evolving into a complex financial system that includes participation by multiple actors, including governments, financial institutions, enterprises, and households. In such a complex financial system, financial risks not only lead to dysfunction in the financial system but also have a serious impact on the real economy [1]. Additionally, the global economy has been negatively affected by COVID-19, which has led to serious debt crises and an increase in bad bank loans. erefore, there is an urgent need to study the interconnections between real economic risks and financial risks.
However, most existing studies pertaining to financial risk contagion have only focused on interbank networks, a focus which is far from sufficient to study financial contagion as a whole given the reality of a complex and multisubject financial system network. Additionally, existing studies concerning complex and multisubject networks have been more inclined to use endogenous macroeconomic network models to construct artificial microeconomic networks as a means of investigating topics such as economic growth, income distribution, and the effects of government policy [2][3][4], and so the focus of these network models has deviated from an investigation into financial correlation. erefore, this paper systematically reviews and summarizes previous studies with the aim of constructing a multiagent multilayer endogenous financial network model that includes an interbank network, an investment network, a deposit network, a business credit network, and a loan network consisting of banks, firms, households, and the government to lay the foundation for the further study of financial risk contagion within a more comprehensive framework.
In existing research concerning the network structure of real financial systems using empirical data, many universally accepted rules have been found. Among empirical studies of interbank networks, there are primarily three such rules: interbank networks obey small-world network characteristics [5][6][7], they obey scale-free network characteristics [8,9], and they have core-periphery network characteristics with respect to money centers [10][11][12]. Furthermore, a crisis in the banking sector impacts the real economy through the financial accelerator [13], so scholars have also studied the characteristics of the economic network structure. In existing research pertaining to networks composed of the banking sector and enterprises in the real economy, most scholars have found that the network is a power-law type and that the degree distribution is a power-law distribution with a thick tail [14][15][16].
Based on the rules of real financial networks mentioned above, many studies have attempted to construct financial networks using three different methods: network construction based on empirical data [17][18][19], exogenous network construction [20][21][22][23][24][25], and endogenous network construction [30][31][32][33][34][35][36][37][38][39][40][41][42][43]. However, for network construction based on empirical data, it is difficult to obtain all the data pertaining to the actual correlations among subjects in reality. Additionally, in terms of exogenous network construction, there is no consensus regarding exactly what network structure should be used to portray the associations among subjects in reality [26]. Furthermore, exogenous networks are static and homogeneous with respect to individuals, and the dynamic evolution of the network and heterogeneous behavior among individuals cannot be studied.
In recent years, with the rapid development of interdisciplinarity, certain methods from the fields of physics and engineering have been used in economics research, such as the use of chaotic systems to understand the complex behavior of real financial markets [27,28] and that of agentbased models (ABMs) to characterize the complex behavior of real financial agents. ABMs offer an easier way to achieve greater heterogeneity, allowing researchers to study heterogeneity, networks, and crisis dynamics in a macroeconomic context [29]. erefore, in terms of endogenous network construction, scholars have mainly used agentbased models and computational simulations to portray individual behavioral mechanisms and form complex networks. Scholars have conducted more research concerning single-agent, single-layer endogenous networks, such as interbank endogenous networks [30], supply chain endogenous networks [31,32], and credit endogenous networks [33], and the models constructed in this context are more mature. However, for systemic financial risk contagion, considering only a single agent and a single layer of the network cannot accurately reflect systemic financial risk and can significantly underestimate such risk [34,35]. erefore, scholars have invested more effort into the construction of multiagent and multilayer endogenous financial networks based on the business behavior mechanism among institutions in reality. ese models can be broadly divided into two categories. e first category focuses only on the impact of the banking sector on the real economy, and this model can better reflect the movement of the economic cycle, but the network model ignores the interbank market as an important risk contagion channel [36][37][38][39]. e other category focuses mainly on the banking sector and constructs models mainly to simulate monetary policy effects, thus lacking an interlinkage mechanism to the real economy [2,[40][41][42][43].
Most current ABM-based modeling in finance has focused on modeling a single market. e modeling of networks of economic systems with multiple agents has also focused on the endogenization of interfirm generative relationships, interbank lending, household consumption, and government policies. Few studies have also incorporated the endogenization of investment relationship networks among subjects, which in reality is an important channel for financial risk transmission and is the focus of this paper. In this paper, we integrate different financial agents at the micro-and macrolevels into the same organic whole by employing a financial system perspective, and we establish an endogenous, complex financial network consisting of different markets among agents, which makes the model highly relevant to the real financial system and allows it to serve as a basis for studying the formation and evolution of the financial system and to lay a foundation for the subsequent study of financial risk contagion. It should be noted that the model constructed in this paper is an endogenous financial network model in a general sense and is not specific to any one country or region. e contributions of this paper are as follows. First, we construct a four-sector model of financial system agent behavior mechanisms, including the government, banks, firms, and households, and generate a complex financial system network (including an interbank network, an investment network, a deposit network, a business credit network, and a loan network). Second, based on ABMs, the individual behavioral mechanism fully accounts for behavioral differences among individuals and allows them to interact and evolve in different financial networks. ird, the complex network can evolve toward a relatively stable state with few periodic fluctuations, and its characteristics are consistent with the findings of empirical research. e simulation results show that the model can converge to a stable state after endogenous evolutionary adjustment. In the steady state, the interbank network, investment network, and business credit network all obey the power-law distribution; the deposit network and loan network exhibit a tendency for large banks to have larger degree distributions and small banks to have smaller degree distributions. e model can still evolve toward a stable state within 100 periods after changing certain parameter values. After changing some main parameters, that is, the counterparty replacement parameter, the firm production target profit rate, or the initial firm financing multiplier, the robustness test shows that the financial network evolves to have the same network characteristics with different stable values. e remainder of the paper is structured as follows. Section 2 describes the model. e results of the simulation experiments are reported in Section 3. Robustness tests of the model are performed in Section 4. Finally, Section 5 concludes the paper.

Overview.
In the endogenous financial network model, we consider four types of agents: banks, firms, households, and the government. We build a complex, dynamic endogenous financial system network based on the behaviors (e.g., firm production and operation, household consumption and investment, or bank lending) and linkages among various agents. As shown in Figure 1, in the interbank market, banks lend or borrow money according to their liquidity. In the investment market, firms and households hold equity in firms, which constitutes the equity investment market; banks and households hold firm bonds and government bonds, which constitute the bond investment market. Households deposit money in banks in the deposit market. Business credit relations among firms constitute the business credit market. Banks lend money to firms and households in the loan market.
Firms are divided into supplier firms and terminal firms. Supplier firms and terminal firms form supply chain relationships with each other, and terminal firms form merchandising relationships with households. Firms develop a production plan, budget their capital, borrow from banks, finance themselves via the investment market, buy raw materials and pay their wage bills, hire workers, and sell their output in the supply chain market and the commodity market. If firms have sufficient funds, they invest in the equity investment market, and the profit is used to pay dividends.
Banks provide loans to firms and households. Each bank has to forecast its liquidity needs and take in or take out funds via the interbank market to meet its liquidity needs and to ensure that sufficient funds flow to the real economy. If banks have sufficient liquidity, they hold firm bonds and government bonds. Banks' liquidity is mainly the result of deposits in the household sector.
Households provide labor, receive income from wages paid by firms and financial assets, and use their income to buy consumer goods, invest, and save. If households' income does not cover their current consumption needs, they take out loans from banks.
In this paper, the government is assumed to act only as an issuer of government bonds. Since the focus of our model is on the financial correlations among individuals in each sector, the role of the government is simplified here.

Event Timeline.
e various types of agents are linked together by the multiple nonlinear feedback described above and evolve over a finite time horizon. With t � 1, . . ., T is indexed. In each period t, the following sequence of events occurs: (1) Firms produce and operate, and each firm determines the current period's production based on its own equity and past sales. (2) Firms purchase raw materials and hire labor. Firms purchase raw materials from upstream firms and hire labor from the household sector according to their output. is step establishes links among firms and between the firm and household sectors. (3) Firm investment and financing: if a firm faces a capital shortage, it takes out a loan from a bank or issues bonds to finance itself. If a firm has sufficient funds, it invests in the stocks of other firms. is step establishes a lending relationship between the firm and the bank and investment relationships among firms. (4) Households receive income from wages and financial investments. (5) Household consumption: households make consumption decisions based on their own consumption tendencies and purchase products from terminal firms. is step establishes a purchasing link between the household and firm sectors. (6) Household loans and investments: after a household has consumed, if there is a surplus of funds, this surplus is distributed among bank deposits, firm securities, firm bonds, and government bonds. If there is a shortage of funds, deposits are withdrawn from the bank, investments are recovered, and a loan is taken from a bank. is step creates a deposit link between households and banks, an investment link between households and firms, an investment link between households and the government, and a loan link between households and banks.

Firm Agents.
Suppose that there are N SF supplier firms and N TF terminal firms. Each supplier firm purchases production factors from upstream firms, hires labor, and sells its products to downstream firms after production; each terminal firm purchases raw materials from supplier firms, hires labor, and sells its products to the household sector after production. For each firm, if it has insufficient capital, it finances itself by borrowing from banks or issuing bonds; if it has sufficient liquidity, it holds equity in other firms for equity investment. e behavioral mechanisms of firms mainly include the following.
First, the firm produces and operates. Referring to Ishikawa et al. [44], the Cobb-Douglas production function is chosen such that, in period t, the desired output of firm j, product f j,t , depends on equity E f j,t and labor lab f j,t : (1)

Discrete Dynamics in Nature and Society
Under the constraint that the firm's equity is determined, the desired output then depends on the level of labor, so it is further assumed that product f j,t � lab f j,t /δ, where δ > 0. en, the labor required for the desired output under the equity constraint satisfies the following: In reality, there is more than one supplier for a core manufacturer, and the supplier is not only the supplier for a certain core manufacturer, so the supply chain relationship is actually a network model [45]. Supplier firm SF i randomly selects a certain percentage of all supplier firms as upstream firms and allocates their purchase volume according to the size of each upstream firm. Terminal firms TF j randomly select a certain percentage of all supplier firms as upstream firms and allocate their purchase volume according to the size of each upstream firm. At period t, at firm j's desired output, assuming that its target profit rate is r f j , the product it needs to buy from upstream firm BUY ff j,t can be expressed as follows: where wage denotes the unit price of labor. In the course of the transaction, a firm whose supply exceeds demand is in a buyer's market, such that a buyer's firm has a high market position and forms its payables YL, while a seller's firm forms its receivables YA at the same time. In contrast, when a firm's demand exceeds supply, it is in a seller's market, such that a seller has a high market position and forms its deposit received PYL, and a buyer forms prepayments PYA. It is assumed that the firm prefers to change to a supplier with abundant supply to reduce purchase costs. erefore, in each period, for reasons related to transaction costs, there is a certain probability that the connection to the old counterparty will be changed, and a new counterparty will be established [37]. In addition, we account for the heterogeneity of the product, and a new target supplier is chosen from other suppliers of other firms that are downstream of the original supplier. is approach ensures that similar products can be purchased.
is probability P j can be expressed as follows: where λ > 0; Ds new and Ds old are the supply and demand situations in which the old and new potential counterparties are located, respectively, so represents the total sales of firm i in period t-1, and Supply t−1 i represents the total supply of firm i in period t-1.
e second mechanism is firm financing. Firms need to purchase raw materials and hire labor to achieve their desired output in production and thus may face a funding gap. Firms mainly meet this funding gap by issuing bonds and by bank loans. In this paper, it is assumed that only the top 10% of firms in terms of size can meet part of the funding gap by issuing bonds and that financing demand is 50% each for bond financing and bank borrowing, while the funding gaps of the remaining firms are all met by bank loans. In period t, the financing demand of firm jFD f j,t can be expressed as follows: IN f j,t−1 represents the inventory of firm j in period t-1. See subsequent sections for the bank loan matching mechanism and bond market matching mechanism. e third mechanism is firm outbound investment. In period t, firm j engages in external investments if it has surplus liquidity after production and operation. In addition, its investment amount I f j,t satisfies the following: Since downstream companies holding shares in upstream companies in the supply chain is a relatively common form of strategic equity alliance [46], this paper assumes that firm j prioritizes a certain percentage of its upstream firms for equity investment and randomly selects other firms for equity investment if excess liquidity is still available. e funds are invested in the invested firms on a priority basis until the holding reaches 50% or more to achieve the purpose of controlling the investee firm; subsequently, other downstream firms are randomly selected to invest in the same holding to reach 50% or more; then, other firms are selected for investment. In summary, under ideal firm production conditions, if the demand of downstream firms for the product is greater than ideal production, this situation indicates that supply is less than demand, and so the firm sells all its products and occupies a strong market position; thus, the profit rate is larger than the target profit rate. If the demand of downstream firms for the product is less than ideal production, this situation indicates that supply is greater than demand, and so the firm develops an inventory; if excess inventory backlog emerges, the firm goes out of business. After earning profits from production and investment income and paying interest on bonds and loans, the net profit is finally obtained. All net profits are distributed to shareholders as dividends.

Bank Agents.
e number of banks is denoted by N B . e main source of funds for banks is households in the deposit market. Banks regulate liquidity via the interbank lending market under the supply constraint of funds, mainly by providing loans to firms and households, while investing in firm bonds and government bonds for income if there is surplus liquidity, so the behaviors involved in the use of funds mainly include the following. e first is interbank lending. In period t, banks borrow or lend funds via the interbank market according to their liquidity levels, where SLIQ b i,t and LLIQ b i,t , respectively, denote the short-term and long-term liquidity level of bank i in period t. Each potential debtor bank j observes the interbank lending rate offered to it by all banks, and following Zhang et al. [47], the short-term and long-term interbank lending rates are denoted as follows: where r 0 represents the risk-free interest rate, αs bb and αl bb denote the sensitivity of short-term and long-term interbank lending rates to interbank risk, respectively (higher values indicate higher risk premiums), SLIQ b i,t /OL i,t is the shortterm liquidity ratio of potential creditor bank i, LLIQ b i,t /OL i,t is the long-term liquidity ratio of potential creditor bank i, and LIL b j,t + SIL b j,t /E b j,t is the debt leverage ratio of potential debtor bank j, that is, the ratio of interbank borrowing to equity. For potential debtor banks, borrowing requests are sent to potential creditor banks, and if sufficient funds are not available from the first creditor bank, borrowing requests continue to be sent to other potential creditor banks to meet the shortfall until funding needs are met or until there is no more excess liquidity in the banking system. If the creditor bank has sufficient liquidity, all interbank borrowing requests are approved, and the potential debtor bank is converted into a debtor bank. If the creditor bank does not have sufficient liquidity to meet all borrowing requests, liquidity is allocated in descending order of the potential debtor bank's equity until no excess liquidity is available.
Second, banks extend loans. e issuance of loans by banks to firms and households is similar to interbank lending in that when a potential debtor firm or debtor household j applies to bank I for a loan, the interest rate on the loan that bank i can offer is as follows: where r 0 represents the risk-free interest rate, α bf and α bh denote the sensitivity of bank loan rates to risk (higher values indicate higher risk premiums), LIQ b i,t is the new liquidity of the bank and equal to the new deposits of the bank, LIQ b i,t /OL i,t is the liquidity ratio of potential creditor bank i, and DL f j,t /E f j,t or DL h j,t /E h j,t is the debt leverage ratio of potential debtor firms or debtor households j, that is, the ratio of firm or household loans to firm equity or household net assets. For potential debtor firms and households, loan applications are sent to potential creditor banks, and if sufficient funds are not available from the first creditor bank, loan applications continue to be sent to other potential creditor banks to meet the shortfall until funding needs are met or until there is no more excess liquidity in the banking system. If the creditor bank has sufficient liquidity, all loan applications are approved, and the potential debtor firm (household) is converted into a debtor firm (household). If the creditor bank does not have sufficient liquidity to satisfy all loan applications, liquidity is allocated in descending order according to the equity of the potential debtor firm (net assets of the household) until no excess liquidity is available.
ird, the bank invests. In period t, if bank i has excess liquidity after satisfying all loan requests, bank i makes bond investments, at which point its investment amount I b i,t satisfies the following: where DA b i,t represents the total number of loans held by bank i in period t. Banks allocate their investments to firm bonds and government bonds. Specifically, it is assumed here that the investment amount is first allocated among firm and government bonds according to the relative proportion of firm-issued bonds and government-issued bonds. Next, a certain number of firm bonds are randomly selected, and the investment amount in firm bonds is allocated in proportion to the size of the bond issue.
In summary, the bank obtains interest on loans, interest on interbank loans, and investment income in each period and obtains net profit after paying interest on deposits and interbank loans.
Discrete Dynamics in Nature and Society

Household Agents.
ere are N H households in the network. Differences in the levels of wealth, income, and propensity to consume of these households lead to different levels of consumption. If current consumption exceeds income, the household takes out a loan from a bank to meet current consumption needs, and if current income exceeds consumption, the household provides the surplus funds to banks via the deposit market or to firms or the government via the financial investment market to earn interest in the future. Household income comes from wages paid by firms and the income generated by investing in financial assets, which leads to real income in the current period.
First, following Popoyan et al. [2], the consumption of household i in period t depends on its expected lasting income and wealth (net assets). e expected lasting income PIC h i,t in period t is adjusted according to the actual income IC h i,t in the current period and can be expressed as follows: where λ h is the adjustment speed parameter. e actual income IC h i,t includes both interest income from financial assets and labor income. Household i's consumption CP h i,t in period t is a fraction of expected lasting income: where v i represents the propensity to consume. In this paper, household consumption mainly refers to purchasing products from terminal firms. Similarly, household i randomly selects a certain percentage of terminal firms from which to purchase products. e consumption amount CP h i,t is allocated to each terminal enterprise in the selected set according to the size of the selected firm. Similarly, households have a certain probability of changing the terminal firm used for consumption in each period, and the probability of changing is also based on Equation (4).
If actual income for the period is less than consumption, a loan from a bank is required, DL h i,t , in the amount of If actual income for the period is greater than consumption, the remaining income is invested. e investment amount FA h i,t can be expressed as follows: where FA h i,t � SA h i,t + CA h i,t + OA h i,t . Next, households further allocate financial investment FA h i,t among equity SA h i,t , debt CA h i,t , and deposits OA h i,t based on their risk attitudes; here, equity and bonds are risky assets, and deposits are risk-free assets, which in turn simplifies the problem of portfolio selection among risk-free and risky assets for households. For simplicity, the risk attitude of households is assumed to be related to the size of their net worth. e larger their net worth is, the more the risk-loving households are and the larger the proportion of risky assets they hold.

Balance Sheet.
e total balance sheet of the endogenous financial network is shown in Table 1. e sum of each row of the associated term is zero, and the sum of all columns is also zero. Assets are denoted by "+," and equities and liabilities are denoted by "−." Households are denoted by H, firms are denoted by F, banks are denoted by B, and the government is denoted by G. E B , E F , and E H denote the equity of the firm, equity of the bank, and net worth of the household, respectively. OA H and OL B denote the deposit association between household and bank. DA B , DL H , and DL F denote loans issued by banks, loans borrowed by households from banks, and loans borrowed by firms from banks, respectively. CA H and CA B denote the total number of bonds held by households and banks, respectively. CL F and CL G denote the total number of bonds issued by firms and by the government, respectively. SA H and SA F denote the total stock holdings of households and firms, respectively. YA F and YL F represent a firm's accounts receivable and accounts payable, respectively. SIA B and LIA B denote a bank's short-term and long-term interbank assets, respectively. SIL B and LIL B denote a bank's short-term and longterm interbank liabilities, respectively. CH B and CH F denote cash assets held by banks and firms, respectively. IN F indicates the inventory held by a firm. I G denotes government investment by government departments.

Simulations
Before the start of the formal evolutionary simulation, we performed the initialization of the model, and the initialization phase was not counted as part of the evolutionary period. At the initial moment, the firm's equity E f i is assumed to obey the Pareto distribution (parameter α � 3.5 and both multiplied by 250 adjusted orders of magnitude). e net worth of household E h j is assumed to obey a lognormal distribution (parameters μ � 1.5, σ � 0.7). Assume that the initial moment interbank network is generated exogenously according to the Barratt-Barthelemy-Vespignani-based (BBV-based) directed weighted network evolution rules discussed in Li et al. [25], after which bank asset size is determined based on the numerical scaling relationship. In the formal evolution phase, the interbank network evolves endogenously alongside other networks. e main parameter settings in the paper follow the suggestions by Gatti et al. [37], Georg [22], Li et al. [48], and Ma et al. [49]. e main parameters are set as shown in Table 2.
3.1. Network Structure. Based on the above parameter settings, a 100-period simulation is conducted in this paper, and we record the degree distribution of each network in the system at t � 100. Figure 2 is a log-log plot of the cumulative distribution of degrees for each network.
As shown in Figure 2(a), in the supply chain network, only a few firms have a large degree distribution and many connections to other firms. However, most firms have a smaller degree distribution and are less connected to other firms. is finding is consistent with the fact that, in the supply chain network, only a few core firms have a large number of upstream and downstream firms, while most firms have relatively few connections to other firms. Our simulation results reflect the tendency of supply chain networks to obey a power-law distribution that has been observed in empirical research. Additionally, Figure 2(b) shows that the interfirm business credit network also has a similar tendency. Similarly, only a few firms have a large degree distribution, and most firms have a small degree distribution.
is result is due to the fact that accounts receivable and accounts payable in the context of business credit are directly determined by the purchasing relationship in the supply chain network and that the core firm node in the supply chain network is also the core node in the business credit network. us, both the interfirm business credit network and the supply chain network obey a powerlaw distribution. Figure 2(c) shows the indegree distribution of firms in the equity investment network, which shows that most firms have small indegrees. A few firms have a large indegree, indicating that they receive a large amount of equity investment. ere are only a few core firms in the network that are large and operate with a high degree of quality, and investors mostly choose these firms for investment, so these firms receive a large amount of equity investment. Similarly, in Figure 2(d), only a few firms that have access to bond financing have a higher indegree. e investment network in our results also exhibits a power-law distribution.
Additionally, in Figures 2(e) and 2(f ), the degree distribution of the interbank network is characterized by a power-law distribution, which is consistent with the findings of empirical studies. In contrast, the deposit network in Figure 2 is result conforms with the fact that larger banks have a stronger capacity to absorb deposits, while smaller banks have a weaker capacity to do so. Additionally, in the loan network in Figure 2(h), larger banks are larger and more liquid; therefore, their outdegrees are larger, and they engage in more external lending. In contrast, smaller banks are less liquid and therefore have smaller outdegrees and make fewer external loans.  Discrete Dynamics in Nature and Society

Model Evolution.
e purpose of this paper is to establish a robust and stable endogenous financial network to lay a foundation for subsequent risk contagion research. In this section, we therefore document certain key indicators in the model in general, particularly the correlation items between sectors in the balance sheet. Our results show that the model evolution becomes stable within 100 periods.
As shown in Figure 3, the trend of total bonds held, total loans issued, and total deposits received by the banking sector as a whole over time is recorded. As the figure shows,  each indicator is accompanied by an adjustment process and tends to become stable after a series of adjustments. e three indicators tend to be stable and reach a stable state at approximately t � 60.
As shown in Figure 4, the indicators for the firm sector also reach a steady state at t � 60 and show small periodic fluctuations, a result which is similar to the findings of Gurgone et al. [36]. Each indicator has a substantial adjustment process from t � 0 to 10, after which it gradually tends toward a stable state.
For the household sector in Figure 5, again, all indicators level off at t � 60 after an initial adjustment. In addition, this figure also shows small cyclical fluctuations. As the firm sector adjusts its planned output to meet the actual demand of the market, the output is reduced, and less labor is required. en, the household sector's wage income decreases, leading to a decrease in household consumption, financial assets held, and deposits. To meet excess consumer demand, bank loans in the household sector increase. erefore, the adjustment of bank loans for households shows an inverse movement to the adjustment of several other items.
As shown in Figure 6, the total amount of bonds issued by the government exhibits a trend of falling, then rising, then falling again, and finally leveling off. e trend is broadly in line with the trend of bond assets held by banks, which show an inverse adjustment process to that of loans, as banks' liquidity is mainly used to issue loans and invest in bonds. Additionally, total corporate debt and total bonds held by households level off after the adjustment, with only minor fluctuations. e total amount of bonds issued by the government is therefore affected by the amount of bonds held and loans granted by banks.

Robustness Test
In this section, to verify the robustness of the constructed model, we modify some of the main parameters in the model for robustness testing. We change the values of the parameters λ, r f , and F r on the basis of Section 3, perform separate simulations to record the variation in each index listed in Section 3.2 over time, and observe the final robustness of the model.

Change to the Counterparty Replacement Parameter.
We hold all remaining parameters constant and change only the value of λ. e simulation is performed at λ � 0.08. e results show that, by changing the value of λ, the model can still converge to a steady state after adjustment.
As Figure 7 shows, total bonds held, total loans issued, and total deposits received by banks in the banking sector stabilize after the adjustment process subsequent to changing the parameter values.
e figure shows small cyclical fluctuations and the value of each indicator that reaches the steady state increases. is result is mainly due to the fact that, with an increase in λ, market frictions are reduced, more firms exhibit levels of supply and demand close to equilibrium, the output of the firm sector increases, demand for firm financing increases, and firms issue more bonds. us, the total amount of bonds held by the banking sector increases, and the increase in firm output inevitably leads to an increase in household sector income and hence an increase in deposits received by the banking sector.
As shown in Figure 8, after changing the values of the parameters, the indicators of the business sector also reach a steady state at t � 60, and each indicator has a substantial adjustment process from t � 0 to 10, after which it gradually tends toward a steady state accompanied by small periodic fluctuations.
e steady-state level of each indicator has improved. Additionally, due to reduced market frictions, there are more firms with levels of supply and demand close to equilibrium, production in the firm sector increases, demand for firm financing increases, firms issue more bonds, and the overall size of the firm sector increases.
For the household sector in Figure 9, all indicators, after the initial adjustment, once again level off at t � 60, with the values of the indicators becoming larger at the time of leveling off. For the same reason, the adjustment of bank loans by households shows an inverse movement to the adjustment of several other items. Due to the increase in production in the firm sector, there is an increase in the need for labor. is situation leads to an increase in the income of the household sector, which in turn leads to an increase in consumption, an increase in financial investment, and an increase in deposits and net worth.
As Figure 10 shows, the total amount of bonds issued by the government likewise exhibits a trend of falling, then Discrete Dynamics in Nature and Society rising, then falling again, and finally leveling off, except that the total amount increases in each period. e total amount of bonds issued by the government sector increases mainly because of an increase in investment demand due to the increase in household sector income.

Change to the Firm Production Target Profit Rate.
Additionally, we hold all remaining parameters constant and perform simulations at r f � 0.1. e results show that, by changing the value of r f , the model can still converge to a steady state after tuning. As Figure 11 shows, total bonds held, total loans issued, and total deposits received by banks in the banking sector stabilize after the adjustment process subsequent to changing the parameter values, and they show small cyclical fluctuations. e increase in B leads to a decrease in the raw materials purchased by firms and thus total production in the firm sector. is change leads to a decrease in the capital requirements of firms and therefore a decrease in the loans  granted by banks. In turn, banks use excess funds for bond investments. us, Figure 11 shows different total values for each indicator per period compared to Figure 3. As shown in Figure 12, after changing the parameter values, the indicators for the business sector also reach a steady state at t � 60, and each indicator has a substantial adjustment process from t � 0 to 10, after which it gradually tends toward the steady state with small periodic fluctuations. Moreover, the steady-state level of certain indicators decreases. is result is mainly due to the increase in r f , which leads to a decrease in the raw materials purchased by firms and thus the total production of the firm sector. is situation leads to a decrease in firms' capital requirements, a decrease in firms' levels of borrowing from banks, and a decrease in the bonds issued by firms. In turn, an increase in the firm production target profit rate r f leads to an increase in the overall size of the business sector and an increase in its holdings of stock assets.
For the household sector in Figure 13, all indicators level off once again at t � 60 after the initial adjustment, and the adjustment for household bank loans shows a movement opposite to that of the adjustment for several other items. As the output of the firm sector decreases, this situation leads to a decrease in the labor income of households and less consumption. However, due to the increase in the firm production target profit rate and consequently the increase in firm dividends, households' income from holding financial assets increases. erefore, households are more willing to hold financial assets for investment, and the total amount of financial assets held by the household sector increases. Due to higher returns on financial investments, certain households invest through bank loans; thus, the  household sector's borrowing from the banking sector increases. As Figure 14 shows, the total amount of bonds issued by the government likewise exhibits a trend of falling, then rising, then falling again, and finally leveling off, except that the total amount increases in each period. As the demand for financial investments in the household and banking sectors increases, so does the issuance of government bonds.

Change to the Initial Firm Financing Multiplier.
We hold all remaining parameters constant and perform the simulation at F r � 2. e results show that, by changing the value of F r , the model can still converge to a steady state after tuning.
As Figure 15 shows, total bonds held, total loans issued, and total deposits received by banks in the banking sector stabilize after the adjustment process subsequent to changing the parameter values, and they show small cyclical fluctuations. Due to the increase in the initial firm financing multiplier, these factors are more often financed via the financial investment market. us, loans to banks decrease, and corporate bonds purchased by banks increase. erefore, the total amount of bonds held by the banking sector in Figure 15(a) increased compared to the amount in each period shown in Figure 3(a), while loans granted by banks in Figure 15(b) decrease compared to those shown in Figure 3 As shown in Figure 16, after changing the parameter values, the indicators for the business sector also reach a steady state at t � 60, and each indicator has a substantial adjustment process from t � 0 to 10, after which it gradually tends toward the steady state. Moreover, due to the increase in the initial firm financing multiplier, the value of the indicators of the firm production segment increases as its input capital at production increases. e values of product, labor, sales, accounts receivable, and accounts payable in Figure 16 increase in each period compared to those shown in Figure 4.
For the household sector in Figure 17, all indicators level off once again at t � 60 after the initial adjustment. For the same reason, the adjustment for household bank loans shows a movement opposite to that of the adjustment for several other items. As firms increase their financing in the financial investment market, households' holdings of equity and bond assets increase.

Conclusion
Based on ABMs, this paper portrays the real-world behavioral mechanisms of banks, firms, households, and the government and investigates the construction of a multiagent, multilayer endogenous financial network model. e simulation results show that the supply chain network, the business credit network, the equity investment network, the bond investment network, and the interbank network all obey the power-law distribution; the deposit network and the loan network exhibit a tendency for large banks to have larger degree distributions and small banks to have smaller degree distributions; and the network model can be robust after endogenous adjustment.
We also found in subsequent robustness tests that the model can still evolve to a stable state within 100 periods after changing the main parameters. After increasing the counterparty replacement parameter λ, market frictions are reduced, which in turn leads to a more balanced matching of supply and demand among suppliers and an increase in the overall output of the firm sector. After increasing the firm production target profit rate r f , firms purchase fewer raw materials, and the overall output of the firm sector decreases. e increase in the firm sector's production target profit rate leads to an increase in the firm sector's external dividends, thus attracting more capital to the financial investment market. e increase in the initial firm financing multiplier F r allows firms to invest more capital in production, so output, sales, and labor demand all increase, and the financing needs of the firm sector also increase. Income, consumption, and investment in the household sector also increase.
is paper can serve as a basis for the study of risk contagion in endogenous macrofinancial networks, but the paper needs to be improved in the following respects: (1) Different debt maturities. In this paper, for the sake of simplicity, all debts exhibit the same maturity structures. (2) Diversity of agent behavior. In this study, for the sake of simplicity, the only government behavior is the issuance of government debt, and other behaviors are not considered. For the sake of a closer approximation to reality, diverse agent behaviors need to be considered. (3) Diverse types of agents. Central banks and nonbank financial institutions are not considered in the study. ese agents also play an important role in financial risk contagion.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare no conflicts of interest.