markets
Estimation Methods for Markets in Equilibrium and Disequilibrium
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.9%) to scientific vocabulary
Keywords
disequilibrium
economics
finance
full-information-maximum-likelihood
market-clearing
market-models
short-side-rule
Last synced: 6 months ago
·
JSON representation
Repository
Estimation Methods for Markets in Equilibrium and Disequilibrium
Basic Info
- Host: GitHub
- Owner: pi-kappa-devel
- License: other
- Language: R
- Default Branch: master
- Homepage: https://markets.pikappa.eu/
- Size: 5.78 MB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 3
Topics
disequilibrium
economics
finance
full-information-maximum-likelihood
market-clearing
market-models
short-side-rule
Created almost 4 years ago
· Last pushed 7 months ago
Metadata Files
Readme
Changelog
License
README.Rmd
---
title: "Models For Markets in Equilibrium and Disequilibrium"
output:
html_document:
math_method: mathjax
theme: readable
highlight: breezedark
keep_md: false
self_contained: true
github_document:
math_method: webtex
md_document:
variant: gfm+tex_math_dollars
bibliography: bibliography.bib
---
```{r maybe-logo, echo=FALSE, results='asis'}
if (knitr::opts_knit$get("rmarkdown.pandoc.to") != "gfm+tex_math_dollars-yaml_metadata_block") {
cat('
')
}
```




The *markets* package provides tools to estimate and analyze an equilibrium and four disequilibrium models. The equilibrium model can be estimated with either two-stage least squares or with full information maximum likelihood. The two methods are asymptotically equivalent. The disequilibrium models are estimated using full information maximum likelihood. The likelihoods can be estimated both with independent and correlated demand and supply shocks. The optimization of the likelihoods can be performed either using analytic expressions or numerical approximations of their gradients. A detailed overview of the package's functionality, usage examples, and design traits is given in @karapanagiotis2024.
# A quick model tour
The five models of the package are described by systems of simultaneous equations, with the equilibrium system being the only linear one, while the disequilibrium systems being non-linear. All models specify the demand and the supply side of the market by a linear (in parameters) equation. The remaining equations of each model, if any, further specify the market structure.
## The equilibrium model
The equilibrium model adds the market-clearing condition to the demand and supply equations of the system. For the system to be identifiable, at least one variable on the demand side must not be present on the supply side and vice versa. This model assumes that the market observations always represent equilibrium points in which the demanded and supplied quantities are equal. The model can be estimated using two-stage least squares [@theil1953] or full information maximum likelihood [@karapanagiotis2020invisible]. Asymptotically, these methods are equivalent [@balestra1987].
$$
\left.
\begin{aligned}
D_{n t} &= X_{d, n t}'\beta_{d} + P_{n t}\alpha_{d} + u_{d, n t} \\
S_{n t} &= X_{s, n t}'\beta_{s} + P_{n t}\alpha_{s} + u_{s, n t} \\
Q_{n t} &= D_{n t} = S_{n t}
\end{aligned}
\right. \qquad\text{(EM)}
$$
## The basic disequilibrium model
The basic model is the simplest disequilibrium model of the package as it basically imposes no assumption on the market structure regarding price movements [@fair1972; @maddala1974]. In contrast with the equilibrium model, the market-clearing condition is replaced by the short-side rule, which stipulates that the minimum between the demanded and supplied quantities is observed. The econometrician does not need to specify whether an observation belongs to the demand or the supply side since the estimation of the model will allocate the observations on the demand or supply side so that the likelihood is maximized.
$$
\left.
\begin{aligned}
D_{n t} &= X_{d, n t}'\beta_{d} + u_{d, n t} \\
S_{n t} &= X_{s, n t}'\beta_{s} + u_{s, n t} \\
Q_{n t} &= \min\{D_{n t},S_{n t}\}
\end{aligned}
\right. \qquad\text{(BM)}
$$
## The directional disequilibrium model
The directional model attaches an additional equation to the system of the basic model. The added equation is a sample separation condition based on the direction of the price movements [@fair1972; @maddala1974]. When prices increase at a given date, an observation is assumed to belong on the supply side. When prices fall, an observation is assumed to belong on the demand side. In short, this condition separates the sample before the estimation and uses this separation as additional information in the estimation procedure. Although, when appropriate, more information improves estimations, it also, when inaccurate, intensifies misspecification problems. Therefore, the additional structure of the directional model does not guarantee better estimates in comparison with the basic model.
$$
\left.
\begin{aligned}
D_{n t} &= X_{d, n t}'\beta_{d} + u_{d, n t} \\
S_{n t} &= X_{s, n t}'\beta_{s} + u_{s, n t} \\
Q_{n t} &= \min\{D_{n t},S_{n t}\} \\
\Delta P_{n t} &\ge 0 \implies D_{n t} \ge S_{n t}
\end{aligned}
\right. \qquad\text{(DM)}
$$
## A disequilibrium model with deterministic price dynamics
The separation rule of the directional model classifies observations on the demand- or supply-side based in a binary fashion, which is not always flexible, as observations that correspond to large shortages/surpluses are treated the same as observations that correspond to small shortages/ surpluses. The deterministic adjustment model of the package replaces this binary separation rule with a quantitative one [@fair1972; @maddala1974]. The magnitude of the price movements is analogous to the magnitude of deviations from the market-clearing condition. This model offers a flexible estimation alternative, with one extra degree of freedom in the estimation of price dynamics, that accounts for market forces that are in alignment with standard economic reasoning. By letting $\gamma$ approach zero, the equilibrium model can be obtained as a limiting case of this model.
$$
\left.
\begin{aligned}
D_{n t} &= X_{d, n t}'\beta_{d} + P_{n t}\alpha_{d} + u_{d, n t} \\
S_{n t} &= X_{s, n t}'\beta_{s} + P_{n t}\alpha_{s} + u_{s, n t} \\
Q_{n t} &= \min\{D_{n t},S_{n t}\} \\
\Delta P_{n t} &= \frac{1}{\gamma} \left( D_{n t} - S_{n t} \right)
\end{aligned}
\right. \qquad\text{(DA)}
$$
## A disequilibrium model with stochastic price dynamics
The last model of the package extends the price dynamics of the deterministic adjustment model by adding additional explanatory variables and a stochastic term. The latter term, in particular, makes the price adjustment mechanism stochastic and, deviating from the structural assumptions of models $(DA)$ and $(DM)$, abstains from imposing any separation assumption on the sample [@maddala1974; @quandt1978estimating]. The estimation of this model offers the highest degree of freedom, accompanied, however, by a significant increase in estimation complexity, which can hinder the stability of the procedure and the numerical accuracy of the outcomes.
$$
\left.
\begin{aligned}
D_{n t} &= X_{d, n t}'\beta_{d} + P_{n t}\alpha_{d} + u_{d, n t} \\
S_{n t} &= X_{s, n t}'\beta_{s} + P_{n t}\alpha_{s} + u_{s, n t} \\
Q_{n t} &= \min\{D_{n t},S_{n t}\} \\
\Delta P_{n t} &= \frac{1}{\gamma} \left( D_{n t} - S_{n t} \right) + X_{p, n t}'\beta_{p} + u_{p, n t}
\end{aligned}
\right. \qquad\text{(SA)}
$$
# Installation and documentation
The released version of [*markets*](https://CRAN.R-project.org/package=markets) can be installed from [CRAN](https://CRAN.R-project.org) with:
```r
install.packages("markets")
```
The source code of the in-development version can be downloaded from [GitHub](https://github.com/pi-kappa-devel/markets).
After installing it, there is a basic-usage example installed with it. To see it type the command
```r
vignette('basic_usage')
```
Online documentation is available for both the [released](https://www.markets.pikappa.eu) and [in-development](https://www.markets.pikappa.eu/dev/) versions of the package. The documentation files can also be accessed in `R` by typing
```r
?? markets
```
An older version of the package (see [diseq](https://CRAN.R-project.org/package=diseq)) was presented in the session Trends, Markets, Models of the [useR!2021](https://user2021.r-project.org/) conference. However, the presented user interface is deprecated and it is recommended to follow [@karapanagiotis2024] for the latest interface. The recording of the session can be found in the video that follows. The presentation slides of the talk are also available [here](https://talks.pikappa.eu/useR!2021/).
```{r maybe-iframe, echo=FALSE, results='asis'}
if (knitr::opts_knit$get("rmarkdown.pandoc.to") == "gfm-yaml_metadata_block") {
cat('
')
} else {
cat('')
}
```
# A practical example
This is a basic example that illustrates how a model of the package can be estimated. The package is loaded in the standard way.
```{r loading}
library(markets)
```
The example uses simulated data. The *markets* package offers a function to simulate data from data-generating processes that correspond to the models that the package provides.
```{r simulation}
model_tbl <- simulate_data(
"diseq_basic", 10000, 5,
-1.9, 36.9, c(2.1, -0.7), c(3.5, 6.25),
2.8, 34.2, c(0.65), c(1.15, 4.2),
NA, NA, c(NA),
seed = 42
)
```
Models are initialized by a constructor. In this example, a basic disequilibrium model is estimated. There are also other models available (see [Design and functionality]). The constructor sets the model's parameters and performs the necessary initialization processes. The following variables specify this example's parameterization.
* The models can be estimated both with panel and time series data. The constructor expects both a subject and a time identifier in order to perform the necessary initialization operations (these are respectively given by `id` and `date` in the simulated data of this example). The observation identification of the data is automatically generated by composing the subject and time identifiers. The resulting composite key is the combination of columns that uniquely identify a record of the dataset.
* The observable traded quantity variable (given by `Q` in this example's simulated data). The demanded and supplied quantities are not observable, and they are identified either based on the market clearing condition or the short-side rule.
* The price variable, which is named after `P` in the simulated data.
* The right-hand side specifications of the demand and supply equations. The expressions are specified similarly to the expressions of formulas of linear models. Indicator variables and interactions are created automatically by the constructor.
* The verbosity level controls the level of messaging. The object displays
* error: always,
* warning: ≥ 1,
* info: ≥ 2,
* verbose: ≥ 3 and
* debug: ≥ 4.
```{r model.parameters.verbose}
verbose <- 0
```
* Should the model estimation allow for correlated demand and supply shocks?
```{r model.parameters.correlated_shocks}
correlated_shocks <- TRUE
```
The model is estimated with default options by a simple call. See the documentation of `estimate` for more details and options.
```{r model.estimate}
fit <- diseq_basic(
Q | P | id | date ~ P + Xd1 + Xd2 + X1 + X2 | P + Xs1 + X1 + X2,
model_tbl, correlated_shocks = correlated_shocks, verbose = verbose
)
```
The results can be inspected in the usual fashion via `summary`.
```{r model.summary}
summary(fit)
```
# Design and functionality
The equilibrium model can be estimated either using two-stage least squares or full information maximum likelihood. The two methods are asymptotically equivalent. The class for which both of these estimation methods are implemented is
* `equilibrium_model`.
In total, there are four disequilibrium models, which are all estimated using full information maximum likelihood. By default, the estimations use analytically calculated gradient expressions, but the user can override this behavior. The classes that implement the four disequilibrium models are
* `diseq_basic`,
* `diseq_directional`,
* `diseq_deterministic_adjustment`, and
* `diseq_stochastic_adjustment`.
The package organizes these classes in a simple object-oriented hierarchy.
Concerning post-estimation analysis, the package offers functionality to calculate
* shortage probabilities,
* marginal effects on shortage probabilities,
* point estimates of normalized shortages,
* point estimates of relative shortages,
* aggregate demand and supply,
* post-estimation classification of observations in demand and supply,
* heteroscedasticity-adjusted (Huber-White) standard errors, and
* clustered standard errors.
# Alternative packages
The estimation of the basic model is also supported by the package [_Disequilibrium_](https://CRAN.R-project.org/package=Disequilibrium). By default, the _Disequilibrium_ package numerically approximates the gradient when optimizing the likelihood. In contrast, _markets_ uses analytically calculated expressions for the likelihood, which can reduce the duration of estimating the model. In addition, it allows the user to override this behavior and use the numerically approximated gradient. There is no alternative package that supports the out-of-the-box estimation of the other three disequilibrium models of _markets_.
# Planned extensions
The package is planned to be expanded in the following ways:
1. The package should become more inclusive by adding additional market models.
2. Single-command functionality for the market-clearing tests (e.g. [@karapanagiotis2020invisible; @hwang1980; @quandt1978tests]) should be included in the package.
3. Alternative estimation methods (e.g. [@zilinskas2006; @quandt1978estimating]) could also be implemented.
# Contributors
[Pantelis Karapanagiotis](https://www.pikappa.eu)
Feel free to join, share, contribute, and distribute.
# License
The code is distributed under the MIT License.
# References
Owner
- Name: Pantelis Karapanagiotis
- Login: pi-kappa-devel
- Kind: user
- Location: Frankfurt am Main
- Company: EBS University Wiesbaden
- Website: https://pikappa.eu/
- Twitter: pi_kappa_
- Repositories: 3
- Profile: https://github.com/pi-kappa-devel
GitHub Events
Total
- Push event: 4
Last Year
- Push event: 4
Committers
Last synced: about 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Pantelis Karapanagiotis | p****l@g****m | 153 |
| Pantelis Karapanagiotis | 2****l | 95 |
| Pantelis Karapanagiotis | n****k@T****l | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 243 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 9
- Total maintainers: 1
cran.r-project.org: markets
Estimation Methods for Markets in Equilibrium and Disequilibrium
- Homepage: https://github.com/pi-kappa-devel/markets/
- Documentation: http://cran.r-project.org/web/packages/markets/markets.pdf
- License: MIT + file LICENSE
-
Latest release: 1.1.6
published 6 months ago
Rankings
Forks count: 28.8%
Dependent packages count: 29.8%
Stargazers count: 31.7%
Dependent repos count: 35.5%
Average: 36.8%
Downloads: 58.4%
Maintainers (1)
Last synced:
6 months ago
Dependencies
.github/workflows/check-standard.yaml
actions
- actions/checkout v3 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml
actions
- SamKirkland/FTP-Deploy-Action 4.3.3 composite
- actions/checkout v3 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml
actions
- actions/checkout v3 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION
cran
- R >= 4.1.0 depends
- Formula * imports
- MASS >= 7.3 imports
- Rcpp * imports
- RcppGSL * imports
- RcppParallel * imports
- dplyr >= 0.7.6 imports
- methods * imports
- rlang >= 0.2.1 imports
- stats * imports
- ggplot2 >= 3.0.0 suggests
- knitr >= 1.20 suggests
- numDeriv >= 2016.8.1.1 suggests
- rmarkdown >= 1.10 suggests
- testthat >= 2.0.0 suggests
.github/workflows/rhub.yaml
actions
- r-hub/actions/checkout v1 composite
- r-hub/actions/platform-info v1 composite
- r-hub/actions/run-check v1 composite
- r-hub/actions/setup v1 composite
- r-hub/actions/setup-deps v1 composite
- r-hub/actions/setup-r v1 composite