Using the python class, try to roughly simulate the production behavior of 1 farmer and the consumption behavior of 1 consumer ① ~ Time to explain the conditions ~

Thanking you in advance. I'm a little nervous because I'm really new to python and simulation. The code of "Using python class ... ①" uploaded this time is not released because it is only a condition setting and background explanation. If you want to see only the result, please skip to the next using python class …… ②.

Academic background of posters

I am doing research in agricultural economics at graduate school. I started studying microeconomics and econometrics in the second half of my undergraduate program. I'm not studying this article. At the python level, I had a friend-sponsored seminar give me a rough overview of installation and external modules, and I read the famous "Python Data Science Handbook" by Jake VanderPlas. The simulation is about the end of "Numerical calculation and simulation by Python" by Tomohiro Odaka. From the above, both python and simulation are beginners, and microeconomic theory is also at the intermediate level of the undergraduate level.

Academic background of this effort

I met Taylor (2005), Dyer (2006), and Janvry (1991), who are related to Agricultural Household Model, and became interested in simulation. So, I decided to make my own simulation with python even though I was an amateur! I would like to create a village or a program that simulates the villages that reflect the contents of the above three papers.

Are the top researchers a model that accumulates economic models such as SAM and CGE? It seems to analyze with. Perhaps the model above? I think that the optimal solution is "calculated" by using. Also, it seems that you can do it relatively easily by using software called GAMS. On the other hand, I wasn't prepared or paid to buy GAMS, and I wanted to make something like a 2D game later, so I used the python class. In addition, when obtaining the optimum solution, we used a method of randomly selecting selection variables and finding the best combination that maximizes the objective function. If my interpretation is correct, this method will not "calculate" the optimal solution and will give you the best solution of the myriad lottery. For the time being, the image is a multi-agent simulation. However, it is unknown whether this made this time is a multi-agent.

What I want to do this time

When I showed it to my supervisor after making it, After some indications, I received a comment saying, "It looks like the production and consumption behavior of self-sufficient farmers." I announced later that I should have done so, but for the time being, I built the program with the following contents.

(1) There is one farmer and one consumer in this world. (2) There are two types of products, A and B. Farmers also engage in non-farm labor. ③ A is grain and B is fruit (image). ④ Farmers make A and B so as to maximize the sum of total production and non-farm wages, and consumers consume A and B so as to maximize utility. ⑤ The price of a product that is consumed a lot rises, and the price of a product that is consumed less often falls.

Farmer and consumer behavior model

I will insure it for the time being, Originally from the Faculty of Agriculture, I am mostly self-taught in microeconomics. The expression may be wrong. I'm sorry in that case.

Relationship between farmers and consumers

In the situation assumed this time, the farmer is a factory that only produces agricultural products, and the consumer is a person who only consumes the produced agricultural products. There are no other people in this world other than these two, and there are no transactions with people in other worlds. Therefore, the price of agricultural products changes depending on the transaction status of these two people. In addition, A and B, which were once made and not consumed, are set to be carried over to the next term.

Farmer behavior

The farmer assumed here is like an agricultural product production factory and does not consume. In addition, there are only two production factors to be input, the self-owned labor force (L) and the other self-owned production factors (K: tractor and land), and there is no access to the production factor market. The farmer also works outside the farm. From the above, this farmer allocates the factors of production to A and B so as to maximize the total production value + non-farm income (can be said to be profit?). The formula that expresses the above state is as follows.

\Pi = p_A*Q_A+p_B*Q_B+w*L_n...(1) \\ Q_A = k*L_A^\alpha *K_A^{1-\alpha}...(2) \\ Q_B = L_B^\beta *K_B^{1-\beta}...(3) \\ \bar{L} = L_A+L_B+L_n...(4) \\ \bar{K} = K_A+K_B...(5)

$ \ Pi $: Total production (profit?) $ p_A, p_B $: Prices of agricultural products A and B (producer price = consumer price) $ w $: Wage $ Q_A, Q_B $: Produce of agricultural products A and B. The functional type of the production function is Cobb-Douglas for the time being $ L_A, L_B, L_n : Labor force allocated to A ( L_A ), B ( L_B ), and non-farm labor ( L_n $) $ K_A, K_B $: Input of other factors of production allocated to A and B $ \ bar {L}, \ bar {K} $: Self-owned labor and other factors of production, upper limit of use of each factor of production $ \ Alpha, \ beta $: Distribution rate of labor and other factors of production in products A and B (sum of distribution rate is 1: constant harvest) $ k $: A is a grain, so a coefficient (> 1) that expresses that you can make more quantity than fruit B.

Consumer behavior

Farmers are not included in the consumers considered here. This consumer consumes A and B to maximize their utility (satisfaction). The constraints are (1) budget constraint, (2) supply for this term + surplus for the previous term> consumption for this term, and (3) satiety constraint.

U = c_A^\gamma+c_B^{1-\gamma}...(1) \\ I_t = I_{t-1} + i - C_{t-1} > C_t = p_A*c_A + p_B*c_B...(2:① Budget constraint) \\ Q_{A,t} + s_{A,t-1} > c_{A,t}...(3:② Supply+Remainder> Consumption) \\ Q_{B,t} + s_{B,t-1} > c_{B,t}...(4:② Supply+Remainder> Consumption) \\ c_A + c_B < Appe...(5:③ Satiety restriction)

$ U $: Utility (satisfaction) $ c_A, c_B $: Consumption of A and B. Cobb-Douglas was also used for the functional type of the utility function. $ I_t $: Total budget for period t $ C_t $: Total expenditure in period t, different from consumption c (lowercase) $ i $: Income for that period $ s_ {t-1} $: The surplus in the t-1 period $ Appe $: appetite, a constant that represents how much you can eat $ \ Gamma $: A multiplier that indicates the impact of consumption of A and B on utility

Others (Please confirm the explanation about price formation)

① Next budget: $ I_ {t + 1} = I_t + i --c_t $ ② Carry-over amount for the next term: $ s_ {t + 1} = s_t + Q_t --c_t $ ③ Next price determination method (0 <r <1)  if (Q_t + s_{t-1} - c_t)/(Q_t + s_{t-1}) < r:   p_{t+1} = 1.01 * p_t

else:   p_{t+1} = 0.99 * p_t

☆ ③ (Price formation) If the consumption of a certain agricultural product is close to the upper limit of consumption, the price of the agricultural product will increase because it is a popular product. On the other hand, if a produce is not consumed at all, it becomes an unpopular product and its price drops. With the above settings, prices will change depending on the behavior of farmers and consumers. In the image, it seemed that the production of too many agricultural products stopped and the production of insufficient agricultural products was promoted, but due to the following drawbacks, it became a subtle feeling.

Reflections

The price setting was not good.

Below, for convenience A market that pays farmers the amount of production, temporarily stores agricultural products, and changes the price of agricultural products is called a "market." Originally, the equilibrium price should be formed by consumption = production. The payment to the farmer is made by the market, not the consumer, and nevertheless neither the farmer nor the market receives the payment paid by the consumer (disappears). It seems that the setting is bad. Perhaps because of this, the equation for the amount of money in circulation does not hold. Due to the above, the price should normally converge to a certain price range, but as shown next time, it will wander around.

From the beginning, should we build a model that creates the production and consumption behavior of "self-sufficient farmers in grain A"? In that case, the farmer first randomly allocates the factors of production to produce A (grain) and B (fruit). Suppose A consumes itself and B sells in the market. Next, turn to the consumer side and add a new co (o of others) as a consumer good. At this time, the self-sufficient farmer considers a combination that maximizes the utility U = U (cA, co) given the income earned from the sale of B and the off-farm labor. On the other hand, if you want to reproduce the situation where a large number of consumers, producers and retailers are crowded instead of considering a self-sufficient farmer, it is necessary to balance not only the amount of agricultural products but also the amount of money. come out. In this case, I have to bring up macroeconomic theory, which is beyond my knowledge. I haven't studied macroeconomics yet ...

So, next time will send you (1) put a constant in the parameter, (2) show the code you made, and (3) briefly consider the result. To do.

Thank you for your continued support.

References

~ Paper ~ [1]Alain de Janvry, Marcel Fafchamps and Elisabeth Sadoulet(1991) “Peasant household behavior with missing markets: some paradoxes explained” Economic Journal. Vol.101, pp.1400-1417. [2]George A. Dyer, Steve Boucher, and J. Edward Taylor(2006) “Subsistence response to market shocks” American journal of agricultural economics. Vol. 88, pp. 279-291. [3]J.Edward Taylor, George A. Dyer, Antonio Yu'nez-Naude(2005) "Disaggregated Rural Economywide Models for Policy Analysis" World Development. vol. 33, pp. 1671-1688

~ Textbook ~ [1] Tomohiro Odaka (2018): "Numerical Calculation and Simulation with Python", Ohmsha [2]Jake VanderPlas(2016) "Python Data Science Handbook: Essential Tools for Working with Data", O'Reilly Media

Recommended Posts

Using the python class, try to roughly simulate the production behavior of 1 farmer and the consumption behavior of 1 consumer ① ~ Time to explain the conditions ~
Using the python class, roughly simulate the production behavior of one farmer and the consumption behavior of one consumer ② ~ Time to see the results ~
Using the python class, try simulating the production and consumption behavior of self-sufficient farmers very roughly and easily ① Condition setting
Using the python class, try simulating the production and consumption behavior of self-sufficient farmers very roughly and easily ② See the code and results
Try to solve the Python class inheritance problem
Try using the collections module (ChainMap) of python3
Try to simulate the movement of the solar system
Try to make it using GUI and PyQt in Python
Try to get the function list of Python> os package
Try to automate the operation of network devices with Python
I want to know the features of Python and pip
The story of returning to the front line for the first time in 5 years and refactoring Python Django
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.
Determine the date and time format in Python and convert to Unixtime
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
How to get followers and followers from python using the Mastodon API
[Introduction to Python] I compared the naming conventions of C # and Python.
I tried to make a regular expression of "time" using Python
[Python] How to get the first and last days of the month
[Python3] Define a decorator to measure the execution time of a function
Get and set the value of the dropdown menu using Python and Selenium
Convert the result of python optparse to dict and utilize it
Try to implement and understand the segment tree step by step (python)
[python] A note that started to understand the behavior of matplotlib.pyplot
Try using FireBase Cloud Firestore in Python for the time being
I tried to deliver mail from Node.js and Python using the mail delivery service (SendGrid) of IBM Cloud!