diff --git a/doc/pub/How2ReadData/html/How2ReadData-bs.html b/doc/pub/How2ReadData/html/How2ReadData-bs.html index 2997777e7..794b43afd 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-bs.html +++ b/doc/pub/How2ReadData/html/How2ReadData-bs.html @@ -102,11 +102,7 @@ Automatically generated HTML file from DocOnce source None, '___sec35'), ('Simulating financial transcations', 2, None, '___sec36'), - ('Project 4a): Simulation of Transactions', 3, None, '___sec37'), - ('Project 4b): Recognizing the distribution', - 3, - None, - '___sec38')]} + ('Simulation of Transactions', 3, None, '___sec37')]} end of tocinfo --> @@ -181,8 +177,7 @@ MathJax.Hub.Config({
  • Parameter estimation
  • A program relevant for the biological problem
  • Simulating financial transcations
  • -
  •    Project 4a): Simulation of Transactions
  • -
  •    Project 4b): Recognizing the distribution
  • +
  •    Simulation of Transactions
  • @@ -216,7 +211,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    May 9, 2018

    +

    May 11, 2018


    @@ -1412,7 +1407,7 @@ Change r in the program and play around to make a better fit!

    Simulating financial transcations

    -The aim of this project is to simulate financial transactions among financial agents +The aim here is to simulate financial transactions among financial agents using Monte Carlo methods. The final goal is to extract a distribution of income as function of the income \( m \). From Pareto's work (V. Pareto, 1897) it is known from empirical studies that the higher end of the distribution of money follows a distribution @@ -1483,9 +1478,9 @@ exponentially decreases with \( m' \). We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments). -

    Project 4a): Simulation of Transactions

    +

    Simulation of Transactions

    -Your task is to first set up an algorithm which simulates the above transactions with an initial +Our task is to first set up an algorithm which simulates the above transactions with an initial amount \( m_0 \). The challenge here is to figure out a Monte Carlo simulation based on the above equations. @@ -1496,12 +1491,45 @@ Your task is to first set up an algorithm which simulates the above transactions \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. You will also need to find a criterion for when the equilibrium situation has been reached. -

    Project 4b): Recognizing the distribution

    +

    -Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \) - and see if you get a straight line. - Comment the result. + +

    #!/usr/bin/env python
    +import numpy as np
    +import matplotlib.mlab as mlab
    +import matplotlib.pyplot as plt
    +import random
     
    +# initialize the rng with a seed
    +random.seed()
    +# Hard coding of input parameters
    +Agents  = 500
    +MCcounts = 1000
    +Transactions = 100000
    +startMoney = 1.0
    +Lambda = 0.0
    +FinancialAgents = startMoney*np.ones(Agents)
    +for i in range (1, MCcounts, 1):
    +    for j in range (1, Transactions, 1):
    +        agent_i = int(Agents*random.random())
    +        agent_j = int(Agents*random.random())
    +        epsilon = random.random()
    +        if agent_i != agent_j:
    +           m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           FinancialAgents[agent_i] = m1
    +           FinancialAgents[agent_j] = m2
    +
    +# the histogram of the data
    +n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green')
    +
    +plt.xlabel('$x$')
    +plt.ylabel('Distribution of wealth')
    +plt.title(r'Money')
    +plt.axis([0, 10, 0, 500])
    +plt.grid(True)
    +plt.show()
    +

    We can then change our model to allow for a saving criterion, meaning that the agents save a fraction \( \lambda \) of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions. @@ -1554,7 +1582,6 @@ $$ Extract a parametrization of the above curves, see for example Patriarca and collaborators and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.

    -In the rest of this project we will follow the work of Goswami and Sen. In the studies above the agents were selected randomly, irrespective of whether we allowed for saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth \( w_m \) by assuming that there is a likelihood $$ diff --git a/doc/pub/How2ReadData/html/How2ReadData-reveal.html b/doc/pub/How2ReadData/html/How2ReadData-reveal.html index bde796e6e..58a26c5a5 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-reveal.html +++ b/doc/pub/How2ReadData/html/How2ReadData-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({

    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

     
    -

    May 9, 2018

    +

    May 11, 2018


    @@ -1310,7 +1310,7 @@ Change r in the program and play around to make a better fit!

    Simulating financial transcations

    -The aim of this project is to simulate financial transactions among financial agents +The aim here is to simulate financial transactions among financial agents using Monte Carlo methods. The final goal is to extract a distribution of income as function of the income \( m \). From Pareto's work (V. Pareto, 1897) it is known from empirical studies that the higher end of the distribution of money follows a distribution @@ -1393,9 +1393,9 @@ exponentially decreases with \( m' \). We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments). -

    Project 4a): Simulation of Transactions

    +

    Simulation of Transactions

    -Your task is to first set up an algorithm which simulates the above transactions with an initial +Our task is to first set up an algorithm which simulates the above transactions with an initial amount \( m_0 \). The challenge here is to figure out a Monte Carlo simulation based on the above equations. @@ -1406,12 +1406,45 @@ Your task is to first set up an algorithm which simulates the above transactions \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. You will also need to find a criterion for when the equilibrium situation has been reached. -

    Project 4b): Recognizing the distribution

    +

    -Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \) - and see if you get a straight line. - Comment the result. + +

    #!/usr/bin/env python
    +import numpy as np
    +import matplotlib.mlab as mlab
    +import matplotlib.pyplot as plt
    +import random
     
    +# initialize the rng with a seed
    +random.seed()
    +# Hard coding of input parameters
    +Agents  = 500
    +MCcounts = 1000
    +Transactions = 100000
    +startMoney = 1.0
    +Lambda = 0.0
    +FinancialAgents = startMoney*np.ones(Agents)
    +for i in range (1, MCcounts, 1):
    +    for j in range (1, Transactions, 1):
    +        agent_i = int(Agents*random.random())
    +        agent_j = int(Agents*random.random())
    +        epsilon = random.random()
    +        if agent_i != agent_j:
    +           m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           FinancialAgents[agent_i] = m1
    +           FinancialAgents[agent_j] = m2
    +
    +# the histogram of the data
    +n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green')
    +
    +plt.xlabel('$x$')
    +plt.ylabel('Distribution of wealth')
    +plt.title(r'Money')
    +plt.axis([0, 10, 0, 500])
    +plt.grid(True)
    +plt.show()
    +

    We can then change our model to allow for a saving criterion, meaning that the agents save a fraction \( \lambda \) of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions. @@ -1474,7 +1507,6 @@ $$ Extract a parametrization of the above curves, see for example Patriarca and collaborators and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.

    -In the rest of this project we will follow the work of Goswami and Sen. In the studies above the agents were selected randomly, irrespective of whether we allowed for saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth \( w_m \) by assuming that there is a likelihood

     
    diff --git a/doc/pub/How2ReadData/html/How2ReadData-solarized.html b/doc/pub/How2ReadData/html/How2ReadData-solarized.html index 81d0df7e3..95a95fee7 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-solarized.html +++ b/doc/pub/How2ReadData/html/How2ReadData-solarized.html @@ -122,11 +122,7 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec35'), ('Simulating financial transcations', 2, None, '___sec36'), - ('Project 4a): Simulation of Transactions', 3, None, '___sec37'), - ('Project 4b): Recognizing the distribution', - 3, - None, - '___sec38')]} + ('Simulation of Transactions', 3, None, '___sec37')]} end of tocinfo --> @@ -168,7 +164,7 @@ MathJax.Hub.Config({

    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    May 9, 2018

    +

    May 11, 2018












    @@ -1330,7 +1326,7 @@ Change r in the program and play around to make a better fit!

    Simulating financial transcations

    -The aim of this project is to simulate financial transactions among financial agents +The aim here is to simulate financial transactions among financial agents using Monte Carlo methods. The final goal is to extract a distribution of income as function of the income \( m \). From Pareto's work (V. Pareto, 1897) it is known from empirical studies that the higher end of the distribution of money follows a distribution @@ -1401,9 +1397,9 @@ exponentially decreases with \( m' \). We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments). -

    Project 4a): Simulation of Transactions

    +

    Simulation of Transactions

    -Your task is to first set up an algorithm which simulates the above transactions with an initial +Our task is to first set up an algorithm which simulates the above transactions with an initial amount \( m_0 \). The challenge here is to figure out a Monte Carlo simulation based on the above equations. @@ -1414,12 +1410,45 @@ Your task is to first set up an algorithm which simulates the above transactions \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. You will also need to find a criterion for when the equilibrium situation has been reached. -

    Project 4b): Recognizing the distribution

    +

    -Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \) - and see if you get a straight line. - Comment the result. + +

    #!/usr/bin/env python
    +import numpy as np
    +import matplotlib.mlab as mlab
    +import matplotlib.pyplot as plt
    +import random
     
    +# initialize the rng with a seed
    +random.seed()
    +# Hard coding of input parameters
    +Agents  = 500
    +MCcounts = 1000
    +Transactions = 100000
    +startMoney = 1.0
    +Lambda = 0.0
    +FinancialAgents = startMoney*np.ones(Agents)
    +for i in range (1, MCcounts, 1):
    +    for j in range (1, Transactions, 1):
    +        agent_i = int(Agents*random.random())
    +        agent_j = int(Agents*random.random())
    +        epsilon = random.random()
    +        if agent_i != agent_j:
    +           m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           FinancialAgents[agent_i] = m1
    +           FinancialAgents[agent_j] = m2
    +
    +# the histogram of the data
    +n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green')
    +
    +plt.xlabel('$x$')
    +plt.ylabel('Distribution of wealth')
    +plt.title(r'Money')
    +plt.axis([0, 10, 0, 500])
    +plt.grid(True)
    +plt.show()
    +

    We can then change our model to allow for a saving criterion, meaning that the agents save a fraction \( \lambda \) of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions. @@ -1472,7 +1501,6 @@ $$ Extract a parametrization of the above curves, see for example Patriarca and collaborators and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.

    -In the rest of this project we will follow the work of Goswami and Sen. In the studies above the agents were selected randomly, irrespective of whether we allowed for saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth \( w_m \) by assuming that there is a likelihood $$ diff --git a/doc/pub/How2ReadData/html/How2ReadData.html b/doc/pub/How2ReadData/html/How2ReadData.html index 08f1880ee..17aa7faa0 100644 --- a/doc/pub/How2ReadData/html/How2ReadData.html +++ b/doc/pub/How2ReadData/html/How2ReadData.html @@ -127,11 +127,7 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec35'), ('Simulating financial transcations', 2, None, '___sec36'), - ('Project 4a): Simulation of Transactions', 3, None, '___sec37'), - ('Project 4b): Recognizing the distribution', - 3, - None, - '___sec38')]} + ('Simulation of Transactions', 3, None, '___sec37')]} end of tocinfo --> @@ -173,7 +169,7 @@ MathJax.Hub.Config({

    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    May 9, 2018

    +

    May 11, 2018












    @@ -1335,7 +1331,7 @@ Change r in the program and play around to make a better fit!

    Simulating financial transcations

    -The aim of this project is to simulate financial transactions among financial agents +The aim here is to simulate financial transactions among financial agents using Monte Carlo methods. The final goal is to extract a distribution of income as function of the income \( m \). From Pareto's work (V. Pareto, 1897) it is known from empirical studies that the higher end of the distribution of money follows a distribution @@ -1406,9 +1402,9 @@ exponentially decreases with \( m' \). We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments). -

    Project 4a): Simulation of Transactions

    +

    Simulation of Transactions

    -Your task is to first set up an algorithm which simulates the above transactions with an initial +Our task is to first set up an algorithm which simulates the above transactions with an initial amount \( m_0 \). The challenge here is to figure out a Monte Carlo simulation based on the above equations. @@ -1419,12 +1415,45 @@ Your task is to first set up an algorithm which simulates the above transactions \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. You will also need to find a criterion for when the equilibrium situation has been reached. -

    Project 4b): Recognizing the distribution

    +

    -Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \) - and see if you get a straight line. - Comment the result. + +

    #!/usr/bin/env python
    +import numpy as np
    +import matplotlib.mlab as mlab
    +import matplotlib.pyplot as plt
    +import random
     
    +# initialize the rng with a seed
    +random.seed()
    +# Hard coding of input parameters
    +Agents  = 500
    +MCcounts = 1000
    +Transactions = 100000
    +startMoney = 1.0
    +Lambda = 0.0
    +FinancialAgents = startMoney*np.ones(Agents)
    +for i in range (1, MCcounts, 1):
    +    for j in range (1, Transactions, 1):
    +        agent_i = int(Agents*random.random())
    +        agent_j = int(Agents*random.random())
    +        epsilon = random.random()
    +        if agent_i != agent_j:
    +           m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
    +           FinancialAgents[agent_i] = m1
    +           FinancialAgents[agent_j] = m2
    +
    +# the histogram of the data
    +n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green')
    +
    +plt.xlabel('$x$')
    +plt.ylabel('Distribution of wealth')
    +plt.title(r'Money')
    +plt.axis([0, 10, 0, 500])
    +plt.grid(True)
    +plt.show()
    +

    We can then change our model to allow for a saving criterion, meaning that the agents save a fraction \( \lambda \) of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions. @@ -1477,7 +1506,6 @@ $$ Extract a parametrization of the above curves, see for example Patriarca and collaborators and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.

    -In the rest of this project we will follow the work of Goswami and Sen. In the studies above the agents were selected randomly, irrespective of whether we allowed for saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth \( w_m \) by assuming that there is a likelihood $$ diff --git a/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb b/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb index 4693e83e0..f4f6d4bf7 100644 --- a/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb +++ b/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb @@ -10,7 +10,7 @@ " \n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **May 9, 2018**\n", + "Date: **May 11, 2018**\n", "\n", "Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", @@ -1216,7 +1216,7 @@ "\n", "## Simulating financial transcations\n", "\n", - "The aim of this project is to simulate financial transactions among financial agents\n", + "The aim here is to simulate financial transactions among financial agents\n", "using Monte Carlo methods. The final goal is to extract a distribution of income as function\n", "of the income $m$. From Pareto's work ([V. Pareto, 1897](http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto)) it is known from empirical studies\n", "that the higher end of the distribution of money follows a distribution" @@ -1344,9 +1344,9 @@ "\n", "\n", "\n", - "### Project 4a): Simulation of Transactions\n", + "### Simulation of Transactions\n", "\n", - "Your task is to first set up an algorithm which simulates the above transactions with an initial\n", + "Our task is to first set up an algorithm which simulates the above transactions with an initial\n", " amount $m_0$.\n", " The challenge here is to figure out a Monte Carlo simulation based on the\n", " above equations.\n", @@ -1355,14 +1355,58 @@ " $w_m\\Delta m$. You will need to set up a value for the interval $\\Delta m$ (typically $0.01-0.05$).\n", " That means you need to account for the number of times you register an income in the interval\n", " $m,m+\\Delta m$. The number of times you register this income, represents the value that enters the histogram.\n", - " You will also need to find a criterion for when the equilibrium situation has been reached.\n", + " You will also need to find a criterion for when the equilibrium situation has been reached." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#!/usr/bin/env python\n", + "import numpy as np\n", + "import matplotlib.mlab as mlab\n", + "import matplotlib.pyplot as plt\n", + "import random\n", "\n", - "### Project 4b): Recognizing the distribution\n", + "# initialize the rng with a seed\n", + "random.seed()\n", + "# Hard coding of input parameters\n", + "Agents = 500\n", + "MCcounts = 1000\n", + "Transactions = 100000\n", + "startMoney = 1.0\n", + "Lambda = 0.0\n", + "FinancialAgents = startMoney*np.ones(Agents)\n", + "for i in range (1, MCcounts, 1):\n", + " for j in range (1, Transactions, 1):\n", + " agent_i = int(Agents*random.random())\n", + " agent_j = int(Agents*random.random())\n", + " epsilon = random.random()\n", + " if agent_i != agent_j:\n", + " m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])\n", + " m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])\n", + " FinancialAgents[agent_i] = m1\n", + " FinancialAgents[agent_j] = m2\n", "\n", - "Make thereafter a plot of $\\log{(w_m)}$ as function of $m$\n", - " and see if you get a straight line.\n", - " Comment the result.\n", + "# the histogram of the data\n", + "n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green')\n", "\n", + "plt.xlabel('$x$')\n", + "plt.ylabel('Distribution of wealth')\n", + "plt.title(r'Money')\n", + "plt.axis([0, 10, 0, 500])\n", + "plt.grid(True)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "We can then change our model to allow for a saving criterion, meaning that the agents save\n", " a fraction $\\lambda$ of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions.\n", "\n", @@ -1452,7 +1496,6 @@ " equilibrium distributions and compare these with the Gibbs distribution. Comment your results.\n", "Extract a parametrization of the above curves, see for example [Patriarca and collaborators](http://www.sciencedirect.com/science/article/pii/S0378437104004327) and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.\n", "\n", - "In the rest of this project we will follow the work of [Goswami and Sen](http://www.sciencedirect.com/science/article/pii/S0378437114006967). \n", "In the studies above the agents were selected randomly, irrespective of whether we allowed for\n", "saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth $w_m$ by assuming that there is a likelihood" ] diff --git a/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz b/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz index adca2182b..1324f754a 100644 Binary files a/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz and b/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz differ diff --git a/doc/pub/How2ReadData/pdf/How2ReadData-beamer-handouts2x3.pdf b/doc/pub/How2ReadData/pdf/How2ReadData-beamer-handouts2x3.pdf index 5aeeb64d6..abcaf9771 100644 Binary files a/doc/pub/How2ReadData/pdf/How2ReadData-beamer-handouts2x3.pdf and b/doc/pub/How2ReadData/pdf/How2ReadData-beamer-handouts2x3.pdf differ diff --git a/doc/pub/How2ReadData/pdf/How2ReadData-beamer.pdf b/doc/pub/How2ReadData/pdf/How2ReadData-beamer.pdf index 5a7ef295d..54486850d 100644 Binary files a/doc/pub/How2ReadData/pdf/How2ReadData-beamer.pdf and b/doc/pub/How2ReadData/pdf/How2ReadData-beamer.pdf differ diff --git a/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf b/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf index d570012ae..c44de518b 100644 Binary files a/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf and b/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf differ diff --git a/doc/src/How2ReadData/How2ReadData.do.txt b/doc/src/How2ReadData/How2ReadData.do.txt index 98a0d0a3d..67aa6fcb4 100644 --- a/doc/src/How2ReadData/How2ReadData.do.txt +++ b/doc/src/How2ReadData/How2ReadData.do.txt @@ -850,7 +850,7 @@ Change `r` in the program and play around to make a better fit! !split ===== Simulating financial transcations ===== -The aim of this project is to simulate financial transactions among financial agents +The aim here is to simulate financial transactions among financial agents using Monte Carlo methods. The final goal is to extract a distribution of income as function of the income $m$. From Pareto's work ("V.~Pareto, 1897":"http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto") it is known from empirical studies that the higher end of the distribution of money follows a distribution @@ -917,8 +917,8 @@ several runs of the above simulations, at least $10^3-10^4$ runs (experiments). -=== Project 4a): Simulation of Transactions === -Your task is to first set up an algorithm which simulates the above transactions with an initial +=== Simulation of Transactions === +Our task is to first set up an algorithm which simulates the above transactions with an initial amount $m_0$. The challenge here is to figure out a Monte Carlo simulation based on the above equations. @@ -929,10 +929,45 @@ Your task is to first set up an algorithm which simulates the above transactions $m,m+\Delta m$. The number of times you register this income, represents the value that enters the histogram. You will also need to find a criterion for when the equilibrium situation has been reached. -=== Project 4b): Recognizing the distribution === -Make thereafter a plot of $\log{(w_m)}$ as function of $m$ - and see if you get a straight line. - Comment the result. +!bc pycod +#!/usr/bin/env python +import numpy as np +import matplotlib.mlab as mlab +import matplotlib.pyplot as plt +import random + +# initialize the rng with a seed +random.seed() +# Hard coding of input parameters +Agents = 500 +MCcounts = 1000 +Transactions = 100000 +startMoney = 1.0 +Lambda = 0.0 +FinancialAgents = startMoney*np.ones(Agents) +for i in range (1, MCcounts, 1): + for j in range (1, Transactions, 1): + agent_i = int(Agents*random.random()) + agent_j = int(Agents*random.random()) + epsilon = random.random() + if agent_i != agent_j: + m1 = Lambda*FinancialAgents[agent_i] + (1-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j]) + m2 = Lambda*FinancialAgents[agent_j] + (1-Lambda)*(1-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j]) + FinancialAgents[agent_i] = m1 + FinancialAgents[agent_j] = m2 + +# the histogram of the data +n, bins, patches = plt.hist(FinancialAgents, 50, facecolor='green') + +plt.xlabel('$x$') +plt.ylabel('Distribution of wealth') +plt.title(r'Money') +plt.axis([0, 10, 0, 500]) +plt.grid(True) +plt.show() + +!ec + We can then change our model to allow for a saving criterion, meaning that the agents save a fraction $\lambda$ of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions. @@ -978,7 +1013,6 @@ We can then change our model to allow for a saving criterion, meaning that the a equilibrium distributions and compare these with the Gibbs distribution. Comment your results. Extract a parametrization of the above curves, see for example "Patriarca and collaborators":"http://www.sciencedirect.com/science/article/pii/S0378437104004327" and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results. -In the rest of this project we will follow the work of "Goswami and Sen":"http://www.sciencedirect.com/science/article/pii/S0378437114006967". In the studies above the agents were selected randomly, irrespective of whether we allowed for saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth $w_m$ by assuming that there is a likelihood !bt