PINE LIBRARY
NeuralMarketsNetworkToolkit

Library "NeuralMarketsNetworkToolkit"
Open-source network analysis toolkit for Pine Script.
This library provides reusable graph algorithms, matrix utilities and network analytics for building advanced multi-asset indicators. Rather than treating markets as isolated charts, it enables developers to model relationships between assets as weighted networks and extract structural characteristics such as connectivity, centrality, clustering and influence.
Current Modules
• Matrix utilities
• Directed & undirected graphs
• Network analytics
• Node analytics
• Graph algorithms
• Experimental financial network tools
Example Applications
• Correlation networks
• Market leadership analysis
• Sector relationship maps
• Cross-asset dependency analysis
• Financial network research
Design Philosophy
This toolkit provides reusable quantitative building blocks rather than trading signals. Functions are intentionally modular so they can be combined into custom indicators and research projects.
Markets are networks. This toolkit provides the building blocks to analyze them as such.
--------------------------------------------------------------------
matrixIndex(row, col, n)
Converts row/column coordinates into a flat matrix index.
Parameters:
row (int): Row index.
col (int): Column index.
n (int): Matrix dimension.
Returns: Flat-array index.
clamp(x, lo, hi)
Clamp a float.
Parameters:
x (float): Value.
lo (float): Minimum.
hi (float): Maximum.
Returns: Clamped value.
newMatrix(n, initialValue)
Creates an n x n flat matrix initialized to a value.
Parameters:
n (int): Number of nodes.
initialValue (float): Initial cell value.
Returns: Flat float array.
setCell(matrix, row, col, n, value)
Sets a matrix cell.
Parameters:
matrix (array<float>): Flat matrix.
row (int): Row.
col (int): Column.
n (int): Matrix dimension.
value (float): New value.
getCell(matrix, row, col, n)
Gets a matrix cell.
Parameters:
matrix (array<float>): Flat matrix.
row (int): Row.
col (int): Column.
n (int): Matrix dimension.
Returns: Cell value.
setUndirectedEdge(matrix, a, b, n, weight)
Sets both directions of an undirected edge.
Parameters:
matrix (array<float>): Flat matrix.
a (int): Node A.
b (int): Node B.
n (int): Matrix dimension.
weight (float): Edge weight.
meanAbsoluteConnectivity(matrix, n)
Average absolute pairwise edge weight.
Parameters:
matrix (array<float>): Symmetric adjacency/weight matrix.
n (int): Number of nodes.
Returns: Average absolute connectivity from 0 upward.
meanSignedConnectivity(matrix, n)
Average signed pairwise weight.
Parameters:
matrix (array<float>): Symmetric matrix.
n (int): Number of nodes.
Returns: Mean signed relationship.
density(matrix, n, threshold)
Proportion of possible edges whose absolute weight exceeds threshold.
Parameters:
matrix (array<float>): Symmetric weight matrix.
n (int): Number of nodes.
threshold (float): Absolute edge threshold.
Returns: Network density from 0 to 1.
fragmentation(matrix, n, threshold)
Network fragmentation as inverse threshold density.
Parameters:
matrix (array<float>): Symmetric weight matrix.
n (int): Number of nodes.
threshold (float): Edge threshold.
Returns: Fragmentation from 0 to 1.
nodeDegree(matrix, n, node, threshold)
Number of strong edges attached to a node.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
node (int): Node index.
threshold (float): Absolute edge threshold.
Returns: Degree count.
nodeStrength(matrix, n, node)
Sum of absolute edge weights attached to node.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Node strength.
strongestNode(matrix, n)
Node with greatest absolute network strength.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Strongest node index.
averageNodeStrength(matrix, n)
Average node strength.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Mean strength.
centralization(matrix, n)
Measures how much one node dominates the network.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Strength centralization approximately 0 to 1.
strengthEntropy(matrix, n)
Shannon entropy of node-strength distribution.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Normalized entropy from 0 to 1.
mstDistance(matrix, n)
Computes total Prim minimum-spanning-tree distance.
Similarity is converted to distance using 1 - abs(similarity).
Parameters:
matrix (array<float>): Similarity matrix.
n (int): Number of nodes.
Returns: Total MST distance.
mstCompactness(matrix, n)
Converts MST distance to compactness.
Parameters:
matrix (array<float>): Similarity matrix.
n (int): Number of nodes.
Returns: Network compactness from approximately 0 to 1.
setDirectedEdge(matrix, fromNode, toNode, n, weight)
Sets one directed edge.
Parameters:
matrix (array<float>): Flat directed adjacency matrix.
fromNode (int): Source node.
toNode (int): Destination node.
n (int): Number of nodes.
weight (float): Directed edge weight.
outStrength(matrix, n, node)
Sum of outgoing positive influence from a node.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Source node.
Returns: Total outbound influence.
inStrength(matrix, n, node)
Sum of incoming positive influence to a node.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Destination node.
Returns: Total inbound influence.
netInfluence(matrix, n, node)
Net directional leadership.
Positive means the node influences others more than it follows them.
Negative means the node behaves more like a follower.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Outbound minus inbound influence.
normalizedLeadership(matrix, n, node)
Normalized directional leadership score.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Score approximately from -1 to +1.
leadingNode(matrix, n)
Node with the largest net directional influence.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Node index.
followingNode(matrix, n)
Node with the greatest incoming influence.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Node index.
meanDirectedInfluence(matrix, n)
Average directed influence in the network.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Mean positive directed edge weight.
leadershipConcentration(matrix, n)
Concentration of outbound influence.
High values mean leadership is concentrated in fewer nodes.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Herfindahl-style concentration from 0 to 1.
connectedComponentsCount(matrix, n, threshold)
Counts connected components in an undirected threshold graph.
Parameters:
matrix (array<float>): Symmetric adjacency / similarity matrix.
n (int): Number of nodes.
threshold (float): Minimum absolute edge weight required to connect nodes.
Returns: Number of connected components.
localClusteringCoefficient(matrix, n, node, threshold)
Computes local clustering coefficient for one node.
Measures how interconnected the node's neighbors are.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
node (int): Node index.
threshold (float): Minimum absolute edge weight to define a connection.
Returns: Local clustering coefficient from 0 to 1.
averageClusteringCoefficient(matrix, n, threshold)
Computes mean clustering coefficient across all nodes.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
threshold (float): Minimum absolute edge weight.
Returns: Average clustering coefficient from 0 to 1.
similarityDistance(similarity)
Converts similarity to graph distance.
Higher similarity becomes shorter distance.
Parameters:
similarity (float): Edge similarity, typically from 0 to 1 in magnitude.
Returns: Distance from 0 to 1.
shortestPathDistance(matrix, n, source, target)
Dijkstra shortest-path distance between two nodes.
Uses distance = 1 - abs(similarity).
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
source (int): Start node.
target (int): End node.
Returns: Shortest path distance.
averagePathLength(matrix, n)
Average shortest-path distance across all node pairs.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
Returns: Mean shortest path distance.
eigenvectorCentrality(matrix, n, node, iterations)
Approximate eigenvector centrality for one node using power iteration.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
iterations (int): Number of power iterations.
Returns: Approximate normalized centrality from 0 to 1.
eigenvectorLeader(matrix, n, iterations)
Returns node with highest eigenvector centrality.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
iterations (int): Number of power iterations.
Returns: Node index.
nodeStrengthPercentile(matrix, n, node)
Cross-sectional percentile rank for a node's strength.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Percentile rank from 0 to 100.
nodeStrengthRank(matrix, n, node)
Returns the rank position of a node by strength.
Rank 1 means strongest.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: One-based rank.
networkCohesion(matrix, n, threshold)
Composite network cohesion score.
Combines connectivity, density and clustering coefficient.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
threshold (float): Edge threshold.
Returns: Composite cohesion from 0 to 1.
Open-source network analysis toolkit for Pine Script.
This library provides reusable graph algorithms, matrix utilities and network analytics for building advanced multi-asset indicators. Rather than treating markets as isolated charts, it enables developers to model relationships between assets as weighted networks and extract structural characteristics such as connectivity, centrality, clustering and influence.
Current Modules
• Matrix utilities
• Directed & undirected graphs
• Network analytics
• Node analytics
• Graph algorithms
• Experimental financial network tools
Example Applications
• Correlation networks
• Market leadership analysis
• Sector relationship maps
• Cross-asset dependency analysis
• Financial network research
Design Philosophy
This toolkit provides reusable quantitative building blocks rather than trading signals. Functions are intentionally modular so they can be combined into custom indicators and research projects.
Markets are networks. This toolkit provides the building blocks to analyze them as such.
--------------------------------------------------------------------
matrixIndex(row, col, n)
Converts row/column coordinates into a flat matrix index.
Parameters:
row (int): Row index.
col (int): Column index.
n (int): Matrix dimension.
Returns: Flat-array index.
clamp(x, lo, hi)
Clamp a float.
Parameters:
x (float): Value.
lo (float): Minimum.
hi (float): Maximum.
Returns: Clamped value.
newMatrix(n, initialValue)
Creates an n x n flat matrix initialized to a value.
Parameters:
n (int): Number of nodes.
initialValue (float): Initial cell value.
Returns: Flat float array.
setCell(matrix, row, col, n, value)
Sets a matrix cell.
Parameters:
matrix (array<float>): Flat matrix.
row (int): Row.
col (int): Column.
n (int): Matrix dimension.
value (float): New value.
getCell(matrix, row, col, n)
Gets a matrix cell.
Parameters:
matrix (array<float>): Flat matrix.
row (int): Row.
col (int): Column.
n (int): Matrix dimension.
Returns: Cell value.
setUndirectedEdge(matrix, a, b, n, weight)
Sets both directions of an undirected edge.
Parameters:
matrix (array<float>): Flat matrix.
a (int): Node A.
b (int): Node B.
n (int): Matrix dimension.
weight (float): Edge weight.
meanAbsoluteConnectivity(matrix, n)
Average absolute pairwise edge weight.
Parameters:
matrix (array<float>): Symmetric adjacency/weight matrix.
n (int): Number of nodes.
Returns: Average absolute connectivity from 0 upward.
meanSignedConnectivity(matrix, n)
Average signed pairwise weight.
Parameters:
matrix (array<float>): Symmetric matrix.
n (int): Number of nodes.
Returns: Mean signed relationship.
density(matrix, n, threshold)
Proportion of possible edges whose absolute weight exceeds threshold.
Parameters:
matrix (array<float>): Symmetric weight matrix.
n (int): Number of nodes.
threshold (float): Absolute edge threshold.
Returns: Network density from 0 to 1.
fragmentation(matrix, n, threshold)
Network fragmentation as inverse threshold density.
Parameters:
matrix (array<float>): Symmetric weight matrix.
n (int): Number of nodes.
threshold (float): Edge threshold.
Returns: Fragmentation from 0 to 1.
nodeDegree(matrix, n, node, threshold)
Number of strong edges attached to a node.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
node (int): Node index.
threshold (float): Absolute edge threshold.
Returns: Degree count.
nodeStrength(matrix, n, node)
Sum of absolute edge weights attached to node.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Node strength.
strongestNode(matrix, n)
Node with greatest absolute network strength.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Strongest node index.
averageNodeStrength(matrix, n)
Average node strength.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Mean strength.
centralization(matrix, n)
Measures how much one node dominates the network.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Strength centralization approximately 0 to 1.
strengthEntropy(matrix, n)
Shannon entropy of node-strength distribution.
Parameters:
matrix (array<float>): Weight matrix.
n (int): Number of nodes.
Returns: Normalized entropy from 0 to 1.
mstDistance(matrix, n)
Computes total Prim minimum-spanning-tree distance.
Similarity is converted to distance using 1 - abs(similarity).
Parameters:
matrix (array<float>): Similarity matrix.
n (int): Number of nodes.
Returns: Total MST distance.
mstCompactness(matrix, n)
Converts MST distance to compactness.
Parameters:
matrix (array<float>): Similarity matrix.
n (int): Number of nodes.
Returns: Network compactness from approximately 0 to 1.
setDirectedEdge(matrix, fromNode, toNode, n, weight)
Sets one directed edge.
Parameters:
matrix (array<float>): Flat directed adjacency matrix.
fromNode (int): Source node.
toNode (int): Destination node.
n (int): Number of nodes.
weight (float): Directed edge weight.
outStrength(matrix, n, node)
Sum of outgoing positive influence from a node.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Source node.
Returns: Total outbound influence.
inStrength(matrix, n, node)
Sum of incoming positive influence to a node.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Destination node.
Returns: Total inbound influence.
netInfluence(matrix, n, node)
Net directional leadership.
Positive means the node influences others more than it follows them.
Negative means the node behaves more like a follower.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Outbound minus inbound influence.
normalizedLeadership(matrix, n, node)
Normalized directional leadership score.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Score approximately from -1 to +1.
leadingNode(matrix, n)
Node with the largest net directional influence.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Node index.
followingNode(matrix, n)
Node with the greatest incoming influence.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Node index.
meanDirectedInfluence(matrix, n)
Average directed influence in the network.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Mean positive directed edge weight.
leadershipConcentration(matrix, n)
Concentration of outbound influence.
High values mean leadership is concentrated in fewer nodes.
Parameters:
matrix (array<float>): Directed matrix.
n (int): Number of nodes.
Returns: Herfindahl-style concentration from 0 to 1.
connectedComponentsCount(matrix, n, threshold)
Counts connected components in an undirected threshold graph.
Parameters:
matrix (array<float>): Symmetric adjacency / similarity matrix.
n (int): Number of nodes.
threshold (float): Minimum absolute edge weight required to connect nodes.
Returns: Number of connected components.
localClusteringCoefficient(matrix, n, node, threshold)
Computes local clustering coefficient for one node.
Measures how interconnected the node's neighbors are.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
node (int): Node index.
threshold (float): Minimum absolute edge weight to define a connection.
Returns: Local clustering coefficient from 0 to 1.
averageClusteringCoefficient(matrix, n, threshold)
Computes mean clustering coefficient across all nodes.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
threshold (float): Minimum absolute edge weight.
Returns: Average clustering coefficient from 0 to 1.
similarityDistance(similarity)
Converts similarity to graph distance.
Higher similarity becomes shorter distance.
Parameters:
similarity (float): Edge similarity, typically from 0 to 1 in magnitude.
Returns: Distance from 0 to 1.
shortestPathDistance(matrix, n, source, target)
Dijkstra shortest-path distance between two nodes.
Uses distance = 1 - abs(similarity).
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
source (int): Start node.
target (int): End node.
Returns: Shortest path distance.
averagePathLength(matrix, n)
Average shortest-path distance across all node pairs.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
Returns: Mean shortest path distance.
eigenvectorCentrality(matrix, n, node, iterations)
Approximate eigenvector centrality for one node using power iteration.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
iterations (int): Number of power iterations.
Returns: Approximate normalized centrality from 0 to 1.
eigenvectorLeader(matrix, n, iterations)
Returns node with highest eigenvector centrality.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
iterations (int): Number of power iterations.
Returns: Node index.
nodeStrengthPercentile(matrix, n, node)
Cross-sectional percentile rank for a node's strength.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: Percentile rank from 0 to 100.
nodeStrengthRank(matrix, n, node)
Returns the rank position of a node by strength.
Rank 1 means strongest.
Parameters:
matrix (array<float>): Weighted matrix.
n (int): Number of nodes.
node (int): Node index.
Returns: One-based rank.
networkCohesion(matrix, n, threshold)
Composite network cohesion score.
Combines connectivity, density and clustering coefficient.
Parameters:
matrix (array<float>): Symmetric similarity matrix.
n (int): Number of nodes.
threshold (float): Edge threshold.
Returns: Composite cohesion from 0 to 1.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
Machine-learning market structure & forecast levels. Publishing levels before the markets move. Educational only.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
Machine-learning market structure & forecast levels. Publishing levels before the markets move. Educational only.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.