Minor update
This commit is contained in:
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -181,8 +177,7 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;"><b>Parameter estimation</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;"><b>A program relevant for the biological problem</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;"><b>Simulating financial transcations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;"> Project 4a): Simulation of Transactions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec38" style="font-size: 80%;"> Project 4b): Recognizing the distribution</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;"> Simulation of Transactions</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -216,7 +211,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>May 9, 2018</h4></center> <!-- date -->
|
||||
<center><h4>May 11, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- potential-jumbotron-button -->
|
||||
@@ -1412,7 +1407,7 @@ Change <code>r</code> in the program and play around to make a better fit!
|
||||
<h2 id="___sec36" class="anchor">Simulating financial transcations </h2>
|
||||
|
||||
<p>
|
||||
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 (<a href="http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto" target="_self">V. Pareto, 1897</a>) 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).
|
||||
|
||||
<h3 id="___sec37" class="anchor">Project 4a): Simulation of Transactions </h3>
|
||||
<h3 id="___sec37" class="anchor">Simulation of Transactions </h3>
|
||||
|
||||
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.
|
||||
|
||||
<h3 id="___sec38" class="anchor">Project 4b): Recognizing the distribution </h3>
|
||||
<p>
|
||||
|
||||
Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \)
|
||||
and see if you get a straight line.
|
||||
Comment the result.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">#!/usr/bin/env python</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.mlab</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mlab</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">random</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># initialize the rng with a seed</span>
|
||||
random<span style="color: #666666">.</span>seed()
|
||||
<span style="color: #408080; font-style: italic"># Hard coding of input parameters</span>
|
||||
Agents <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
MCcounts <span style="color: #666666">=</span> <span style="color: #666666">1000</span>
|
||||
Transactions <span style="color: #666666">=</span> <span style="color: #666666">100000</span>
|
||||
startMoney <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
Lambda <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
FinancialAgents <span style="color: #666666">=</span> startMoney<span style="color: #666666">*</span>np<span style="color: #666666">.</span>ones(Agents)
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, MCcounts, <span style="color: #666666">1</span>):
|
||||
<span style="color: #008000; font-weight: bold">for</span> j <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, Transactions, <span style="color: #666666">1</span>):
|
||||
agent_i <span style="color: #666666">=</span> <span style="color: #008000">int</span>(Agents<span style="color: #666666">*</span>random<span style="color: #666666">.</span>random())
|
||||
agent_j <span style="color: #666666">=</span> <span style="color: #008000">int</span>(Agents<span style="color: #666666">*</span>random<span style="color: #666666">.</span>random())
|
||||
epsilon <span style="color: #666666">=</span> random<span style="color: #666666">.</span>random()
|
||||
<span style="color: #008000; font-weight: bold">if</span> agent_i <span style="color: #666666">!=</span> agent_j:
|
||||
m1 <span style="color: #666666">=</span> Lambda<span style="color: #666666">*</span>FinancialAgents[agent_i] <span style="color: #666666">+</span> (<span style="color: #666666">1-</span>Lambda)<span style="color: #666666">*</span>epsilon<span style="color: #666666">*</span>(FinancialAgents[agent_i] <span style="color: #666666">+</span> FinancialAgents[agent_j])
|
||||
m2 <span style="color: #666666">=</span> Lambda<span style="color: #666666">*</span>FinancialAgents[agent_j] <span style="color: #666666">+</span> (<span style="color: #666666">1-</span>Lambda)<span style="color: #666666">*</span>(<span style="color: #666666">1-</span>epsilon)<span style="color: #666666">*</span>(FinancialAgents[agent_i] <span style="color: #666666">+</span> FinancialAgents[agent_j])
|
||||
FinancialAgents[agent_i] <span style="color: #666666">=</span> m1
|
||||
FinancialAgents[agent_j] <span style="color: #666666">=</span> m2
|
||||
|
||||
<span style="color: #408080; font-style: italic"># the histogram of the data</span>
|
||||
n, bins, patches <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>hist(FinancialAgents, <span style="color: #666666">50</span>, facecolor<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'Distribution of wealth'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Money'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">10</span>, <span style="color: #666666">0</span>, <span style="color: #666666">500</span>])
|
||||
plt<span style="color: #666666">.</span>grid(<span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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 <a href="http://www.sciencedirect.com/science/article/pii/S0378437104004327" target="_self">Patriarca and collaborators</a> and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.
|
||||
|
||||
<p>
|
||||
In the rest of this project we will follow the work of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_self">Goswami and Sen</a>.
|
||||
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
|
||||
$$
|
||||
|
||||
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>May 9, 2018</h4></center> <!-- date -->
|
||||
<center><h4>May 11, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -1310,7 +1310,7 @@ Change <code>r</code> in the program and play around to make a better fit!
|
||||
<h2 id="___sec36">Simulating financial transcations </h2>
|
||||
|
||||
<p>
|
||||
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 (<a href="http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto" target="_blank">V. Pareto, 1897</a>) 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).
|
||||
|
||||
<h3 id="___sec37">Project 4a): Simulation of Transactions </h3>
|
||||
<h3 id="___sec37">Simulation of Transactions </h3>
|
||||
|
||||
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.
|
||||
|
||||
<h3 id="___sec38">Project 4b): Recognizing the distribution </h3>
|
||||
<p>
|
||||
|
||||
Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \)
|
||||
and see if you get a straight line.
|
||||
Comment the result.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22">#!/usr/bin/env python</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.mlab</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mlab</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">random</span>
|
||||
|
||||
<span style="color: #228B22"># initialize the rng with a seed</span>
|
||||
random.seed()
|
||||
<span style="color: #228B22"># Hard coding of input parameters</span>
|
||||
Agents = <span style="color: #B452CD">500</span>
|
||||
MCcounts = <span style="color: #B452CD">1000</span>
|
||||
Transactions = <span style="color: #B452CD">100000</span>
|
||||
startMoney = <span style="color: #B452CD">1.0</span>
|
||||
Lambda = <span style="color: #B452CD">0.0</span>
|
||||
FinancialAgents = startMoney*np.ones(Agents)
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, MCcounts, <span style="color: #B452CD">1</span>):
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> j <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, Transactions, <span style="color: #B452CD">1</span>):
|
||||
agent_i = <span style="color: #658b00">int</span>(Agents*random.random())
|
||||
agent_j = <span style="color: #658b00">int</span>(Agents*random.random())
|
||||
epsilon = random.random()
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> agent_i != agent_j:
|
||||
m1 = Lambda*FinancialAgents[agent_i] + (<span style="color: #B452CD">1</span>-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
|
||||
m2 = Lambda*FinancialAgents[agent_j] + (<span style="color: #B452CD">1</span>-Lambda)*(<span style="color: #B452CD">1</span>-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
|
||||
FinancialAgents[agent_i] = m1
|
||||
FinancialAgents[agent_j] = m2
|
||||
|
||||
<span style="color: #228B22"># the histogram of the data</span>
|
||||
n, bins, patches = plt.hist(FinancialAgents, <span style="color: #B452CD">50</span>, facecolor=<span style="color: #CD5555">'green'</span>)
|
||||
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'Distribution of wealth'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Money'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>, <span style="color: #B452CD">10</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">500</span>])
|
||||
plt.grid(<span style="color: #658b00">True</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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 <a href="http://www.sciencedirect.com/science/article/pii/S0378437104004327" target="_blank">Patriarca and collaborators</a> and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.
|
||||
|
||||
<p>
|
||||
In the rest of this project we will follow the work of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
|
||||
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
|
||||
<p> <br>
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -168,7 +164,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>May 9, 2018</h4></center> <!-- date -->
|
||||
<center><h4>May 11, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -1330,7 +1326,7 @@ Change <code>r</code> in the program and play around to make a better fit!
|
||||
<h2 id="___sec36">Simulating financial transcations </h2>
|
||||
|
||||
<p>
|
||||
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 (<a href="http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto" target="_blank">V. Pareto, 1897</a>) 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).
|
||||
|
||||
<h3 id="___sec37">Project 4a): Simulation of Transactions </h3>
|
||||
<h3 id="___sec37">Simulation of Transactions </h3>
|
||||
|
||||
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.
|
||||
|
||||
<h3 id="___sec38">Project 4b): Recognizing the distribution </h3>
|
||||
<p>
|
||||
|
||||
Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \)
|
||||
and see if you get a straight line.
|
||||
Comment the result.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22">#!/usr/bin/env python</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.mlab</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mlab</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">random</span>
|
||||
|
||||
<span style="color: #228B22"># initialize the rng with a seed</span>
|
||||
random.seed()
|
||||
<span style="color: #228B22"># Hard coding of input parameters</span>
|
||||
Agents = <span style="color: #B452CD">500</span>
|
||||
MCcounts = <span style="color: #B452CD">1000</span>
|
||||
Transactions = <span style="color: #B452CD">100000</span>
|
||||
startMoney = <span style="color: #B452CD">1.0</span>
|
||||
Lambda = <span style="color: #B452CD">0.0</span>
|
||||
FinancialAgents = startMoney*np.ones(Agents)
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, MCcounts, <span style="color: #B452CD">1</span>):
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> j <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, Transactions, <span style="color: #B452CD">1</span>):
|
||||
agent_i = <span style="color: #658b00">int</span>(Agents*random.random())
|
||||
agent_j = <span style="color: #658b00">int</span>(Agents*random.random())
|
||||
epsilon = random.random()
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> agent_i != agent_j:
|
||||
m1 = Lambda*FinancialAgents[agent_i] + (<span style="color: #B452CD">1</span>-Lambda)*epsilon*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
|
||||
m2 = Lambda*FinancialAgents[agent_j] + (<span style="color: #B452CD">1</span>-Lambda)*(<span style="color: #B452CD">1</span>-epsilon)*(FinancialAgents[agent_i] + FinancialAgents[agent_j])
|
||||
FinancialAgents[agent_i] = m1
|
||||
FinancialAgents[agent_j] = m2
|
||||
|
||||
<span style="color: #228B22"># the histogram of the data</span>
|
||||
n, bins, patches = plt.hist(FinancialAgents, <span style="color: #B452CD">50</span>, facecolor=<span style="color: #CD5555">'green'</span>)
|
||||
|
||||
plt.xlabel(<span style="color: #CD5555">'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">'Distribution of wealth'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Money'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>, <span style="color: #B452CD">10</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">500</span>])
|
||||
plt.grid(<span style="color: #658b00">True</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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 <a href="http://www.sciencedirect.com/science/article/pii/S0378437104004327" target="_blank">Patriarca and collaborators</a> and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.
|
||||
|
||||
<p>
|
||||
In the rest of this project we will follow the work of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
|
||||
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
|
||||
$$
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -173,7 +169,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>May 9, 2018</h4></center> <!-- date -->
|
||||
<center><h4>May 11, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -1335,7 +1331,7 @@ Change <code>r</code> in the program and play around to make a better fit!
|
||||
<h2 id="___sec36">Simulating financial transcations </h2>
|
||||
|
||||
<p>
|
||||
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 (<a href="http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto" target="_blank">V. Pareto, 1897</a>) 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).
|
||||
|
||||
<h3 id="___sec37">Project 4a): Simulation of Transactions </h3>
|
||||
<h3 id="___sec37">Simulation of Transactions </h3>
|
||||
|
||||
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.
|
||||
|
||||
<h3 id="___sec38">Project 4b): Recognizing the distribution </h3>
|
||||
<p>
|
||||
|
||||
Make thereafter a plot of \( \log{(w_m)} \) as function of \( m \)
|
||||
and see if you get a straight line.
|
||||
Comment the result.
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">#!/usr/bin/env python</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.mlab</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mlab</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">random</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># initialize the rng with a seed</span>
|
||||
random<span style="color: #666666">.</span>seed()
|
||||
<span style="color: #408080; font-style: italic"># Hard coding of input parameters</span>
|
||||
Agents <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
MCcounts <span style="color: #666666">=</span> <span style="color: #666666">1000</span>
|
||||
Transactions <span style="color: #666666">=</span> <span style="color: #666666">100000</span>
|
||||
startMoney <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
Lambda <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
FinancialAgents <span style="color: #666666">=</span> startMoney<span style="color: #666666">*</span>np<span style="color: #666666">.</span>ones(Agents)
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, MCcounts, <span style="color: #666666">1</span>):
|
||||
<span style="color: #008000; font-weight: bold">for</span> j <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, Transactions, <span style="color: #666666">1</span>):
|
||||
agent_i <span style="color: #666666">=</span> <span style="color: #008000">int</span>(Agents<span style="color: #666666">*</span>random<span style="color: #666666">.</span>random())
|
||||
agent_j <span style="color: #666666">=</span> <span style="color: #008000">int</span>(Agents<span style="color: #666666">*</span>random<span style="color: #666666">.</span>random())
|
||||
epsilon <span style="color: #666666">=</span> random<span style="color: #666666">.</span>random()
|
||||
<span style="color: #008000; font-weight: bold">if</span> agent_i <span style="color: #666666">!=</span> agent_j:
|
||||
m1 <span style="color: #666666">=</span> Lambda<span style="color: #666666">*</span>FinancialAgents[agent_i] <span style="color: #666666">+</span> (<span style="color: #666666">1-</span>Lambda)<span style="color: #666666">*</span>epsilon<span style="color: #666666">*</span>(FinancialAgents[agent_i] <span style="color: #666666">+</span> FinancialAgents[agent_j])
|
||||
m2 <span style="color: #666666">=</span> Lambda<span style="color: #666666">*</span>FinancialAgents[agent_j] <span style="color: #666666">+</span> (<span style="color: #666666">1-</span>Lambda)<span style="color: #666666">*</span>(<span style="color: #666666">1-</span>epsilon)<span style="color: #666666">*</span>(FinancialAgents[agent_i] <span style="color: #666666">+</span> FinancialAgents[agent_j])
|
||||
FinancialAgents[agent_i] <span style="color: #666666">=</span> m1
|
||||
FinancialAgents[agent_j] <span style="color: #666666">=</span> m2
|
||||
|
||||
<span style="color: #408080; font-style: italic"># the histogram of the data</span>
|
||||
n, bins, patches <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>hist(FinancialAgents, <span style="color: #666666">50</span>, facecolor<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'Distribution of wealth'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Money'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>, <span style="color: #666666">10</span>, <span style="color: #666666">0</span>, <span style="color: #666666">500</span>])
|
||||
plt<span style="color: #666666">.</span>grid(<span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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 <a href="http://www.sciencedirect.com/science/article/pii/S0378437104004327" target="_blank">Patriarca and collaborators</a> and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.
|
||||
|
||||
<p>
|
||||
In the rest of this project we will follow the work of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
|
||||
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
|
||||
$$
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \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"
|
||||
]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user