Title: | Quickly Build and Manipulate Financial Networks |
---|---|
Description: | Providing classes, methods, and functions to deal with financial networks. Users can easily store information about both physical and legal persons by using pre-made classes that are studied for integration with scraping packages such as 'rvest' and 'RSelenium'. Moreover, the package assists in creating various types of financial networks depending on the type of relation between its units depending on the relation under scrutiny (ownership, board interlocks, etc.), the desired tie type (valued or binary), and renders them in the most common formats (adjacency matrix, incidence matrix, edge list, 'igraph', 'network'). There are also ad-hoc functions for the Fiedler value, global network efficiency, and cascade-failure analysis. |
Authors: | Fabio Ashtar Telarico [aut, cre] |
Maintainer: | Fabio Ashtar Telarico <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.2 |
Built: | 2024-10-31 18:20:43 UTC |
Source: | https://github.com/fatelarico/finnet |
firm
object(s)Generic function to coerce other other classes into the S4 class firm
representing a firm (legal person)
as.firm(x, ...)
as.firm(x, ...)
x |
The object to coerce |
... |
Arguments passed to class-specific methods |
An object of class firm
or a (usually named) list of them, depending on the available method for the object being coerced.
Telarico, Fabio Ashtar
financial_matrix
object into a list of firm
objects'as.firm' method for an object of class financial_matrix
## S4 method for signature 'financial_matrix' as.firm(x, ...)
## S4 method for signature 'financial_matrix' as.firm(x, ...)
x |
The |
... |
Optional arguments |
A (usually named) list of firm
objects the length of which equals the number of rows and columns of the provided financial_matrix
Telarico, Fabio Ashtar
Based in part on the earlier work of Katz (1953) and Hubbell (1965), Bonacich (1972a, 1972b) argued that a point's centrality in a network should depend on three criteria: (1) the number of links to other points; (2) the intensity of the links; and (3) the centrality of those with whom one is linked. This centrality has been applied to board interlocks for the first time by Mizruchi and Bunting (1981).
bonacich(FF, exo = 1, alpha = NULL, tol = 1e-07)
bonacich(FF, exo = 1, alpha = NULL, tol = 1e-07)
FF |
An object of class |
exo |
A value for the exogenous parameter of the Bonacich centrality. Defaults to |
alpha |
A value for the alpha parameter of the Bonacich centrality. Defaults to a function of the matrix's largest eigenvalue. |
tol |
A value for the tolerance of the Bonacich centrality. Defaults to |
A scalar vector with the Bonacich centrality of each firm.
Telarico, Fabio Ashtar
Katz, Leo. 1953. “A new status index derived from sociometric analysis.” Psychometrika 18: 39-43 doi:10.1007/BF02289026.
Bonacich, Phillip. 1972a. “Technique for Analyzing Overlapping Memberships.” Sociological Methodology 4: 176–85. doi:10.2307/270732.
Bonacich, Phillip. 1972b. “Factoring and Weighting Approaches to Status Scores and Clique Identification.” The Journal of Mathematical Sociology 2 (1): 113–20. doi:10.1080/0022250X.1972.9989806.
Mizruchi, Mark S., and David Bunting. 1981. “Influence in Corporate Networks: An Examination of Four Measures.” Administrative Science Quarterly 26, no. 3: 475–89. doi:10.2307/2392519.
# Find the Bonacich centralities for all the companies that Berkshire Hathaway holds data('firms_BKB') FF_BKB <- FF.norm.ownership(firms_BKB) bonacich(FF_BKB)
# Find the Bonacich centralities for all the companies that Berkshire Hathaway holds data('firms_BKB') FF_BKB <- FF.norm.ownership(firms_BKB) bonacich(FF_BKB)
Cascade failure analysis (CFA) involves understanding how failures in one part of the network might cascade to other parts. Networks capable of isolating such failures or minimizing their effects demonstrate higher robustness.
cfa( ..., ordering = "tot", custom.order = NULL, decreasing = TRUE, Rcpp = ifelse(requireNamespace("Rcpp", quietly = TRUE), yes = TRUE, no = FALSE) )
cfa( ..., ordering = "tot", custom.order = NULL, decreasing = TRUE, Rcpp = ifelse(requireNamespace("Rcpp", quietly = TRUE), yes = TRUE, no = FALSE) )
... |
Firm-Firm network in one of the following classes:
|
ordering |
In what order to remove the firms, the completing ordering is always returned as part of the result. Take the following values:
|
custom.order |
Order in which to remove the firms. If |
decreasing |
Logical, defaults to
|
Rcpp |
Whether to use the |
A data.frame
with one row for the result of the CFA after each node is removed. The columns report:
l_scc
- Size of the largest strongly connected component
rem_id
- ID of the firm removed
rem_pos
- Position of the firm removed (row/column number)
n_scc
- Number of strongly connected components
n_rem
- Number of firms removed
n_left
- Number of firms left
Telarico, Fabio Ashtar
Elliott, Matthew, Benjamin Golub, and Matthew O. Jackson. ‘Financial Networks and Contagion’. American Economic Review 104, no. 10 (1 October 2014): 3115–53. doi:10.1257/aer.104.10.3115.
# Create a matrix mat <- matrix(c( 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 ),ncol = 8, byrow = TRUE) # Add rownames rownames(mat) <- paste0("Firm", LETTERS[1:ncol(mat)]) # Create a FF matrix mat <- methods::new('financial_matrix', M = mat, relation = c('own'), legal_form = c('JSC'), sector = c('A.01'), revenues = c(NA), capitalisation = c(NA), currency = c('USD')) # Notice the differnce between: # a. CFA with ordering by in-degree (decreasing) # b. CFA with ordering by in-degree (increasing) cfa(mat, ordering = 'in', decreasing = FALSE) # But ordering by increasing (decreasing) in-degree is the # same as ordering by decreasing (increasing) out-degree and # vice versa! cfa(mat, ordering = 'out', decreasing = FALSE) # By out-degree (increasing)
# Create a matrix mat <- matrix(c( 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 ),ncol = 8, byrow = TRUE) # Add rownames rownames(mat) <- paste0("Firm", LETTERS[1:ncol(mat)]) # Create a FF matrix mat <- methods::new('financial_matrix', M = mat, relation = c('own'), legal_form = c('JSC'), sector = c('A.01'), revenues = c(NA), capitalisation = c(NA), currency = c('USD')) # Notice the differnce between: # a. CFA with ordering by in-degree (decreasing) # b. CFA with ordering by in-degree (increasing) cfa(mat, ordering = 'in', decreasing = FALSE) # But ordering by increasing (decreasing) in-degree is the # same as ordering by decreasing (increasing) out-degree and # vice versa! cfa(mat, ordering = 'out', decreasing = FALSE) # By out-degree (increasing)
General function to create a firm-firm (FF) matrix
FF(..., who, ties, id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE)
FF(..., who, ties, id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE)
... |
Either multiple objects of class |
who |
Whether to take into account: ( |
ties |
Type of ties to create. Possible values: |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
See more specific functions for a detailed overview:
for board interlocks (who == 'management'
):
FF.binary.management
, if ties = 'binary'
;
FF.binary.management
, if ties = 'naive'
;
FF.norm.management
, if ties = 'share'
.
for co-ownership (who == 'ownership'
):
FF.binary.ownership
, if ties = 'binary'
;
FF.naive.ownership
, if ties = 'naive'
;
FF.norm.ownership
, if ties = 'share'
.
for both co-ownership and board interlocks (who == 'both'
):
FF.binary.both
, if ties = 'binary'
;
FF.naive.both
, if ties = 'naive'
;
FF.norm.both
, if ties = 'share'
.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the normalised FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF(firms_BKB, who = 'man', ties = 'share')
# Create the normalised FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF(firms_BKB, who = 'man', ties = 'share')
financial_matrix
Basic methods for objects of class financial_matrix
## S4 method for signature 'financial_matrix' rownames(x, do.NULL = TRUE, prefix = "row") ## S4 method for signature 'financial_matrix' colnames(x, do.NULL = TRUE, prefix = "row")
## S4 method for signature 'financial_matrix' rownames(x, do.NULL = TRUE, prefix = "row") ## S4 method for signature 'financial_matrix' colnames(x, do.NULL = TRUE, prefix = "row")
x |
The |
do.NULL |
Whether to use |
prefix |
Prefix for created names (if |
Mind that usually the rows and columns are named after the firm's tickers.
A character vector of length equal to the number of rows (or columns) in the financial_matrix
corresponding to the names of the rows (or columns)
Telarico, Fabio Ashtar
financial_matrix
objectBasic method to check to compare values in a financial_matrix
object
## S4 method for signature 'financial_matrix,logical' duplicated(x, incomparables = FALSE, ...) ## S4 method for signature 'financial_matrix,logical' unique(x, incomparables = FALSE, ...)
## S4 method for signature 'financial_matrix,logical' duplicated(x, incomparables = FALSE, ...) ## S4 method for signature 'financial_matrix,logical' unique(x, incomparables = FALSE, ...)
x |
The |
incomparables |
Either:
|
... |
Arguments passed to the relevant |
duplicated
: A logical array with the same dimensions and dimnames
of the financial_matrix
's matrix component.
unique
: The matrix component is coerced into a vector and then returned, but with only one copy of each duplicated element.
Telarico, Fabio Ashtar
financial_matrix
objectsisSymmetric
checks only the matrix-like part
summary
operates on all numeric attributes and the matrix-like part
## S4 method for signature 'financial_matrix' isSymmetric(object, ...) ## S4 method for signature 'financial_matrix' summary(object, ...)
## S4 method for signature 'financial_matrix' isSymmetric(object, ...) ## S4 method for signature 'financial_matrix' summary(object, ...)
object |
The |
... |
Arguments passed to the relevant |
Mathematical methods for financial_matrix
objects
isSymmetric
: a boolean, TRUE
if the matrix is symmetric, FALSE
otherwise;
summary
: a list of length equal to the number of numeric attributes possed by the financial_matrix
(maximum three, the matrix itself, revenues, and capitalisation) assumed as measured on the same scale and denominated in the same currency). Each element of the list of class c('summaryDefault', 'table')
which has specialized format and print methods
Telarico, Fabio Ashtar
financial_matrix
objectUnlike most other methods (i.e., duplicated
, isSymmetric
, summary
, rownames
, and colnames
), these methods act on both the matrix-like and the other components of a financial_matrix
object.
## S4 method for signature 'financial_matrix' ncol(x) ## S4 method for signature 'financial_matrix' nrow(x)
## S4 method for signature 'financial_matrix' ncol(x) ## S4 method for signature 'financial_matrix' nrow(x)
x |
The |
Checks if the length of the names matches that of the other attributes that are not NA
or structurally of unitary length (i.e., the slots M
and relation
).
A single numeric, the number of rows (columns) in the matrix. It also prints a message to the console if any of the object's other attributes (e.g., capitalisation) is not conformed to the matrix's dimensions
Telarico, Fabio Ashtar
financial_matrix
Subsets all components of a financial_matrix
object
## S4 method for signature 'financial_matrix' subset(x, ...)
## S4 method for signature 'financial_matrix' subset(x, ...)
x |
The |
... |
Arguments passed to the relevant |
A financial_matrix
object, subsetted to the desired firms
Telarico, Fabio Ashtar
Function to create a binary firm-firm (FF) matrix based on both common ownership and board interlocks
FF.binary.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
FF.binary.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
combining |
How to combine the FF matrix for managers and that for owners. Possible values:
|
The ties' value will be: if there is at least one common manager or owner,
otherwise.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the complete binary firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.binary.both(firms_BKB)
# Create the complete binary firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.binary.both(firms_BKB)
Function to create a binary firm-firm (FF) matrix based on board interlocks
FF.binary.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.binary.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the binary FF matrix of Berkshire Hathaway's holdings by boards interlock data('firms_BKB') FF <- FF.binary.management(firms_BKB)
# Create the binary FF matrix of Berkshire Hathaway's holdings by boards interlock data('firms_BKB') FF <- FF.binary.management(firms_BKB)
Function to create a binary firm-firm (FF) matrix based on common ownership
FF.binary.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.binary.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the binary FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.binary.ownership(firms_BKB)
# Create the binary FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.binary.ownership(firms_BKB)
igraph
Create an object of class igraph
from the package igraph
using a FF matrix of class financial_matrix
using all the default aesthetic options
FF.graph(x, aesthetic = c("simple", "nice"))
FF.graph(x, aesthetic = c("simple", "nice"))
x |
A matrix-like object produced by |
aesthetic |
Choose a pre-set for the graph's look. Either |
This function does not allow for any of the additional arguments that can be passed to FF.graph.custom
.
A network in the desired format
Loops will be allowed if at least one of the matrix's diagonal entries is not zero. The igraph will be valued if at least one entry of the matrix is neither zero nor one.
Instead, if aesthetic
is set to 'simple'
:
The width of the ties is 1
;
The colour of the ties is #b4b4b4
(Philippine Silver);
The size of the nodes is 5
;
The colour of the nodes is #081677
(Gentian blue).
Otherwise, if aesthetic
is set to 'nice'
:
The width of the ties is 1
;
The colour of the ties is a grey scale reflecting tie strength if the graph is valued, otherwise it is #b4b4b4
(Philippine Silver);
The size of the nodes reflects their capitalisation
if all firms have data on it and ranges between 1
and 5
, otherwise it is 5
for all nodes;
The colour of the nodes reflects their sector
if all firms have data on it is taken from a built-in palette, otherwise it is #081677
(Gentian blue).
Telarico, Fabio Ashtar
FF.net FF.net.custom FF.graph.custom
# Create a nice graph representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.graph(x = x, aesthetic = 'nice')
# Create a nice graph representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.graph(x = x, aesthetic = 'nice')
igraph
Create an object of class graph
from the package igraph
using a FF matrix of class financial_matrix
FF.graph.custom( x, vertex.size = NULL, vertex.colour = NULL, edge.width = NULL, edge.greyscale = NULL, directed = TRUE, loops = FALSE, weighted = any(x@M %in% c(0, 1)), ... )
FF.graph.custom( x, vertex.size = NULL, vertex.colour = NULL, edge.width = NULL, edge.greyscale = NULL, directed = TRUE, loops = FALSE, weighted = any(x@M %in% c(0, 1)), ... )
x |
A matrix-like object produced by |
vertex.size |
Which piece of information on the firms should be used to represent the nodes' size (see Details). |
vertex.colour |
Which piece of information on the firms should be used to represent the nodes' colours (see Details). |
edge.width |
Whether to use the edges' width to represent tie strength. Defaults to |
edge.greyscale |
Whether to use the edges' colour to represent tie strength through a grey scale. Defaults to |
directed |
Whether the network should be directed. Defaults to |
loops |
Whether the network should have loops. Defaults to |
weighted |
Whether the ties/edges should be weighted. Defaults to |
... |
Aliases to the other parameters and additional settings (see Details). |
This function allows for a number of additional arguments.
A network in the desired format
vertex.colour
and vertex.size
The pieces of information that is possible to pass to vertex.size
and vertex.colour
are:
capitalisation
, will be arranged into steps (see capitalisation.bins
below)
revenue
, will be arranged into steps (see revenues.bins
below)
legal_form
sector
currency
edge.width
and edge.greyscale
The pieces of information that is possible to pass to edge.width
and edge.greyscale
are:
capitalisation
revenue
vertex.size
The effect of the additional parameters that modify the behaviour of vertex.size
are:
vertex.size.max
(defaults to 5
) :
if vertex.size
or one of its aliases is specified, this is the size of the biggest vertex;
if neither vertex.size
nor any of its aliases is given, this is the size of ALL vertices.
vertex.size.min
(defaults to 1
):
if vertex.size
or one of its aliases is specified, this is the size of the smallest vertex;
if neither vertex.size
nor any of its aliases is given, it is ignored.
vertex.colour
The only additional parameter related to vertex.colour
is vertex.colour.palette
.
It supports a vector of RGB or named colours (see colours
for all named colours in R
).
It also accepts complete calls to functions that return a such a vector like RColorBrewer::brewer.pal(n, name)
or viridisLite::viridis(n, option)
.
If the palette is too short, it will be extended automatically using colorRampPalette
.
If the palette is not declared, but this arguemnt is TRUE
, it will defaulr to the following vector of colours:
#00204D
, Oxford Blue
#31446B
, Police Blue
#666970
, Dim Grey
#958F78
, Artichoke
#CBBA69
, Dark Khaki
#FFEA46
, Gargoyle Gas
If the argument is FALSE
, NULL
or NA
, the vertex will be coloured of #081677
(Gentian blue).
edge.width
edge.width.max
(defaults to 5
) :
if edge.width
or one of its aliases is specified, this is the thickness of the thickest edge;
if neither edge.width
nor any of its aliases is given, this is the thickness of ALL edges
edge.width.min
(defaults to 1
):
if edge.width
or one of its aliases is specified, this is the thickness of the slimmest edge;
if neither edge.width
nor any of its aliases is given, it is ignored.
edge.greyscale
edge.greyscale.darkest
(defaults to 5
) :
if edge.greyscale
or one of its aliases is specified, this is the thickness of the thickest edge;
if neither edge.greyscale
nor any of its aliases is given, this is the thickness of ALL edges
edge.greyscale.fairest
(defaults to 1
):
if edge.greyscale
or one of its aliases is specified, this is the thickness of the slimmest edge;
if neither edge.greyscale
nor any of its aliases is given, it is ignored.
Several aliases are accepted for all arguments, except M
:
for vertex.size
: node.size
for vertex.colour
: vertex.color
, node.colour
, and node.color
;
for edge.width
: tie.width
for edge.greyscale
: tie.grayscale
, tie.greyscale
, and edge.grayscale
Telarico, Fabio Ashtar
# Create the graph representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.graph.custom(x = x, node.size = 3)
# Create the graph representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.graph.custom(x = x, node.size = 3)
Function to create a naive-valued firm-firm (FF) matrix based on both common ownership and board interlocks
FF.naive.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
FF.naive.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
combining |
How to combine the FF matrix for managers and that for owners. Possible values:
|
The ties' value will reflect the count of common owners and membership depending on combining
:
sum
: sum of the counts;
mean
or average
: average of the counts;
min
: minimum of the counts;
max
: maximum of the counts.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the complete naive firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.naive.both(firms_BKB)
# Create the complete naive firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.naive.both(firms_BKB)
Function to create a naive-valued firm-firm (FF) matrix based on boards interlocks
FF.naive.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.naive.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
Naive-valued means simply counting the number of common managers.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the naive FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF.naive.management(firms_BKB)
# Create the naive FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF.naive.management(firms_BKB)
Function to create a naive-valued firm-firm (FF) matrix based on common ownership
FF.naive.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.naive.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
Naive-valued means simply counting the number of common owners
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.norm.both()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the naive FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.naive.ownership(firms_BKB)
# Create the naive FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.naive.ownership(firms_BKB)
network
Create an object of class network
from the package network
using a FF matrix of class financial_matrix
using all the default aesthetic options
FF.net(x, aesthetic = c("simple", "nice"))
FF.net(x, aesthetic = c("simple", "nice"))
x |
A matrix-like object produced by |
aesthetic |
Choose a pre-set for the network's look. Either |
This function does not allow for any of the additional arguments that can be passed to FF.net.custom
.
A network in the desired format
Loops will be allowed if at least one of the matrix's diagonal entries is not zero. The network will be valued if at least one entry of the matrix is neither zero nor one.
Instead, if aesthetic
is set to 'simple'
:
The width of the ties is 1
;
The colour of the ties is #b4b4b4
(Philippine Silver);
The size of the nodes is 5
;
The colour of the nodes is #081677
(Gentian blue).
Otherwise, if aesthetic
is set to 'nice'
:
The width of the ties is 1
;
The colour of the ties is a grey scale reflecting tie strength if the network is valued, otherwise it is #b4b4b4
(Philippine Silver);
The size of the nodes reflects their capitalisation
if all firms have data on it and ranges between 1
and 5
, otherwise it is 5
for all nodes;
The colour of the nodes reflects their sector
if all firms have data on it is taken from a built-in palette, otherwise it is #081677
(Gentian blue).
Telarico, Fabio Ashtar
FF.net.custom FF.graph FF.graph.custom
# Create a nice network representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.net(x = x, aesthetic = 'nice')
# Create a nice network representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.net(x = x, aesthetic = 'nice')
network
Create an object of class network
from the package network
using a FF matrix of class financial_matrix
FF.net.custom( x, vertex.size = NULL, vertex.colour = NULL, edge.width = NULL, edge.greyscale = NULL, directed = TRUE, loops = FALSE, weighted = any(x@M %in% c(0, 1)), ... )
FF.net.custom( x, vertex.size = NULL, vertex.colour = NULL, edge.width = NULL, edge.greyscale = NULL, directed = TRUE, loops = FALSE, weighted = any(x@M %in% c(0, 1)), ... )
x |
A matrix-like object produced by |
vertex.size |
Which piece of information on the firms should be used to represent the nodes' size (see Details). |
vertex.colour |
Which piece of information on the firms should be used to represent the nodes' colours (see Details). |
edge.width |
Whether to use the edges' width to represent tie strength. Defaults to |
edge.greyscale |
Whether to use the edges' colour to represent tie strength through a grey scale. Defaults to |
directed |
Whether the network should be directed. Defaults to |
loops |
Whether the network should have loops. Defaults to |
weighted |
Whether the ties/edges should be weighted. Defaults to |
... |
Aliases to the other parameters and additional settings (see Details). |
This function allows for a number of additional arguments.
A network in the desired format
vertex.colour
and vertex.size
The pieces of information that is possible to pass to vertex.size
and vertex.colour
are:
capitalisation
, will be arranged into steps (see capitalisation.bins
below)
revenue
, will be arranged into steps (see revenues.bins
below)
legal_form
sector
currency
edge.width
and edge.greyscale
The pieces of information that is possible to pass to edge.width
and edge.greyscale
are:
capitalisation
revenue
vertex.size
The effect of the additional parameters that modify the behaviour of vertex.size
are:
vertex.size.max
(defaults to 5
):
if vertex.size
or one of its aliases is specified, this is the size of the biggest vertex;
if neither vertex.size
nor any of its aliases is given, this is the size of ALL vertices.
vertex.size.min
(defaults to 1
):
if vertex.size
or one of its aliases is specified, this is the size of the smallest vertex;
if neither vertex.size
nor any of its aliases is given, it is ignored.
vertex.colour
The only additional parameter related to vertex.colour
is vertex.colour.palette
.
It supports a vector of RGB or named colours (see colours
for all named colours in R
).
It also accepts complete calls to functions that return a such a vector like RColorBrewer::brewer.pal(n, name)
or viridisLite::viridis(n, option)
.
If the palette is too short, it will be extended automatically using colorRampPalette
.
If the palette is not declared, but this arguemnt is TRUE
, it will defaulr to the following vector of colours:
#00204D
, Oxford Blue
#31446B
, Police Blue
#666970
, Dim Gray
#958F78
, Artichoke
#CBBA69
, Dark Khaki
#FFEA46
, Gargoyle Gas
If the argument is FALSE
, NULL
or NA
, the vertex will be coloured of #081677
(Gentian blue).
edge.width
edge.width.max
(defaults to 5
):
if edge.width
or one of its aliases is specified, this is the thickness of the thickest edge;
if neither edge.width
nor any of its aliases is given, this is the thickness of ALL edges
edge.width.min
(defaults to 1
):
if edge.width
or one of its aliases is specified, this is the thickness of the slimmest edge;
if neither edge.width
nor any of its aliases is given, it is ignored.
edge.greyscale
edge.greyscale.darkest
(defaults to 5
) :
if edge.greyscale
or one of its aliases is specified, this is the thickness of the thickest edge;
if neither edge.greyscale
nor any of its aliases is given, this is the thickness of ALL edges
edge.greyscale.fairest
(defaults to 1
):
if edge.greyscale
or one of its aliases is specified, this is the thickness of the slimmest edge;
if neither edge.greyscale
nor any of its aliases is given, it is ignored.
Several aliases are accepted for all arguments, except M
:
for vertex.size
: node.size
for vertex.colour
: vertex.color
, node.colour
, and node.color
;
for edge.width
: tie.width
for edge.greyscale
: tie.grayscale
, tie.greyscale
, and edge.grayscale
Telarico, Fabio Ashtar
FF.net FF.graph FF.graph.custom
# Create the network representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.net.custom(x = x, node.size = 3)
# Create the network representation of the binary FF of # Berkshire Hataway's holdings based on common ownership data("firms_BKB") x <- FF.naive.ownership(firms_BKB) FF.net.custom(x = x, node.size = 3)
Function to create a normalised-valued firm-firm (FF) matrix based on both common ownership and board interlocks
FF.norm.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
FF.norm.both( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE, combining = "sum" )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
combining |
How to combine the FF matrix for managers and that for owners. Possible values:
|
The ties' value will reflect the count of common owners and membership depending on combining
:
-sum
: sum of the shares (normalised on 2);
-mean
or average
: average of the shares (normalised on 1);
-min
: minimum of the shares (normalised on 1);
-max
: maximum of the shares (normalised on 1).
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.management()
,
FF.norm.ownership()
# Create the complete normalised firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.norm.both(firms_BKB)
# Create the complete normalised firm-firm matrix for the companies held by Berkshire Hathaway data('firms_BKB') FF <- FF.norm.both(firms_BKB)
Function to create a normalised-valued firm-firm (FF) matrix based on boards interlocks
FF.norm.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.norm.management( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
Normalised-valued means that weights represent the share of common managers.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.ownership()
# Create the normalised FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF.norm.management(firms_BKB)
# Create the normalised FF matrix of Berkshire Hathaway's holdings by boards interlocks data('firms_BKB') FF <- FF.norm.management(firms_BKB)
Function to create a normalised-valued firm-firm (FF) matrix based on common ownership
FF.norm.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
FF.norm.ownership( ..., id_as_firm_name = NULL, Matrix = NULL, self_ties = FALSE )
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
self_ties |
Whether to allow self-ties (a 'loop' in graph theory). Defaults to |
Normalised-valued means that weights represent the share of common managers.
A matrix object of class financial_matrix
(possibly using the Matrix
package)
Telarico, Fabio Ashtar
Other Financial_matrix builders:
FF()
,
FF.binary.both()
,
FF.binary.management()
,
FF.binary.ownership()
,
FF.naive.both()
,
FF.naive.management()
,
FF.naive.ownership()
,
FF.norm.both()
,
FF.norm.management()
# Create the normalised FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.norm.ownership(firms_BKB)
# Create the normalised FF matrix of Berkshire Hathaway's holdings by common ownership data('firms_BKB') FF <- FF.norm.ownership(firms_BKB)
This function expresses the algebraic connectivity of a Firm-Firm network as its Fiedler value. The Fiedler value, named after Miroslav Fiedler, who explored its significance, summarises the connectivity and robustness of a network. Mathematically, it is the second smallest eigenvalue of the network's Laplacian matrix
fiedler(..., ignore.weights = FALSE, generalise = NULL)
fiedler(..., ignore.weights = FALSE, generalise = NULL)
... |
Firm-Firm network in one of the following classes:
|
ignore.weights |
Optional parameter, defaults to |
generalise |
See Details for more information. Defaults to |
The Fiedler value is specifically defined for undirected graphs. For directed or asymmetrical networks like the Firm-Firm ones, the Laplacian is not necessarily symmetric, and its eigenvalues can be complex. In practical applications, this is more likely to happen in naively valued networks, due to the presence of large off-diagonal values. But it can happen also under other circumstances.
There are three main workarounds:
1. Symmetrisation - Simply considers the underlying undirected graph. This involves ignoring the direction of edges and calculating the Laplacian matrix and its eigenvalues as if the graph were undirected.
2. The generalised Laplacian calculated as the sum of the diagonal matrices for
in-degree and out-degree
3. The Hermitian part of the Laplacian - Uses the Hermitian part of the
Laplacian matrix of the directed network ,
where the second addendum is the conjugate transpose of the adjacency matrix.
Practically, the third method is excessive here, as the values of the ties
cannot be complex numbers. Indeed, the Hermitian is actually the Laplacian
of the underlying symmetric network with the value of the ties being split
equally in both directions because the conjugate of a real number is that number.
Moreover, symmetrising before calculating the Laplacian or generalising the matrix
returns the same result. So, the parameter
generalise
is logical
and takes the following values:
TRUE
for the generalised Laplacian;
FALSE
for the possibly complex (and uninterpretable) eigenvalue of the as-is Laplacian.
NULL
will take the generalised Laplacian only if necessary.
A numeric, the Fiedler value.
Telarico, Fabio Ashtar
Fiedler, Miroslav. ‘Laplacian of Graphs and Algebraic Connectivity’. Banach Center Publications 25, no. 1 (1989): 57–70. https://eudml.org/doc/267812.
Guo, Krystal, and Bojan Mohar. ‘Hermitian Adjacency Matrix of Digraphs and Mixed Graphs’. Journal of Graph Theory 85, no. 1 (May 2017): 217–48. doi:10.1002/jgt.22057.
# Load some data data('firms_BKB') # Create a FF matrix mat <- FF(firms_BKB, who = 'b', ties = 'n') fiedler(mat) # Create a FF network if(!require('network')){ net <- FF.net(mat, 'simple') fiedler(net)==fiedler(mat) } # Create a FF graph if(!require('igraph')){ g <- FF.graph(mat, 'simple') fiedler(g)==fiedler(mat) }
# Load some data data('firms_BKB') # Create a FF matrix mat <- FF(firms_BKB, who = 'b', ties = 'n') fiedler(mat) # Create a FF network if(!require('network')){ net <- FF.net(mat, 'simple') fiedler(net)==fiedler(mat) } # Create a FF graph if(!require('igraph')){ g <- FF.graph(mat, 'simple') fiedler(g)==fiedler(mat) }
firm
(legal person) using data from 'Yahoo! Finance'Tickers can be retrieved from [Yahoo! Finance](https://finance.yahoo.com/lookup/).
This function requires the package yahoofinancer
to be installed. It is available from the CRAN by running install.packages('yahoofinancer')
.
find.firm( ticker, name = NULL, ticker_is_id = TRUE, legal_form = NULL, sector_granularity = 1, managers_remove_salutation_title = TRUE, managers_only_surname = FALSE )
find.firm( ticker, name = NULL, ticker_is_id = TRUE, legal_form = NULL, sector_granularity = 1, managers_remove_salutation_title = TRUE, managers_only_surname = FALSE )
ticker |
Firm's ticker. |
name |
Provide the firm's name. If not provided, |
ticker_is_id |
Should the ticker be used as the firm's id? |
legal_form |
The firm's legal form of the firm. Possible values:
- a string (e.g., 'LLC', 'Private', 'GmbH', etc.);
- |
sector_granularity |
Sector in which the firm operates. Possible values:
- |
managers_remove_salutation_title |
Yahoo! Finance provide salutation titles before the names of the managers. If this is |
managers_only_surname |
Yahoo! Finance provide first, middle, and last name of the managers. If this is |
An object of the S4 class firm
containing several fields, only the first one of which is mandatory:
name |
Name of the firm (or ticker if no name was provided) |
id |
Firm' ticker (if ticker_is_id was 'TRUE') or nothing (otherwise) |
legal_form |
Legal form of the firm (may be null) |
sector |
Sector in which the firm operates (may be null) |
revenues |
Yearly revenues |
capitalisation |
Capitalisation |
management |
Members of the board |
ownership |
Owner(s) |
shares |
Share owned by (each of) the owner(s) |
currency |
Currency |
Telarico, Fabio Ashtar
# Registering Apple automatically #| Results are subject to the correct functioning of the package `yahoofinancer` #| and of the Yahoo! Finance API
# Registering Apple automatically #| Results are subject to the correct functioning of the package `yahoofinancer` #| and of the Yahoo! Finance API
firms
(legal persons) using data from 'Yahoo! Finance'If legal_form
is a vector containing:
- one or more NULL
elements, the corresponding firm
's legal form will be JSC
;
- one or more NA
s, the corresponding firm
's legal form will be NA
.
find.firms( tickers, name = NULL, ticker_is_id = TRUE, legal_form = NULL, sector_granularity = 1, managers_remove_salutation_title = TRUE, managers_only_surname = FALSE )
find.firms( tickers, name = NULL, ticker_is_id = TRUE, legal_form = NULL, sector_granularity = 1, managers_remove_salutation_title = TRUE, managers_only_surname = FALSE )
tickers |
The firms' ticker. |
name |
Provide the firms' names as a vector of the same length as tickers. If not provided, |
ticker_is_id |
Should the ticker be used as the firm's id? |
legal_form |
The firm's legal form of the firm. Possible values:
- a vector of strings (e.g., 'LLC', 'Private', 'GmbH', etc.) of the same length as |
sector_granularity |
Sector in which the firm operates. Possible values:
- |
managers_remove_salutation_title |
Yahoo! Finance provide salutation titles before the names of the managers. If this is |
managers_only_surname |
Yahoo! Finance provide first, middle, and last name of the managers. If this is |
To ensure consistency, ticker_is_id
, sector_granularity
, managers_remove_salutation_title
, and managers_only_surname
cannot be vectors.
Tickers can be retrieved from [Yahoo! Finance](https://finance.yahoo.com/lookup/).
This function requires the package yahoofinancer
to be installed. It is available from the CRAN by running install.packages('yahoofinancer')
.
An object of the S4 class firm
containing several fields, only the first one of which is mandatory:
name |
Name of the firm (or ticker if no name was provided) |
id |
Firm' ticker (if ticker_is_id was 'TRUE') or nothing (otherwise) |
legal_form |
Legal form of the firm (may be null) |
sector |
Sector in which the firm operates (may be null) |
revenues |
Yearly revenues |
capitalisation |
Capitalisation |
management |
Members of the board |
ownership |
Owner(s) |
shares |
Share owned by (each of) the owner(s) |
currency |
Currency |
Telarico, Fabio Ashtar
# Registering Apple, General Motors, and British American Tobacco automatically #| Results are subject to the correct functioning of the package `yahoofinancer` #| and of the Yahoo! Finance API
# Registering Apple, General Motors, and British American Tobacco automatically #| Results are subject to the correct functioning of the package `yahoofinancer` #| and of the Yahoo! Finance API
firm
objectsExtract all the unique people associated to at least one of the provided firm
objects
find.people(..., who = c("managers", "owners", "both", "all"), sorting = TRUE)
find.people(..., who = c("managers", "owners", "both", "all"), sorting = TRUE)
... |
Either multiple objects of class |
who |
Whether to extract the 'managers' or the 'owners' (minimum unambiguous string) |
sorting |
Whether to sort the people by alphabetical order. Defaults to |
A vector containing the names of the individuals looked up. If
Telarico, Fabio Ashtar
# Find all the shareholders in companies that Berkshire Hathaway holds data('firms_BKB') shareholders <- find.people(firms_BKB, who = 'own') # Find all those managing the companies that Berkshire Hathaway holds data('firms_BKB') managers <- find.people(firms_BKB, who = 'man')
# Find all the shareholders in companies that Berkshire Hathaway holds data('firms_BKB') shareholders <- find.people(firms_BKB, who = 'own') # Find all those managing the companies that Berkshire Hathaway holds data('firms_BKB') managers <- find.people(firms_BKB, who = 'man')
Data on Apple (AAPL), General Motors (GM), and British American Tobacco (BTI) extracted from Yahoo! Finance (on May 20, 2023) and formatted a firm
objects.
data('firms_BKB')
data('firms_BKB')
Three objects of class firm
.
- Divine, John. “The Complete Berkshire Hathaway Portfolio.” FInancial data. U.S. News & World Report, May 17, 2023. <https://money.usnews.com/investing/stock-market-news/articles/the-complete-berkshire-hathaway-portfolio>. - ICE Data Services. “Nasdaq Stock Exchange & Dow Jones Indexes.” Financial data, May 21, 2023, <https://finance.yahoo.com/lookup/>.
Data on Apple (AAPL), General Motors (GM), and British American Tobacco (BTI) extracted from Yahoo! Finance (on May 20, 2023) and formatted a firm
objects.
data('firms_US')
data('firms_US')
Three objects of class firm
.
ICE Data Services. “Nasdaq Stock Exchange & Dow Jones Indexes.” Financial data, May 21, 2023, <https://finance.yahoo.com/lookup/>
Function to create a (necessarily binary) firm-manager (FM) matrix
FM(..., id_as_firm_name = NULL, Matrix = NULL)
FM(..., id_as_firm_name = NULL, Matrix = NULL)
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
A matrix object of class financial_matrix
(possibly using the Matrix
package) in which:
Represent firms;
Represent managers (usually physical persons).
Telarico, Fabio Ashtar
# Create the FM matrix of Berkshire Hathaway's holdings data('firms_BKB') FM <- FM(firms_BKB)
# Create the FM matrix of Berkshire Hathaway's holdings data('firms_BKB') FM <- FM(firms_BKB)
Function to create a binary firm-owner (FO) matrix
FO.binary(..., id_as_firm_name = NULL, Matrix = NULL)
FO.binary(..., id_as_firm_name = NULL, Matrix = NULL)
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
A matrix object of class financial_matrix
(possibly using the Matrix
package) in which:
Represent firms;
Represent owners (physical and legal persons).
Telarico, Fabio Ashtar
# Create the binary FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.binary(firms_BKB)
# Create the binary FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.binary(firms_BKB)
The values are simply the value of the owner 's stake in firm
.
FO.naive(..., id_as_firm_name = NULL, Matrix = NULL)
FO.naive(..., id_as_firm_name = NULL, Matrix = NULL)
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
A matrix object of class financial_matrix
(possibly using the Matrix
package) in which:
Represent firms;
Represent owners (physical and legal persons).
Telarico, Fabio Ashtar
# Create the naive FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.naive(firms_BKB)
# Create the naive FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.naive(firms_BKB)
The values represent the share of firm 's capital owned by
.
FO.norm(..., id_as_firm_name = NULL, Matrix = NULL)
FO.norm(..., id_as_firm_name = NULL, Matrix = NULL)
... |
Either multiple objects of class |
id_as_firm_name |
Whether to use the ticker as the firm's name. Defaults to |
Matrix |
Whether to use the |
A matrix object of class financial_matrix
(possibly using the Matrix
package) in which:
Represent firms;
Represent owners (physical and legal persons).
Telarico, Fabio Ashtar
# Create the normalised FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.norm(firms_BKB)
# Create the normalised FO matrix of Berkshire Hathaway's holdings data('firms_BKB') FO <- FO.norm(firms_BKB)
igraph
functions to igraph_financial
objectsThe following functions are implemented:
V
to retrieve the vertexes (igraph::V
);
vcount
to count the vertexes (igraph::vcount
);
gorder
as an alias to vcount_fin
(igraph::gorder
);
E
to retrieve the edges (igraph::E
);
gsize
to count the edges (igraph::gsize
);
ecount
as an alias to gsize_fin
(igraph::ecount
)
plot_igraph
to plot graphs (igraph::plot.igraph
))
V(x) vcount(x) gorder(x) E(x, ...) ecount(x, ...) gsize(x, ...) plot_igraph(x, ...)
V(x) vcount(x) gorder(x) E(x, ...) ecount(x, ...) gsize(x, ...) plot_igraph(x, ...)
x |
The |
... |
Other parameters passed to the corresponding |
Implementing most basic iterators from the package igraph
for objects of class igraph_financial
The same result for both igraph
and igraph_financial
objects
V
: A vertex sequence containing all vertices, in the order of their numeric vertex ids.
vcount
and gorder
: Number of vertices, numeric scalar.
E
: An edge sequence of the graph
ecount
and gsize
: Number of edges, numeric scalar.
plot_igraph
: Returns NULL, invisibly. Called to print the graph to any R device. (see method and igraph::plot.igraph)
Telarico, Fabio Ashtar
igraph_financial
objectsMethods to extend igraph edge iterators and functions to igraph_financial
objects
## S4 method for signature 'igraph_financial' E(x, ...) ## S4 method for signature 'igraph' E(x, ...) ## S4 method for signature 'igraph_financial' ecount(x, ...) ## S4 method for signature 'igraph' ecount(x, ...) ## S4 method for signature 'igraph_financial' gsize(x, ...) ## S4 method for signature 'igraph' gsize(x, ...)
## S4 method for signature 'igraph_financial' E(x, ...) ## S4 method for signature 'igraph' E(x, ...) ## S4 method for signature 'igraph_financial' ecount(x, ...) ## S4 method for signature 'igraph' ecount(x, ...) ## S4 method for signature 'igraph_financial' gsize(x, ...) ## S4 method for signature 'igraph' gsize(x, ...)
x |
The |
... |
Other parameters passed to the corresponding method and/or |
The same result for both igraph
and igraph_financial
objects
E
: An edge sequence of the graph
ecount
and gsize
: Number of edges, numeric scalar
Telarico, Fabio Ashtar
An S4 class for the network objects produced by the FF.graph
and FF.graph.custom
to represent the relations between firms (legal person)
data
The representation of the network as a igraph object
igraph_financial
objectsMethods to extend igraph vertex iterators and functions to igraph_financial
objects
## S4 method for signature 'igraph_financial' V(x) ## S4 method for signature 'igraph' V(x) ## S4 method for signature 'igraph_financial' vcount(x) ## S4 method for signature 'igraph' vcount(x) ## S4 method for signature 'igraph_financial' gorder(x) ## S4 method for signature 'igraph' gorder(x)
## S4 method for signature 'igraph_financial' V(x) ## S4 method for signature 'igraph' V(x) ## S4 method for signature 'igraph_financial' vcount(x) ## S4 method for signature 'igraph' vcount(x) ## S4 method for signature 'igraph_financial' gorder(x) ## S4 method for signature 'igraph' gorder(x)
x |
The |
The same result for both igraph
and igraph_financial
objects
V
: A vertex sequence containing all vertices, in the order of their numeric vertex ids
vcount
and gorder
: Number of vertices, numeric scalar
Telarico, Fabio Ashtar
An S4 class for the network objects produced by the FF.net
and FF.net.custom
functions to represent the relations between firms (legal person)
data
The representation of the network as a network object
newtwork
functions to newtwork_financial
objectsThe following functions are implemented:
edgecount
to count the number of eges (network::network.edgecount
);
vertex.names
to retrieve the vertices' names (network::network.vertex.names
);
network.size
to count the edges (network::network::network.size
);
plot_network
to plot networks (network::plot.network
))
edgecount(x, ...) network.size(x, ...) vertex.names(x, ...) plot_network(x, ...)
edgecount(x, ...) network.size(x, ...) vertex.names(x, ...) plot_network(x, ...)
x |
The |
... |
Other parameters passed to the corresponding |
Implementing most basic iterators from the package newtwork
for objects of class newtwork_financial
The same result for both newtwork
and newtwork_financial
objects
edgecount
: Number of edges, numeric scalar
vertex.names
: Names/Labels of the vertices, character vector
network.size
: Number of vertices, numeric scalar
plot_network
: Returns a two-column matrix containing the vertex positions as (x,y)
coordinates, invisibly. Called to print the graph to any R
device.)
Telarico, Fabio Ashtar
network_financial
objectsMethods to extend operators from the package network
to network_financial
objects
## S4 method for signature 'network_financial' edgecount(x, ...) ## S4 method for signature 'network' edgecount(x, ...) ## S4 method for signature 'network_financial' vertex.names(x, ...) ## S4 method for signature 'network' vertex.names(x, ...) ## S4 method for signature 'network_financial' network.size(x, ...) ## S4 method for signature 'network' network.size(x, ...)
## S4 method for signature 'network_financial' edgecount(x, ...) ## S4 method for signature 'network' edgecount(x, ...) ## S4 method for signature 'network_financial' vertex.names(x, ...) ## S4 method for signature 'network' vertex.names(x, ...) ## S4 method for signature 'network_financial' network.size(x, ...) ## S4 method for signature 'network' network.size(x, ...)
x |
The |
... |
Other parameters passed to the corresponding method and/or |
The same result for both network
and network_financial
objects
network.edgecount
: Number of edges, numeric scalar
network.vertex.names
: Names/Labels of the vertices, character vector
network::network.size
: Number of vertices, numeric scalar
Telarico, Fabio Ashtar
Network efficiency quantifies how efficiently information (management relations) and/or money capital (ownership relations) flow through a network. It is essential in systemic-risk identification, resilience assessment, and crisis-propagation analysis.
network.efficiency( ..., ignore.weights = FALSE, use.igraph = isTRUE(requireNamespace("igraph", quietly = TRUE)) )
network.efficiency( ..., ignore.weights = FALSE, use.igraph = isTRUE(requireNamespace("igraph", quietly = TRUE)) )
... |
Firm-Firm network in one of the following classes:
|
ignore.weights |
Optional parameter, defaults to |
use.igraph |
Whether to use igraph to speed-up the computation. See 'Details'. |
The function is implemented both for igraph
users and in base R
using the Floyd-Warshall algorithm.
However, the latter runs in , which may not be efficient for very large networks.
The distances enter into play in the formal definition of efficiency:
where:
is the set of all nodes;
is the number of nodes (i.e., the number of elements in
;
is the shortest (weighted and directed) path distance between the nodes
and
.
A numeric
, the global efficiency value.
Telarico, Fabio Ashtar
Latora, Vito, and Masimo Marchiori. 'Economic Small-World Behavior in Weighted Networks'. The European Physical Journal B - Condensed Matter and Complex Systems 32, no. 2 (1 March 2003): 249–63. doi:10.1140/epjb/e2003-00095-5.
Floyd, Robert W. 'Algorithm 97: Shortest path'. Communications of the ACM, 5, no. 6 (1962): 345.
# Load some data data('firms_BKB') # Create a FF matrix mat <- FF(firms_BKB, who = 'b', ties = 'n') # Use the built-in Floyd-Warshall algorithm network.efficiency(mat, use.igraph = FALSE) #' # Create a FF graph if(!require('igraph')){ g <- FF.graph(mat, 'simple') # Use igraph's implementation, which gives the same result # as the built-in Floyd-Warshall algorithm, but is faster network.efficiency(g, use.igraph = TRUE)==network.efficiency(mat, use.igraph = FALSE) }
# Load some data data('firms_BKB') # Create a FF matrix mat <- FF(firms_BKB, who = 'b', ties = 'n') # Use the built-in Floyd-Warshall algorithm network.efficiency(mat, use.igraph = FALSE) #' # Create a FF graph if(!require('igraph')){ g <- FF.graph(mat, 'simple') # Use igraph's implementation, which gives the same result # as the built-in Floyd-Warshall algorithm, but is faster network.efficiency(g, use.igraph = TRUE)==network.efficiency(mat, use.igraph = FALSE) }
igraph_financial
objectsMethods to extend igraph
's plotting functions to igraph_financial
objects
## S4 method for signature 'igraph_financial' plot_igraph(x, ...) ## S4 method for signature 'igraph' plot_igraph(x, ...)
## S4 method for signature 'igraph_financial' plot_igraph(x, ...) ## S4 method for signature 'igraph' plot_igraph(x, ...)
x |
The |
... |
Other parameters passed to the corresponding method and/or |
For both igraph
and igraph_financial
objects, returns NULL invisibly. It is called to print the graph to any R device. (see method and igraph::plot.igraph)
Telarico, Fabio Ashtar
igraph_financial
objectsMethods to extend network
's plotting functions to network_financial
objects
## S4 method for signature 'network_financial' plot_network(x, ...) ## S4 method for signature 'network' plot_network(x, ...)
## S4 method for signature 'network_financial' plot_network(x, ...) ## S4 method for signature 'network' plot_network(x, ...)
x |
The |
... |
Other parameters passed to the corresponding method and/or |
For both igraph
and igraph_financial
objects, returns NULL invisibly. It is called to print the graph to any R device. (see method and igraph::plot.igraph)
Telarico, Fabio Ashtar
firm
objectPrint method for the S4 class representing a firm (legal person)
## S4 method for signature 'firm' print(x)
## S4 method for signature 'firm' print(x)
x |
The |
No return value, called to print to the console detail information about the firm
object including:
in the first paragraph:
legal form (if any),
revenues (if known),
capitalisation (if known).
in the second paragraph, the names of the board members/managers;
in the third paragraph, a data frame with two columns:
First, the names of the owners
The, their respective share of the firm's capital (normalised to 1)
Telarico, Fabio Ashtar
firm
object (legal person)Function to extract information from a firm
object (legal person)
query.firm(firm, which, naming = TRUE)
query.firm(firm, which, naming = TRUE)
firm |
Firm which to extract information from |
which |
Information to extract, minimum unambiguous substring. Possible values (one or more):
- |
naming |
Whether to name the result after the querie information (defaults to |
Depends on the information queried. One (or, if length(which)>=2
, a list
of two or more) of the following:
name |
A string representing the name of the firm |
id |
A string representing the ID of the firm (usually its ticker) |
legal_form |
A string representing the firm's legal form |
sector |
A string indicating the sector in which the firm operates (possibly a NACE rev. 2 code) |
revenues |
A numeric (double) quantifying yearly revenues |
capitalisation |
A numeric (double) quantifying capitalisation |
management |
A vector of strings representing the members of the board |
ownership |
A vector of strings representing the owner(s) |
shares |
A numeric (double) vector indicating the shares controlled by (each of) the owner(s) |
currency |
A string indicating the currency in which revenues and capitalisation are denominated |
Telarico, Fabio Ashtar
query.firms query.firms.dataframe
# Query Apple's capitalisation data('firms_US') list2env(firms_US, parent.frame()) query.firm(AAPL, which = 'capitalisation') # Query British-American Tobacco's capitalisation using the common abbreviation 'cap' data('firms_US') list2env(firms_US, parent.frame()) query.firm(BTI, 'cap') # Query General Motors's owners and their shares, but return an unnamed \code{\link{list}} data('firms_US') list2env(firms_US, parent.frame()) query.firm(GM, c('own', 'sha'), naming = FALSE)
# Query Apple's capitalisation data('firms_US') list2env(firms_US, parent.frame()) query.firm(AAPL, which = 'capitalisation') # Query British-American Tobacco's capitalisation using the common abbreviation 'cap' data('firms_US') list2env(firms_US, parent.frame()) query.firm(BTI, 'cap') # Query General Motors's owners and their shares, but return an unnamed \code{\link{list}} data('firms_US') list2env(firms_US, parent.frame()) query.firm(GM, c('own', 'sha'), naming = FALSE)
firm
object (legal person)This function can be fed either:
- a (possibly named) list
of objects of class firm
(see examples 1 and 2); or
- multiple objects of class firm
(see example 3)
query.firms(..., which, naming = TRUE)
query.firms(..., which, naming = TRUE)
... |
Object/s which to extract information from (see 'Details') |
which |
Information to extract, minimum unambiguous sub-string. Possible values (one or more):
- |
naming |
Whether to name the result after the querie information (defaults to |
Depends on the information queried. An object of class list
(that, if length(which)>=2
, contain multiple sub-lists) of the following:
name |
A string representing the name of the firm |
id |
A string representing the ID of the firm (usually its ticker) |
legal_form |
A string representing the firm's legal form |
sector |
A string indicating the sector in which the firm operates (possibly a NACE rev. 2 code) |
revenues |
A numeric (double) quantifying yearly revenues |
capitalisation |
A numeric (double) quantifying capitalisation |
management |
A vector of strings representing the members of the board |
ownership |
A vector of strings representing the owner(s) |
shares |
A numeric (double) vector indicating the shares controlled by (each of) the owner(s) |
currency |
A string indicating the currency in which revenues and capitalisation are denominated |
Telarico, Fabio Ashtar
query.firm query.firms.dataframe
# Query Apple's, GM's, and BTI's market cap and revenues data('firms_US') query.firms(firms_US, which = c('cap', 'rev')) # Query GM's and BTI's management data('firms_US') query.firms(firms_US, which = 'man') # Query Appple's and GM's revenues and currency data('firms_US') list2env(firms_US, envir = parent.frame()) query.firms(AAPL, GM, which = c('rev', 'curr'))
# Query Apple's, GM's, and BTI's market cap and revenues data('firms_US') query.firms(firms_US, which = c('cap', 'rev')) # Query GM's and BTI's management data('firms_US') query.firms(firms_US, which = 'man') # Query Appple's and GM's revenues and currency data('firms_US') list2env(firms_US, envir = parent.frame()) query.firms(AAPL, GM, which = c('rev', 'curr'))
firm
object (legal person) as a data frameThis function can be fed either:
- a (possibly named) list
of objects of class firm
(see example 1); or
query.firms.dataframe(..., which, naming = TRUE, transposing = TRUE)
query.firms.dataframe(..., which, naming = TRUE, transposing = TRUE)
... |
Object/s which to extract information from (see 'Details') |
which |
Information to extract, minimum unambiguous sub-string. Possible values (one or more):
- |
naming |
Whether to name the result after the queried information (defaults to |
transposing |
If |
It is not recommended to use this function with management
, ownership
, or shares
unless transposing == FALSE
.
A data frame in structured as follows (or vice versa if transposing == TRUE
):
for each queried information; and
for each number of firm
.
Telarico, Fabio Ashtar
# Query Apple's, GM's, and BTI's market cap and revenues data('firms_US') query.firms.dataframe(firms_US, which = c('cap', 'rev')) # Query GM's and BTI's market cap and revenues data('firms_US') list2env(firms_US, envir = parent.frame()) query.firms.dataframe(GM, BTI, which = c('cap', 'rev'))
# Query Apple's, GM's, and BTI's market cap and revenues data('firms_US') query.firms.dataframe(firms_US, which = c('cap', 'rev')) # Query GM's and BTI's market cap and revenues data('firms_US') list2env(firms_US, envir = parent.frame()) query.firms.dataframe(GM, BTI, which = c('cap', 'rev'))
firm
(legal person)Function to create a firm
(legal person)
register.firm( name, id = NA, legal_form = NA, sector = NA, sector_classif = NULL, revenues = NA, capitalisation = NA, management = NA, ownership = NA, shares = NA, currency = NA )
register.firm( name, id = NA, legal_form = NA, sector = NA, sector_classif = NULL, revenues = NA, capitalisation = NA, management = NA, ownership = NA, shares = NA, currency = NA )
name |
Name of the firm |
id |
Provide an ID code for the firm. Defaults to |
legal_form |
Legal form of the firm (e.g., LLP, Inc, GmbH, Private, etc.) |
sector |
Sector in which the firm operates (its values depend on the value of |
sector_classif |
Which standard sector classification (if any) to be used. Possible values are
- |
revenues |
Yearly revenues |
capitalisation |
Firm's capitalisation |
management |
Names of the members of the board |
ownership |
Names of the owner(s) |
shares |
Share owned by (each of) the owner(s) |
currency |
Currency in which the capitalisation and revenues are expressed (defaults to 'USD') |
An object of the S4 class firm
containing several fields, only the first one of which is mandatory:
name |
Name of the firm |
id |
ID of the firm, usually the ticker |
legal_form |
Legal form of the firm |
sector |
Sector in which the firm operates |
revenues |
Yearly revenues |
capitalisation |
Capitalisation |
management |
Members of the board |
ownership |
Owner(s) |
shares |
Share owned by (each of) the owner(s) |
currency |
Currency |
Telarico, Fabio Ashtar
# Registering Apple manually AAPL <- register.firm(name = 'Apple', id = 'AAPL', legal_form = 'GmbH', revenues = 81665400000, capitalisation = 2755039000000, management = my_vector <- c("Timothy D. Cook", "Luca Maestri", "Jeffrey E. Williams", "Katherine L. Adams", "Deirdre O'Brien", "Chris Kondo", "James Wilson", "Mary Demby", "Nancy Paxton", "Greg Joswiak"), ownership = c('Vanguard Total Stock Market Index Fund', 'Vanguard 500 Index Fund', 'Fidelity 500 Index Fund', 'SPDR S&P 500 ETF Trust', 'iShares Core S&P 500 ETF', 'Invesco ETF Tr-Invesco QQQ Tr, Series 1 ETF', 'Vanguard Growth Index Fund', 'Vanguard Institutional Index Fund-Institutional Index Fund', 'Vanguard Information Technology Index Fund', 'Select Sector SPDR Fund-Technology'), shares = c(0.0290, 0.0218, 0.0104, 0.0102, 0.0084, 0.0082, 0.0081, 0.0066, 0.0043, 0.0039), currency = 'USD') # Registering a coal-mining company indicating the sector using `NACE` codes, without ID set.seed(123456789) firm_coalmining <- register.firm( name = 'A coal-mining firm', legal_form = 'Private', sector = 'B.05', sector_classif = 'NACE' ) # Getting creative: Register a firm with coded owners and managers set.seed(123456789) firm_coded <- register.firm( name = 'Coded firm', revenues = sample(seq(1:100)/10, 1)*10^sample(1:5, 1), capitalisation = sample(seq(1:100)/10, 1)*10^sample(2:7, 1), management = c('Board Member', 'CEO', 'CTO', 'Activist investor'), ownership = c('State', 'Foreign investors'), shares = c(51, 49), currency = 'EUR' )
# Registering Apple manually AAPL <- register.firm(name = 'Apple', id = 'AAPL', legal_form = 'GmbH', revenues = 81665400000, capitalisation = 2755039000000, management = my_vector <- c("Timothy D. Cook", "Luca Maestri", "Jeffrey E. Williams", "Katherine L. Adams", "Deirdre O'Brien", "Chris Kondo", "James Wilson", "Mary Demby", "Nancy Paxton", "Greg Joswiak"), ownership = c('Vanguard Total Stock Market Index Fund', 'Vanguard 500 Index Fund', 'Fidelity 500 Index Fund', 'SPDR S&P 500 ETF Trust', 'iShares Core S&P 500 ETF', 'Invesco ETF Tr-Invesco QQQ Tr, Series 1 ETF', 'Vanguard Growth Index Fund', 'Vanguard Institutional Index Fund-Institutional Index Fund', 'Vanguard Information Technology Index Fund', 'Select Sector SPDR Fund-Technology'), shares = c(0.0290, 0.0218, 0.0104, 0.0102, 0.0084, 0.0082, 0.0081, 0.0066, 0.0043, 0.0039), currency = 'USD') # Registering a coal-mining company indicating the sector using `NACE` codes, without ID set.seed(123456789) firm_coalmining <- register.firm( name = 'A coal-mining firm', legal_form = 'Private', sector = 'B.05', sector_classif = 'NACE' ) # Getting creative: Register a firm with coded owners and managers set.seed(123456789) firm_coded <- register.firm( name = 'Coded firm', revenues = sample(seq(1:100)/10, 1)*10^sample(1:5, 1), capitalisation = sample(seq(1:100)/10, 1)*10^sample(2:7, 1), management = c('Board Member', 'CEO', 'CTO', 'Activist investor'), ownership = c('State', 'Foreign investors'), shares = c(51, 49), currency = 'EUR' )