top of page
  • Twitter
  • LinkedIn
  • Facebook

AI Handbook – CFA Institute Unsupervised Learning II: Network Theory - Edited by Joseph Simonian

gkonstantinov1111
22. Aug. 2025
1 Min. Lesezeit

Aktualisiert: 6. März


This is a chapter on network theory and its applications in finance. The chapter summarizes the basic and advanced concepts applied to financial and portfolio networks and provides practical examples. Below we provide the R programming languagte code for the visualizations.


R Code:

#colnames(INDU_experimental)<- sapply(strsplit(colnames(INDU_experimental), split='X.', fixed=TRUE), function(x) (x[2]))



returns_indu<-INDU_experimental

#mtx_indu<-data.frame()

#mtx_indu<-matrix(nrow=ncol(INDU_experimental),ncol=ncol(INDU_experimental))

mtx_indu<-cor(returns_indu)

mat_indu=sqrt(2*(1-mtx_indu))

#mat_indu=t(apply(mat_indu, 1, function(x) x/sum(x)))

mat_indu<-ifelse(mat_indu[,]>mean(mat_indu),1,0)

ifelse(mat_indu[,]>1.18,1,0)

#diag(mat_indu)<-0

colnames(mat_indu)<-colnames(INDU_experimental)


as_adjacency_matrix(net_indu)


net_indu<-as.matrix(mat_indu)

net_indu<-graph_from_adjacency_matrix(net_indu, weighted=TRUE)

hist(degree_distribution(net_indu))

E(net_indu)$arrow.size<-0


plot(net_indu, layout=layout_with_fr,vertex.label.cex=.6)


edge_density(net_indu)


tab.central<-cbind(

ec=eigen_centrality(net_indu)$vector,

cc=closeness(net_indu, normalized=TRUE),

bc=betweenness(net_indu, normalized=TRUE),

dc=degree(net_indu))

colnames(tab.central)<-c("Eigenvector", "Closeness", "Betweenness", "Degree")

tab.central<-round(tab.central,digits=2)

print(tab.central)


#Cluster Affiliation and Centrality Plots

clp<-cluster_label_prop(as.undirected(net_indu))

cfg<-cluster_fast_greedy(as.undirected(net_indu))

clei<-cluster_leading_eigen(as.undirected(net_indu))

cim<-cluster_infomap(as.undirected(net_indu))

csg<-cluster_spinglass(net_indu)

cwt<-cluster_walktrap(net_indu)

clo<-cluster_louvain(as.undirected(net_indu))


modularity(clp)

modularity(cfg)

modularity(clei)

modularity(cim)

modularity(csg)

modularity(cwt)

modularity(clo)

##select the community algorithm with the highest modularity score, which is “cwt”

V(net_indu)$com<-csg$membership

par(mfrow=c(2,2))

E(net_indu)$arrow.size<-0

plot(net_indu, layout=layout_with_kk, edge.color="grey80", vertex.color=V(net_indu)$com,vertex.size=sqrt(eigen_centrality(net_indu)$vector)*20, main="Eigenvalue")

plot(net_indu, layout=layout_with_kk, edge.color="grey80",vertex.color=V(net_indu)$com,vertex.size=sqrt(closeness(net_indu, normalized=TRUE))*20, main="Closeness")

plot(net_indu, layout=layout_with_kk,edge.color="grey80", vertex.color=V(net_indu)$com,vertex.size=sqrt(betweenness(net_indu, normalized=TRUE))*200, main="Betweenness")

plot(net_indu, layout=layout_with_kk, edge.color="grey80",vertex.color=V(net_indu)$com,vertex.size=degree(net_indu)/2,main="Degree")


par(mfrow=c(1,1))

plot(csg,net_indu, layout=layout_with_gem, edge.color="grey70"

,vertex.size=degree(net_indu)/3)

 
 
 

Kommentare


bottom of page