**In the absence of extensive experimental research in the field of mining, we can turn to modeling.Combined with other forms of analysis, modeling can make mining amenable to systematization and understanding, despite the opacity and capital intensity of the industry. Experimenting with setting up a mining venture is expensive. It is much cheaper to model it.**

"Anyone who tries to generate random numbers by deterministic methods is certainly living in sin."

- John von Neumann.

In the first article of this series, we built a modelMonte Carlo to approximate the fair value of mining equipment and the sensitivity of this fair value to various market parameters. We have shown that the market price of hashpower often deviates from its theoretical fair value, in part due to the instrument's illiquidity.

Also in the previous article we modeledfuture price trajectory using a diffusion jump model and used a linear function to measure the response of the global hash power to price changes. However, as mentioned in previous articles, the dynamics of the relationship between hashrate and price goes beyond a simple linear relationship. To improve the representativeness of the presented analysis system, it is necessary to go beyond characterizing the global hashpower as a unit and instead model it from the bottom up.

In this article, we classify miners intomultiple archetypes based on the type of machines used, total operating costs and preferred mining strategy. Each miner archetype has a different rate of return and risk factors. The profitability of mining changes over time, and each miner makes a profit or loss, which, in turn, determines his decisions to increase or decrease the number of working machines.

In this system, the change in the network hash rate is a function of not just the price change, but the aggregate of the overall results of all miners with different economic and risk profiles.

**The codebase of our model is completely open and accessible ****here****.**

You can change the assumptions we usedon your own and see how the simulated mining enterprise will work in the resulting conditions. In this article, I will go into detail about this model, describe using examples of its use and present some interesting conclusions drawn from the analysis of five different scenarios.

## John Conway's Game of Life

Our approach to modeling the network hash rate asthe sum of the results obtained by individual miners is based on a technique called agent-based modeling. This method grew out of John von Neumann's early work on cellular automata, published in the 1950s, and was popularized by John Conway in the game Life.

This is a step-by-step simulation taking place ona two-dimensional grid of cells. Predefined deterministic rules are set that govern interactions between neighboring cells. With each turn, the status of the cells changes depending on the status of the cells adjacent to it: cells come to life if they have exactly three living neighbors, remain alive if they have two or three living neighbors, otherwise the cells die off.

The game "Life" is a primitive example of an agent-basedsimulation, a type of simulation in which decisions are made by different actors sharing a global state. In the game "Life", agents are cells, and the decisions they make boil down to whether to live or die. The result depends solely on the initial state of the board and this state can change counterintuitively.

Today, agent-based modeling has advanced far beyond the Conway game and is widely used in ecology, economics, financial mathematics (PDF), and smart contract analysis (PDF).

The profitability of Bitcoin mining depends on the pricebitcoin, overall network hashrate and, to a lesser extent (for now), transaction fees. The second component in this ROI calculation, the network hashrate, depends on the decisions of other miners to start or shut down their machines. As a result, mining profitability forecasts must be iterative, and this task is well suited for agent-based modeling.

Assuming that the price of bitcoin is not at alldepends on the hash rate of the network, then it can be modeled the price as an autonomous geometric Brownian motion. In a similar vein, we model daily commissions as independent and lognormally distributed based on a constant block interval of 10 minutes.

Every day in the time series we consideras one move; at the beginning of each turn, the price of the asset, the size of the commission and the total hash rate of the network are transmitted to the agents of the miners as input data for making decisions.

Based on the net profit received, eachthe miner scales his enterprise by increasing or decreasing the number of machines connected to the network and publishes the resulting hash rate. The sum of the hash rates of all miners, in turn, is recorded as the new value of the total network hash rate:

</p>## Miners as agents

Modeling miners as agents is essentially a parameterization of input parameters in the mining economy. In Hashpower Alchemy, we introduced the concept *hash power reflexivity*: every mining company is highly dependent on both physical conditions and the subjective perception of the market by its operator.

It is impossible to cover all decision-making factors, but as the main determinants of the behavior of miners, we single out *type of machines used*, *cost basis* and *miner's strategy*... We formalize these factors in the form of parameters of the classes of miners.

### Machine type:

In the real world, a mining enterprise is usuallyoperates machines of various types. For simplicity, we have assigned each miner archetype to use one type of machine for the entire simulated period. In this version of the simulation, we support the following universe of machines:

</p>### Cost basis:

- Total electricity cost
- Energy consumption

Each miner is not assigned the average total cost of electricity for the entire simulation period. The power consumption of the miner is calculated as follows:

*Number of machines * Energy consumption of this type of machine.*

Every day of work, the miner incurs operating expenses equal to:

*Energy consumption / 1000 * Total cost of electricity * 24.*

Also, when initializing the model, we set the distribution of electricity tariffs, which determines the number of machines for each miner archetype.

In this version, we provide the following stratification by default. You can customize this parameter to your liking before starting the simulation.

### Strategy:

- Long BTC
- Daily sale

When initializing the model, each minerthe strategy is attributed. In practice, miners can use a wide variety of strategies and switch between them whenever their perception of market conditions changes.

For simplicity, in our model, each miner followsone strategy throughout the entire simulated period. We presented these two strategies and evaluated their profitability in different market cycles in a previous article.

**Long BTC** means that the miner sells just enough bitcoins to cover the operating costs, and keeps the rest of his income in BTC.

**Daily sale** means that the miner immediately exchanges all earned bitcoins for dollars.

The miner's strategy is determined by his position in BTC and the dollar. When calculating the profit for miners using the BTC long strategy, it is also necessary to take into account the unrealized profit: *BTC position * BTC price*.

Based on combinations of these three variables,we divided the universe of miners according to 11 types of machines, 7 ranges of electricity prices and 2 strategies, which gave a total of 154 archetypes.

When initializing the model, we set the stratificationmachines on the market and prices based on data from the Hashrate Index, General Mining Research and several other sources. These parameters can be adjusted as desired before starting the simulation.

*Distribution of electricity tariffs* and *machine stratification* represent the input for the calculation *number of cars* each miner.This is the number of pieces of equipment managed by the miner. It is important to note that in practice these two distributions are not statistically independent as in our model - for example, older machines like the S9s are more likely to be used by miners with access to cheaper electricity.

At the beginning of the simulation, the total indicator *Number of machines * Hashrate* for all miners is scaled to approximately equal to the current network hash rate according to Coin Metrics.

To track the profitability of the miner, we have added a simple account balance and historical profit calculator to the miner class.

### Account balance:

- USD position;
- position on BTC;
- hash power position.

The initial hashpower position is *number of cars * hashrate of cars of the corresponding type*.

### Profitability:

- Profit_Daily - daily profit;
- Profit_Last_30_Day - profit for the last 30 days;
- Profit_All - total profit.

The profitability determines the miner's behavior as the market situation develops. We'll look at this mechanism in the next section. *Profit_30_Days* and *Profit_All* - show the current profit at the corresponding point in time.

Below are all the items for the miner class. The code for the miner class is in the file *agents.py*.

## Miner utility function

With a high projected profitability, minersthey may want to expand their fleet of equipment, and in anticipation of negative profitability they may turn off some of the machines in order to reduce operating costs. We need to figure out exactly how miners scale their hashpower by increasing or decreasing the number of active machines.

In fact, there are a number of exogenous factors,affecting the miner's decision to buy or, conversely, turn off the machines, such as the availability of external funding and the quality of sleep. For simplicity, in our model, we take the historical profitability of the miner as the main decision-making factor.

The decision-making process takes as input the value *Profit_Last_30_Day* and calculates the result from which the action is taken. The process of calculating the result is as follows:

*If the value of Profit_Last_30_Day ≤0, the miner reduces the number of machines by*x*until break-even is reached. Payment*x*simple:*

*loss (Profit_Last_30_Day) is divided by the cost of electricity consumed per unit of equipment.**If the value of the variable Profit_Last_30_Day is positive and exceeds a certain threshold, the miner will increase the number of machines.*

*2a) Threshold value: Profit_Last_30_Day> sums of all costs.*

*2b) The increase in the fleet is calculated as follows:*

*(Profit_Last_30_Day - the sum of all costs) / Unit cost. equipment * Growth factor unit. equipment.**The price of the car changes dynamically during the simulation and is determined as follows:*

*Initial car price * (Current BTC price * Initial network hash) / (Initial BTC price * Current network hash).*

Mining equipment prices are adaptable andreact to changes in the asset price and network hashrate. Each type of machine also has its own growth rate, reflecting the relative rate of growth of its price. Older machines have a slower growth rate due to the reluctance of manufacturers to continue producing them. We also take into account the delay in adding new machines. It often takes some time to make and deliver an order to a customer.

In our model, this means that after increasing *x* - the value that triggers the adjustment of the amount of equipment - the machines will not be added to the miner's account immediately.

We have defined a list of constants that definedelay for each type of machine. The response lag is a static approximation and must be updated periodically to reflect changes in the throughput of the supply chain.

As a result, the trigger function returns the number of machines that the miner buys or sells.

Users can replace the growth factor and the default response times and times with any constants they want. The configuration code can be found in the file *Simulator.py*.

## Setting up the model

As in the first part, we usestochastic process for projecting bitcoin price and daily commission income for the entire simulated period. The basic parameters of the geometric Brownian motion model for price and lognormal distribution for commissions are obtained from historical price data (source: Coin Metrics).

Tying all of the above together, we use the following graph to illustrate the process:

</p>## Scenario analysis

To test the model, we modeleddifferent market conditions and analyzed the resulting behavior of the miners. We estimated the profitability of a miner with an initial capital for the purchase of equipment of $ 1 million and is deprived of the opportunity to further scale his enterprise. Simulations were run over a period of 100 days and the average of 25 tests were taken.

Profitability was measured at several different electricity costs in our universe of machine types. The highlights are shown below.

The parameters used are by no meansare final and users are free to carry out their own analysis based on any other assumptions. The script analysis code is in the file *main.py*.

### Scenario 1: bull market

Our first test simulates a bull market.Given the ongoing bull market at the time of this writing, we simply fitted the geometric Brownian motion model to historical data. Under these conditions, the price of BTC gradually increases to more than $ 100 thousand, undergoing several corrections along the way.

The network hash rate is growing steadily, undergoing some minor corrections that occur with some delay after episodes of price declines.

In these conditions, it is much more profitable to simplyhold the bitcoin position instead of selling mined BTC every day, even with high electricity rates. This makes sense given the rapid rise in the price of BTC.

With electricity at 4 ¢ / kWh, only miners using S9s and holding a position in BTC break even during the 100-day simulation period.

### Scenario 2: volatile market

For the second scenario, we simulate an unstablethe market by increasing the volatility in the historically valid geometric Brownian motion pattern by 25% and setting the drift value to zero. The price first rises to almost $ 80,000, and then drops sharply to just over $ 40,000.

The hash rate rises rapidly at first, but then plateaues in response to a fall in price. Due to the delay in response, the hash rate continues to grow, albeit at a much slower rate.

At first, both strategies work in a comparable way:BTC long strategy is only slightly ahead of daily selling in profitability. When the price of bitcoin falls, miners with BTC exposure are punished for the additional risk they have taken by lowering the market value of their assets.

### Scenario 3: bear market

In the third simulation, we simulate a bear market,fitting the model of geometric Brownian motion to historical data and changing the sign of the drift record. The price drops sharply from the current level and practically reaches $ 30 thousand.

In response to the price drop, the hash rate also corrects after the initial growth. This is the transition from the phase *disposal of stocks [equipment]* to phase *shaking off the market*using the terminology from Hashpower Alchemy.

In a bear market, everyone suffers, but most of allit affects bitcoin longs: with such a strategy and electricity at 4 ¢ / kWh, even the most efficient miners cannot recoup even half of their initial investment during the simulated period.

The daily sell strategy shows a much better result, but since miners' incomes still depend on the price of BTC, its profitability is also significantly lower than in a bull market.

### Scenario 4: Which machines are more profitable to work with in a bull market - old or new?

In the fourth scenario, we used the samehistorical parameters, as in the first, to compare the efficiency of miners working with old and new equipment at a competitive cost of electricity.

This time, the price of BTC soars to $ 140K, accelerating in the process. The hashrate is also growing rapidly.

With such intensity of a bull market, evenminers with a daily sell strategy manage to break even during the 100-day simulated period, provided they are running S9s. The profitability of S19 miners is significantly lower, but still the strategy of daily sale allows them to return most of the initial investment.

Miners holding long BTC in theseconditions are incredibly profitable. Miners with S9s have almost doubled their initial investment over the simulated period. The S19 miners also managed to make significant profits.

### Scenario 5: In a bear market, how important is lower operating costs?

In the fifth and final simulation, we are againsimulated bear market conditions, this time to analyze the role of energy costs in overall profitability. To do this, we evaluated the efficiency of miners working with S9 and S19 in a bear market with electricity costs of 3, 4 and 5 cents per kWh.

The market situation is similar to scenario # 3: the BTC price drops sharply and the hash rate undergoes a shallow but prolonged correction.

For miners with S9, the cost of electricity hasessential. Although at any level of electricity costs, the efficiency of mining in these conditions leaves much to be desired, miners holding long BTC with electricity at 3 ¢ / kWh recoup almost 40% of the initial investment, while their counterparts with electricity at 5 ¢ / kWh only return a little less than 32%.

This sensitivity to electricity costs explains why S9 miners typically operate in peripheral regions with cheaper electricity.

For miners with S19, this difference is not so pronounced. Of course, the cost of electricity in any case affects the profitability of mining, however, when using the S19, this effect is much less pronounced.

## Conclusion

Multidimensionality is the enemy of statistics, and modelingBitcoin mining is not an easy task. Even our model, with all its simplifying assumptions, ended up being much more complex than we originally thought. As with all Monte Carlo-based instruments, its predictive power is fundamentally limited by user bias, which, through the initial input conditions, is reflected in any results obtained.

Our model explicitly assumes that the relationshipbetween price and hash rate is unidirectional. Implicitly, it assumes that there is no relationship between the likely correlated distribution of equipment models and energy costs. Basically, all the models are wrong, but some of them are useful.

This model, in our opinion, is useful and should find its way into the toolkit of a reasonable bitcoin miner.

</p>