YAFiMM - Yet Another Financial Market Model
Table of Contents
Getting Started
This package contains programs providing a simulation framework for the analysis of a financial market model. For the description of the model, see the References below. Five dinstinct programs are provided:
deterministic
- it computes the deterministic market dynamics obtained under the hypothesis of identical agents;
stochastic
- it provides the stochastic version of the previous system with the addition of random noise;
aggregate
- is for the market (aggregate) dynamics obtained with "nosy" perturbed agents with short selling allowed;
yafimm
- a complete agent-based simulation of a market, with prices fixed via different trading protocols and considering heterogeneous agents with budget constraints;
match
- test the implementation of the batch auction.
YAFiMM configuration file
The program yfimm
reads the description of the market and the
agents from a configuration file. The name of this file can be
provided at the command line with the option -F
. If no file name
is provided, yafimm reads the market and agents description from
the standard input.
The structure of the configuration file is a sequence of lines. Each line constitutes a record whose field are separated by blank (spaces or tabs) characters. Each record describe one "building block" of the model: the general properties of the market or the characteristic of a group of agents. The generic structure of a line can be represented as
typeofrecord first_arg second_arg ...
The first field of a line specifies the type of record and can assume the following values
- market
- the line describe a market
- trendfollower
- the line describe a group of "trend following" agents
- fundamental
- the line describe a group of "fundamental" agents
- sophfund
- the line describe a group of sophisticated "fundamental" agents
- noise
- the line describe a group of "noise trading" agents
(Only the first three characters are relevant to identify the type of a record). Line beginning with a "#" are considered comments and are skipped.
If the record describes a group of agents, the second field has a special meaning: it is the number of agents belonging to this group. The rest of the line is formed by couples of the form key=value. The possible values for the key depend on the type of record and are listed below, together with their default value and constraints
record type | key | (default) explanation |
---|---|---|
market | type | (0) 0 walrasian auction 1 batch auction 2 order book |
.. | d | (.01) dividend (d>0) |
.. | r | (.01) riskless return (r>0) |
.. | A | (1) total amount of risky shares (A>0) |
.. | initnoise | (.01) initial level of noise on forecasted returns |
.. | initnumber | (100) number of time steps in market initialization |
trendfollower | beta | (1.) risk aversion (beta>0) |
or | lamba | (.99) EWMA parameter (0<lambda<=1) |
noise trader | eta | (0.0) market orders propensity (0<=eta<=1) |
.. | Dy | (0.0) personal shock of forecasted return (0<=Dy<=1) |
.. | horizon | (1) horizon of trading position (integer>0) |
.. | shortA | (0) switch on (0) or off (1) the budget constraint of A |
.. | shortB | (0) switch on (0) or off (1) the budget constraint of B |
fundamental | beta | (1.) risk aversion (beta>0) |
or | lambda | (.99) EWMA parameter (0<lambda<=1) |
soph. fund. | eta | (0.0) market orders propensity (0<=eta<=1) |
.. | theta | (1.0) market efficiency estimation (0<=theta<=1) |
.. | Dy | (0.0) personal shock of forecasted return (0<=Dy<=1) |
.. | horizon | (1) horizon of trading position (integer>0) |
.. | shortA | (0) switch on (0) or off (1) the budget constraint on A |
.. | shortB | (0) switch on (0) or off (1) the budget constraint on B |
The value can be substituted by a comma separated couple
minvalue,maxvalue. In this case each agent of the group will be
assigned a random value drawn from an uniform distribution with
support (minvalue,maxvalue]. Notice that shortA=1
implies
shortB=1
.
Configuration File Example
This is the situation: the market is a batch auction; the riskless return is $.001$ and the dividends per share paid at each market round are $.001$. On the market there are \(100\) agents acting as trend followers. They use an EWMA rule with parameter $.97$ for future return forecasting and their risk aversion is randomly chosen between \(100\) and \(200\). During the trading, they send market orders (instead of limit order) to the auctioneer \(50\%\) of the times. Operating on the market there are also \(50\) fundamentalists, whose forecasting rule for return supposes a "market efficiency" of $.5$ and an EWMA coefficient of $.94$. Their risk aversion is equal to 10. Moreover, they receive random shocks, uniformly distributed in \([-2\%,2\%]\), to their future price prediction and they always partecipate the market via limit orders. Both types of agents are initialized with forecasts extracted from a random distribution of mean zero and variance \(0.01\). Fundamentalists can attain short position in bond (i.e. they can borrow money).
This situation described above is represented with the following lines
market type=1 d=.001 r=.001 noise=.01 trend 100 lambda=0.97 beta=100,200 eta=.5 fund 50 theta=.5 lambda=0.94 beta=10 Dy=.02 shortB=1
Try the three .ini files provided with the package as an example.
Installation
Download the latest source code from the cafed repository. On Linux the installation is simple. Uncompress the package
tar xvsf yafimm-version.tar.gz
move to the directory::
cd yafimm-version
configure, compile and install the package using
./configure make make install
By default, the executable files are placed in /usr/local/bin
. If
you prefer different location then use the configure
option
--prefix
. See the file INSTALL
for more information.
Required libraries
yafimm
is written in C++. It requires the GNU Scientific Library,
which should be available through the package management software
of any Linux distribution. Remember to install the development
version of the libraries before trying to compile yafimm
.
Technical information for advanced users (regular users can skip it): The standard packages assume the use of the CBLAS interface provided by the GSL library itself. If you want to use a different library, you should intall via the source code (tar.gz file) and change the LOADLIBES parameter in Makefile to reflect your preferences.
How to obtain help
Look at the short help provided by the programs
yafimm -h deterministic -h aggregate -h
There is a still-work-in-progress manual in the directory doc. Most importantly, read the papers listed in the References below, where the model and its features are (hopefully) clearly explained.
References
M. Anufriev and G. Bottazzi Asset Pricing with Heterogeneous Investment Horizons, Studies in Nonlinear Dynamics & Econometrics, Volume 16, Issue 4, October 2012. DOI
G.Bottazzi, G.Dosi and I.Rebesco Institutional Architectures and Behavioral Ecologies in the Dynamics of Financial Markets Journal of Mathematical Economics, vol. 41, pp. 197-228, 2005
G.Bottazzi A Simple Micro-Model of Market Dynamics, Lecture Notes in Economics and Mathematical Systems, Volume 531, pp. 213-228, Springer-Verlag, Berlin, 2004 DOI
Package files list
README this file deterministic.c src of deterministic aggregate.c src of aggregate match.c src of match Order[.h,.cpp] class Order BookOrder[.h,.cpp] class BookOrder Market[.h,.cpp] class Market Walrasian[.h,.cpp] definition of Walrasian auction protocol Batch[.h,.cpp] definition of Batch auction protocol Book[.h,.cpp] definition of Order Book protocol Agent[.h,.cpp] class Agent TrendFollower[.h,.cpp] class TrendFollower Fundamentalist[.h,.cpp] class Fundamentalist SophFundamentalist[.h,.cpp] class SophFundamentalist NoiseTrader[.h,.cpp] class NoiseTrader Parser[.h,.cpp] initialization file parser Yafimm[.h,.cpp] the main program fixed.ini example initialization file for yafimm aperiodic.ini example initialization file for yafimm test.ini example initialization file for yafimm Makefile COPYING Gnu public Licence AUTHORS list of authors yafimm.css docutils stylesheet