Python Code and cloud servers#
Most of the code used for this project is in a Contract.py python module that is imported at the top of each notebook. This allows us to use object oriented programming to establish Contract objects which help define a particular contracting environment, specifying parameter attributes and providing a number of methods for calculating useful values or optimal contracts.
To run this and other notebook pages interactively you will need to be running a jupyter server. There are a few options available for doing this described at the very end of this page.
Here we describe the basics of using the Contract
module. We get things started by importing the module:
import Contract
This defines a Contract
class which serve to create different instances of contract objects. For example, below we define cC
as an instance of the competitive contract object and we examine its default parameters with the print_params
method.
cC = Contract.Competitive(beta=0.7)
cC.print_params()
beta : 0.7
kappa : 0
rho : 1.2
y : [100 100 100]
We can use other methods to do things such as find the “full commitment” (i.e. first-best) contract under the assumption that banks would never renegotiate.
You can see how this present-biased consumer borrows in period 0 and then sets up constant repayments in period 1 and 2. The consumer’s optimum consumption smoothing contract is:
cC.fcommit()
array([120.68803907, 89.65598047, 89.65598047])
Given that the consumer has an income stream y
we can see the borrowing (-) and repayments as:
cC.y - cC.fcommit()
array([-20.68803907, 10.34401953, 10.34401953])
We also have methods for doing things such as find the minimum renegotiation penalty that allows us to sustain the \(\bar \kappa\).
cC.kbar()
2.3294778074268097
If the bank faces renegotiation costs \(\kappa > \bar \kappa\) then the full-commitment contract will be ‘renegotiation-proof’. Note how we first change the value of the \(\kappa\) parameter associated with this particular contract. We then find the renegotiation proof contract.
cC.kappa = 10
cC.reneg_proof()
array([120.68803907, 89.65598047, 89.65598047])
If, however, the bank faces a renegotiation costs \(\kappa < \bar kappa\) then the ‘renegotiation-proof’ contract will become distorted. Period-0 self needs to tilt the contract toward the contract preferred by her later self by just enough to reduce future gains to renegotiation by enough to make a renegotiation-proof contract work with the available external \(\kappa\) renegotiation penalty.
cC.kappa = 1
cC.reneg_proof()
array([120.84922353, 94.16379033, 84.98698614])
Running on a Cloud Server#
Options to run this and other pages interactively:
Binder or Google Colab Cloud Servers: Click on the rocket icon at the top of this page to launch one of these cloud server services.
Binder: this will create a virtual machine which will allow you to run the notebooks. It may take some time to first build and launch.
Google Colab: this will launch a jupyter notebook server of the current notebook. You will need to make the
Contract.py
module available to google’s colab environment. You need to replace the code cell that saysimport Contract
with the following instead:!git clone https://github.com/jhconning/commitments.git import commitments.notebooks.Contract as Contract
If you have a jupyter kernel runing on your local machine. Clone jhconning/commitments and then run the notebooks yourself.