The Wiener index W(G)—the sum of shortest-path distances over all unordered vertex pairs in a graph—can be a useful bridge between graph theory and quantitative trading when market structure is modeled as a network. In trading, we often represent relationships (between assets, regimes, indicators, or states) as a graph where vertices are “entities” (assets, features, Markov states) and edges encode similarity, influence, transition likelihood, or co-movement. In that setting, the Wiener index becomes a compact measure of global connectivity: low W(G) implies many pairs are “close” (information or influence travels quickly), while high W(G) implies a more “stretched” structure with longer average separations.
One direct application is regime monitoring. Suppose you construct a state graph from a Markov model of price action (like candlestick-pattern states), where edges are weighted by transition probabilities. When the market becomes highly directional, transitions may concentrate into a tighter subset of states; the graph effectively shrinks and the Wiener index can drop. In choppy or fragmented conditions, transitions may disperse across many states, increasing typical distances and thus raising
W(G). A strategy can use changes in a Wiener-like metric as a risk switch: trade aggressively when the system is “compact” (predictable transitions) and reduce exposure when it becomes “diffuse” (higher uncertainty).
The connection to hexagonal chains with segments of equal length comes from using well-studied graph families as interpretable templates. Hexagonal chains (common in chemical graph theory) have clear, tunable structure: straight segments and “kinks” change global distances, and therefore the Wiener index. In quantitative trading, a comparable idea is to model the “path” of market behavior as a chain of locally structured motifs (segments) of equal duration—e.g., repeating microstructure patterns, volatility regimes, or candlestick signatures. The way these segments connect (straight continuation vs turns/branch-like transitions) affects global reachability across the state space, analogous to how turning a hexagonal chain changes W(G). By calibrating a market-state graph to resemble different chain configurations, you can interpret W(G) as a structure score: lower Wiener index corresponds to smoother, more coherent regime progression; higher Wiener index suggests fragmented transitions and weaker predictability. This gives a graph-theoretic tool for feature engineering, regime detection, and systematic risk control.
// Gri04.cpp - Zorro64 Strategy DLL (C++), Wiener index demo
#include <zorro.h>
#include <stdio.h>
#include <stdlib.h>
#define N 6
#define INF 1000000
struct Graph {
int n;
int* d; // flat n*n matrix
};
static int Graph_pos(const Graph* g, int r, int c) {
return r*g->n + c;
}
static Graph* Graph_create(int n) {
Graph* g = (Graph*)malloc(sizeof(Graph));
if(!g) return 0;
g->n = n;
g->d = (int*)malloc(n*n*sizeof(int));
if(!g->d) { free(g); return 0; }
return g;
}
static void Graph_destroy(Graph* g) {
if(!g) return;
if(g->d) free(g->d);
free(g);
}
static void Graph_reset(Graph* g) {
for(int r=0; r<g->n; r++) {
for(int c=0; c<g->n; c++) {
g->d[Graph_pos(g,r,c)] = (r==c) ? 0 : INF;
}
}
}
static void Graph_link(Graph* g, int a, int b) {
g->d[Graph_pos(g,a,b)] = 1;
g->d[Graph_pos(g,b,a)] = 1;
}
static void Graph_buildBenzene(Graph* g) {
Graph_reset(g);
Graph_link(g,0,1);
Graph_link(g,1,2);
Graph_link(g,2,3);
Graph_link(g,3,4);
Graph_link(g,4,5);
Graph_link(g,5,0);
}
static void Graph_allPairsShortest(Graph* g) {
for(int k=0; k<g->n; k++) {
for(int i=0; i<g->n; i++) {
for(int j=0; j<g->n; j++) {
int ij = Graph_pos(g,i,j);
int ik = Graph_pos(g,i,k);
int kj = Graph_pos(g,k,j);
int cand = g->d[ik] + g->d[kj];
if(cand < g->d[ij]) g->d[ij] = cand;
}
}
}
}
static double Graph_wiener(const Graph* g) {
double W = 0.0;
for(int i=0; i<g->n; i++)
for(int j=i+1; j<g->n; j++)
W += (double)g->d[Graph_pos(g,i,j)];
return W;
}
static void Graph_dump(const Graph* g) {
printf("\nDistance matrix:");
for(int r=0; r<g->n; r++) {
printf("\n");
for(int c=0; c<g->n; c++)
printf("%2d ", g->d[Graph_pos(g,r,c)]);
}
}
static int doMain()
{
Graph* G = Graph_create(N);
if(!G) {
printf("\nOOM creating Graph");
return 1;
}
Graph_buildBenzene(G);
Graph_allPairsShortest(G);
double W = Graph_wiener(G);
Graph_dump(G);
printf("\n\nWiener index (benzene C6) = %.0f\n", W);
Graph_destroy(G);
return 0;
}
// Zorro entry point for DLL strategies
DLLFUNC void run()
{
// Only run once at start
if(is(INITRUN)) {
doMain();
quit("Done.");
}
}