def get_cycles_by_value(self, edge_type: EdgeType, quote_type: QuoteType) -> Dict[float, List[str]]:
dg = self.get_network(NetworkType.price, edge_type, quote_type)
weights = get_edge_attributes(dg, 'weight')
cycle_vals = {}
for cycle in simple_cycles(dg):
# sort the currencies in cycle for long term sanity
best_curr = max(cycle, key=lambda x: Currency[x].value)
best_curr_ind = cycle.index(best_curr)
cycle = [cycle[best_curr_ind]] + cycle[(best_curr_ind + 1):] + cycle[:best_curr_ind]
cycle.append(cycle[0])
prodw = [float(weights[(cycle[i], cycle[i + 1])]) for i in range(len(cycle) - 1)]
prodw = prod(prodw)
cycle_vals[prodw] = cycle
return cycle_vals
评论列表
文章目录