Playing with the endowment effect in Python | by Andrea Cattaneo | Jan, 2021

0
52

Finally, let’s write some code. First of all, we claim a category known as Sim. In the constructor, we create an inventory known as prior_values ​​of duration m to constitute the a priori perceived price of the cup by every particular person. We initialize it with random values. After that, we initialize an inventory known as mugs with ones and zeros randomly, the place one implies that the particular person has a espresso mug and 0 differently.

The run() means calculates the perceived application of the mug for every particular person. It makes use of the a priori values and the prospect concept’s price serve as. Finally, we compute the selection of trades simulating a marketplace that follows the laws defined above.

For the sake of simplicity, we approximate the prospect concept’s price serve as with the following piecewise linear serve as.

And right here’s the code.

What we would possibly wish to do subsequent is to discover a price serve as ready to give an explanation for the experimental effects by Kahneman et al [2]. Our price serve as incorporates just one loose parameter, so the problem is to seek out the perfect price of α. Here involves rescue.

First of all, we outline an purpose() serve as to be optimized. We use the Mean Squared Error (MSE), a well known loss serve as. Since the simulation is stochastic, we continue with a Monte Carlo way. Given a worth of α prompt by Optuna, we run the simulation N occasions and we compute the quadratic error throughout all the executions (the random seed is mounted just for reproducibility functions).

The process is iterated 1000 occasions. At the finish of all trials, we print the perfect price of α discovered. Notice that by default Optuna suggests parameters the usage of the Tree-structured Parzen Estimator set of rules, however .

>>> {'alpha': 8.378816205287283}

An interesting assets of the style is that the form of the price serve as is impartial of the distribution of the a priori values ​​if (and provided that) ok = m/2. If you need to deepen this level, I counsel you check out the complete instance to be had on .

LEAVE A REPLY

Please enter your comment!
Please enter your name here