Playing with the endowment effect in Python

How to merge economics and psychology in 35 lines of code

Andrea Cattaneo
Towards Data Science

--

Photo by Amy Parkes on Unsplash.

One of the pillars of the behavioural economic theory is the endowment effect. In this article, we’re going to briefly show how it works, why it works and then we are going to write some lines of code in order to model it with Python.

Scenario

Imagine having 44 people in a room. Choose 22 of them at random and give them a coffee mug. After that, suppose you create a market in which any person can trade coffee mugs. People who have a coffee mug declare the minimum amount of money they require to sell the coffee mug (ask). Vice versa, every non-owner states the maximum price they are willing to pay for the coffee mug (bid). Once all reserve prices have been collected, we determine the number of trades by comparing asks and asks. If the highest bid is greater or equal to the lowest ask, we have at least one sale. If the second-highest bid is greater or equal to the second-lower ask we have at least two trades, and so on until the bid is lower than the ask (or we run out of reserve prices). All sales are made at the same price, determined by the highest ask accepted.

Example of how the market works. Three trades are made and the sales price is 4. Image by author.

How many trades do we expect in this market? According to the traditional economic theory, we can answer using the Coase theorem [1]. In essence, it says that in a market with no transaction costs, the resources will flow to the use that maximizes their value. To apply this theorem to our scenario, let’s assume to sort people by their perceived value of the coffee mug and randomly distribute the coffee cups in half of them.

A hypothetical perceived value scale. Image by author.

To reach equilibrium, all the coffee mugs in the lower half of the scale must flow to the people who value them the most. Since we distributed the coffee mugs randomly, we expect half of the cups to be in the lower half. Therefore, we can expect the number of exchanges to be half as many as available coffee cups.

Trades needed to reach equilibrium. Image by author.

The settings explained above are the exact experiment performed by Kahneman et al [2]. in 1990. Surprisingly, they found out that the average number of trades in a real-world scenario was 2.25, much lower than the 11 exchanges predicted by the Coase theorem. Why is that?

Endowment effect

The behaviour showed above can be explained by the endowment effect.

The endowment effect states that people are more likely to retain an object they own rather than acquire the same object when they do not own it.

Psychology has a clear explanation for this behaviour. Prospect theory [3] describes how individuals assess their losses and gains perspectives asymmetrically. This theory is strongly related to a cognitive bias known as Loss aversion, the human tendency to prefer avoiding losses rather than acquiring equivalent gains.

An interesting way of looking at the prospect theory is through its value function shown above. It relates the perceived utility by a person to gains and losses. The «pain» obtained when an individual gives away something is significantly greater than the «happiness» s/he acquires when s/he gets the same thing.

The prospect theory value function. Image by author.

The picture below shows the experimental situation. Before receiving the coffee mug, Harry (H) rates the object less than the top half of the other people. Thus, he’s a candidate for the transfer in case he receives the mug. But after receiving the cup, the perceived usefulness of the object has increased, so much so that he is now in the upper half of the value scale. Consequently, Harry will not sell his mug. The same phenomenon happens to all the other people who receive a coffee mug.

For this reason, the value scale will always be unbalanced. The top half will contain more people with the mug. It explains why fewer trades are needed to reach equilibrium.

The value scale before giving the coffee mugs. Image by author.
The value scale after giving the coffee mugs. Only one trade (K → B) is needed to reach equilibrium. Image by author.

Modelling the endowment effect in Python

Finally, let’s write some code. First of all, we declare a class called Sim. In the constructor, we create a list called prior_values ​​of length m to represent the a priori perceived value of the cup by each person. We initialize it with random values. After that, we initialize a list called mugs with ones and zeros randomly, where one means that the person has a coffee mug and zero otherwise.

The run() method calculates the perceived utility of the mug for each person. It uses the a priori values and the prospect theory’s value function. Finally, we compute the number of trades simulating a market that follows the rules explained above.

For the sake of simplicity, we approximate the prospect theory’s value function with the following piecewise linear function.

And here’s the code.

What we may want to do next is to find a value function able to explain the experimental results by Kahneman et al [2]. Our value function contains only one free parameter, so the challenge is to find the best value of α. Here Optuna comes to rescue.

First of all, we define an objective() function to be optimized. We use the Mean Squared Error (MSE), a well-known loss function. Since the simulation is stochastic, we proceed with a Monte Carlo approach. Given a value of α suggested by Optuna, we run the simulation N times and we compute the quadratic error across all the executions (the random seed is fixed only for reproducibility purposes).

The procedure is iterated 1000 times. At the end of all trials, we print the best value of α found. Notice that by default Optuna suggests parameters using the Tree-structured Parzen Estimator algorithm, but other algorithms are available.

>>> {'alpha': 8.378816205287283}

A fascinating property of the model is that the shape of the value function is independent of the distribution of the a priori values ​​if (and only if) k = m/2. If you want to deepen this point, I suggest you take a look at the full example available on GitHub.

This article was inspired by the amazing book “Misbehaving: The Making of Behavioral Economics” written by the Nobel Prize Richard H. Thaler.

[1] R. H. Coase, The Problem of Social Cost (1960), The Journal of Law and Economics

[2] D. Kahneman, J. L. Knetsch and R. H. Thaler, Experimental Tests of the Endowment Effect and the Coase Theorem (1990), Journal of Political Economy

[3] D. Kahneman and A. Tversky, Prospect Theory: An Analysis of Decision under Risk (1979), Econometrica

--

--