PulseHub
PINE LIBRARY

NeuralMarketsNetworkToolkit

131
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.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.