network.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:trading_package 作者: abrahamchaibi 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号