Skip to content

Instantly share code, notes, and snippets.

@McKlayne
Created June 18, 2021 04:25
Show Gist options
  • Save McKlayne/8395d60d7cfbdff08fe1e01694397db3 to your computer and use it in GitHub Desktop.
Save McKlayne/8395d60d7cfbdff08fe1e01694397db3 to your computer and use it in GitHub Desktop.
def arbitrage_scan(graph):
arb_checks = []
for c1, c2 in combinations(graph.nodes, 2):
# print('paths from ', c1, 'to ', c2)
for path in nx.all_simple_paths(graph, c1, c2):
path_weight1 = 1
for i in range(len(path) - 1):
# print(g[path[i]][path[i+1]]['weight'])
path_weight1 *= graph[path[i]][path[i+1]]['weight']
# print(f'weight for {path} is {path_weight1}')
path.reverse()
path_weight2 = 1
for i in range(len(path) - 1):
# print(g[path[i]][path[i+1]]['weight'])
path_weight2 *= graph[path[i]][path[i+1]]['weight']
# print(f'weight for {path} is {path_weight2}')
factor = path_weight1 * path_weight2
arb_checks.append((path, factor))
# print(f'path weights factor is: {factor}')
arb_checks = pd.DataFrame(arb_checks, columns=['Path', 'Result'])
return(arb_checks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment