B.F.M. UNITY
6.0.0
6.0.0
  • 🏁B.F.M. UNITY & U.R.S. & R.V.C.(On war with ShenNanPeng SEQUOIA HongShan & DaHongFei NEO Antshares)
  • 🩸B.F.M. R.V.C. 执行令
  • 沈南鹏,姚期智,去所里办点事吧
    • 沈南鹏,姚期智,去所里办点事吧
  • 🌟BF​M UNITY : A Brief Fantasy of Multiverse
  • 🫀古灵阁米达斯银行,请对洋人使用炼金术吧
  • B.F.M. R.V.C. | 位面简梦复仇做空风投
    • 中国加密项目名录
  • 中国金融机构名录
  • 红杉资本中国生态
  • 红杉资本全球生态
  • Antbot Antshares NEO 生态
  • 币安投资
  • 做市商名单
  • 华尔街RWA
  • 隐私代币
  • 人工智障
  • NFT
  • 跨链桥
  • 隐私代币
  • launchpad
  • BFM Lite | 位面简梦轻量版
    • 🌱新人必看(🔥)
    • 驾驶舱 (运行) (🔥)
      • 私钥云保管 🔑 ☁️
    • BFM Navigation
    • Main Bridge (Navigator)
  • BFM URS|位面简梦联合体储备系统(区块链加密货币宏观调控与货币政策机构)
    • 《位面简梦联合体(BFM-UNITY)储备系统(简称,位面简梦联储,位面联储,BFM-URS)法》
    • 😇历任行长(嵌套螺旋·符文占星·死灵炼金·原语谕示)
    • 🌟新资料片:寒武纪大过滤器与奥陶纪跃迁引擎启动!Smart Beta Neutral ——奎扎尔·科亚特尔计划
    • 战略资产配置——卓尔金历 🕙
      • 卓尔金升级1——拟合函数
      • 卓尔金升级2——误差分析
      • 卓尔金升级3——智能实验
      • 卓尔金升级4——图灵完备
      • 卓尔金升级5——动态图表
      • 卓尔金升级6——分类网络
      • 卓尔金升级7——引力透镜
      • 卓尔金升级8——货币政策
      • 卓尔金升级9——杠杆控制
      • 卓尔金升级A1——市占幂修
      • 卓尔金升级A2——参数读取
      • 卓尔金升级A3——止损熔断
      • 卓尔金升级A4——最大回撤
      • 卓尔金升级A5——波动率止损
      • 卓尔金升级A6——安全带
      • 卓尔金升级A7——在线图表
      • 卓尔金升级A8——商业化
      • 卓尔金升级A9——下拉菜单
      • 卓尔金升级A10——xlwings与Python连接
      • 卓尔金升级A11——KDE核密度估计
      • 卓尔金升级A12——杠杆风险控制,凯利准则
      • Plotly-制作数据仪表盘
      • 如何获取数字货币数据
      • 卓尔金升级A13——无监督学习优化
      • 卓尔金历法旧版页面
    • 战术资产配置——哈布历⌚️
      • 哈布历法1层次
      • 哈布历法2层次
      • 哈布历法3——仓位单元,量子调仓
      • 已废弃
    • 资产配置 🕙 ⌚️(🔥)
    • 时间校准研究
    • 如何碾碎中美政府国际金融部门
    • 如何碾碎中国人民银行
    • 如何碾碎中国三大政策性银行
    • 如何碾碎中国四大国有银行
    • 如何碾碎美联储
  • BFM Unity | 位面简梦联合体
    • 陈列室 (历程)
      • 虚拟资产编号名录
    • 新人指导
      • 【管理】宪章说明
      • 【选择】学区房 or 比特币
    • 【运营】加入组建
      • 群公告备份
    • 【组织】团队构成
  • BFM DA | 位面简梦数产
    • BFM Unity Reserve System
    • BFM Foundation
      • 比坊梦全球互联网 基金
      • 若尘的基金
    • BFM Trading Strategy♟
    • 影银行 (枢纽)
      • 自营业务
      • 个人业务
      • 企业业务
      • 创世业务
    • 会客厅 (赞助) 💰 & 资产公示
    • 财务
  • 🦣BFM Eco. | 位面简梦区块生态
    • BFM Eco. 🛰️
    • 链上数据分析
    • Cross-Chain Bridge
    • ETH - MainNet
      • Layer-2
        • MATIC - Polygon
        • Arbitrum
        • OP - Optimism
      • SHIB - Shiba Inu
    • BNB - BSC
    • AVAX - Avalanche
    • SOL - Solana
    • 其他公链
      • ADA - Cardano
      • ATOM - Cosmos
        • ☠️LUNA - Terra(已亡)
      • FTM - Fantom
      • Flow
      • Near
      • IPFS/FIL
    • BFM Meta
      • BFM DeFi 🦄️👻
      • BFM NFT🃏🧩
      • BFM Meme 🐶 💩
      • BFM GameFi 🎮👾
  • BFM DS|位面简梦数据支撑
    • Page 5
  • BFM OL|位面简梦障碍解除
    • SS/V2Ray 科学上网 ✈️
    • 华谷套件(Google Play商店)
    • 跨境收付
    • 离岸实体
    • Page 3
  • BFM BM|位面简梦区块基础
    • “在座的各位”总集篇
      • 讲师阵容
      • 介绍在座的各位
      • 问候在座的各位
      • 评价在座的各位
    • 《精通比特币》《精通以太坊》
    • 区块链安全
    • 区块链共识算法
    • 区块链分类与层次
    • 区块链要素理论
    • 区块链评级
    • 私钥与BIP44
    • 钱包
    • 交易所
    • 实体挖矿
    • 质押挖矿
    • 云算力挖矿
    • 桥接性钱包&加密银行卡
    • 礼品卡&场外交易
  • BFM Trad. | 位面简梦传统金融
    • FOReign EXchange
    • Cloud-POS,CNP 💳
    • Stock Investment
      • 选股
    • Fund Investment
      • 金融
      • 地产
      • 白酒
      • 医药
      • 互联网
      • 新能源
    • Gold investment
    • 国债逆回购
    • 可转债打新
    • Offshore Finance 🌍
    • Offshore Entity
    • International Phone Number
    • International Bank Card
    • 桥接性数字钱包
    • 礼品卡与场外交易
    • 草稿
  • BFM R-Ins. | 位面简梦科学研究院
    • 数学研究部
    • 算法科学部
      • 【算法】算法描述
        • 【研究】参考文献
        • BFM 维基百科翻译
        • 陵墓
    • 组织架构部
    • 项目流程部
      • 【软件】行动手册 🚩
      • 【软件】其他代码
      • 【软件】Graph algorithms and currency arbitrage
      • 【创新】未来发展
      • 【创新】DeFi - AMM
    • 项目架构部
      • 【架构】架构设计
        • 【规划】发展路线
        • 【规划】AMM下潜
        • 弯路
    • 量子科学部
      • LV5-研究院 (量子) ☢️
    • 数据智能部
      • Page
      • LV6-星魔方 (分类) 🎲
        • 数据分析-精炼
        • 数据分析-实验
        • 人工智能-实验
  • BFM D-Ins. | 位面简梦工程设计院
    • API接口
      • 币安API实验室🚩
    • 高并发
      • 新版本高并发实验室🚩
      • 旧版本高并发实验室
    • 开源项目部
      • 总览
      • Freqtrade 领域级重点实验室
      • HummingBot领域级重点实验室🚩
      • CCXT 领域级重点实验室🚩
        • CCXT文档
        • CCXT手册
      • AIOQuant 实验室
      • Peregrine 领域级重点实验室🚩
      • btrader实验室
      • js实验室1
      • 实验室2
      • py重点实验室
      • 以太坊部署实验室
    • 衍生产品部
    • 量化交易部
  • BFM Univ. | 位面简梦大学
    • 素白 · 密斯卡托尼克大学 🏫
    • Excel 教室
    • Power BI 教室
    • SPSS 教室
    • Python少儿编程教室 👩‍🏫
      • Python 办公自动化 OA
      • Python 金融 Finance
      • Python Project
    • 开发环境搭建教室 👨‍🏫 🚩
    • 文献与数据
    • 网络安全
    • MIS 系统开发
    • WEB 全栈开发
    • 企业战略分析
    • 基础财商教育
    • C#教室
    • 金融考试
    • 计算机考试
    • 发卡卡密交易平台
  • BFM LIB.|位面简梦图书馆
    • Page 1
    • Page 2
  • BFM Cult. | 位面简梦文化
    • 组织文化宣传
    • 设计
    • 组织文化
      • IT超度指南
      • 动漫
      • 漫画
      • 游戏
      • 01城密咒
      • 心理学
    • 风水玄学儒释道瑜伽占卜塔罗吸引力法则灵性修行
    • 【传媒】引起兴趣
  • 风控与合规
    • LICENCE:GNU GPL v3.0
  • 工具
    • AIGC
    • 文章论文生成器
    • 绘画生成器
    • AI 导航网站
    • 发现网站
    • B站视频下载 🎬 ⏬
  • 链接
    • 看板
    • 投资方法论
    • Github托管地址
    • 旧群文件
  • 位面简梦回收站
    • 三角套利程序众筹(中止)
  • 位面简梦后勤部
    • 餐厅
    • 药店
    • 服饰店
    • 数码店
    • 钱包店
    • 家具店
  • BFM AI|位面简梦智能
    • Page 4
Powered by GitBook
On this page
  • Graph data structure
  • Finding arbitrage
  • Bellman Ford Algorithm
  • 我们发现了一个术语叫 predecessor chain,这很重要。
  • 运行结果:
  1. BFM R-Ins. | 位面简梦科学研究院
  2. 项目流程部

【软件】行动手册 🚩

Previous项目流程部Next【软件】其他代码

恭喜有品位的你翻到了这一页!请仔细阅读!

你现在是在 BFM Unity Doc 最重要的一页 上!

How do we solve this?

Graph data structure

Weighted directed graphs can be represented as an adjacency matrix. For a graph with |V| X |V| vertices, an adjacency matrix is a |V| times |V| matrix of values, where the entry in row i & column j is a non-zero integer if and only if the edge (i, j) is in the graph. If you want to indicate an edge weight, put it in the row i, column j entry, and reserve a special value (perhaps None) to indicate an absent edge.

Finding arbitrage

Arbitrage opportunities arise when a cycle is determined such that the edge weights satisfy the following expression

w1 * w2 * w3 * … * wn > 1

The above constraint of finding the cycles is harder in graphs. Instead we must transform the edge weights of the graph such that the standard graph algorithms can be applied.

Let’s take the logarithm on both sides, such that

log(w1) + log(w2) + log(w3) + … + log(wn) > 0

Taking the negative log, this becomes

(-log(w1)) + (-log(w2)) + (-log(w3)) + … + (-log(wn)) < 0

Therefore we can conclude that if we can find a cycle of vertices such that the sum of their weights if negative, then we can conclude there exists an opportunity for currency arbitrage. Luckily, Bellman-Ford algorithm is a standard graph algorithm that can be used to easily detect negative weight cycles in O(|V*E|) time.

Bellman Ford Algorithm

Let G(V, E) be a graph with vertices, V, and edges, E.

Let w(x) denote the weight of vertex x.

Let w(i, j) denote the weight of the edge from source vertex i to destination vertex j.

Let p(j) denote the predecessor of vertex j.

The Bellman-Ford algorithm seeks to solve the single-source shortest path problem. It is used in situations where a source vertex is selected and the shortest paths to every other vertex in the graph need to be determined. After applying Bellman-Ford algorithm on a graph, each vertex maintains the weight of the shortest path from the source vertex to itself and the vertex which precedes it in the shortest path. In each iteration, all edges are relaxed if [w(i) + w(i, j) < w(j)] and the weight of each vertex is updated accordingly. After the i-th iteration, the algorithm finds all shortest paths consisting of at most i edges.

Once all shortest paths have been identified, the algorithm loops through all of the edges and looks for edges that can further decrease the value of the shortest path. If we can still relax the edges, then a negative weight cycle has been found since a path can have at most |V-1| edges.

Printing a negative weight cycle is done to show the arbitrage opportunity. We use the predecessor chain to print the cycle. Now that we have an edge which can be further relaxed, we have found the source & destination vertex of such an edge. Let’s`` ``start from the source vertex and go backwards until you see the source vertex again or any other vertex that predecessor chain has already shown us while printing the negative weighted cycle.

打印"负权环"以显示套利机会。
我们使用"前驱链"打印周期。
现在我们有了可以进一步放松的边缘,我们已经找到了该边缘的源顶点和目标顶点。 
让我们从源顶点开始,然后返回,
直到您再次看到源顶点或在打印"负权环"时"前驱链"已经向我们显示的任何其他顶点。

我们发现了一个术语叫 predecessor chain,这很重要。

from typing import Tuple, List
from math import log

rates = [
    [1, 0.23, 0.25, 16.43, 18.21, 4.94],
    [4.34, 1, 1.11, 71.40, 79.09, 21.44],
    [3.93, 0.90, 1, 64.52, 71.48, 19.37],
    [0.061, 0.014, 0.015, 1, 1.11, 0.30],
    [0.055, 0.013, 0.014, 0.90, 1, 0.27],
    [0.20, 0.047, 0.052, 3.33, 3.69, 1],
]

currencies = ('PLN', 'EUR', 'USD', 'RUB', 'INR', 'MXN')


def negate_logarithm_convertor(graph: Tuple[Tuple[float]]) -> List[List[float]]:
    ''' log of each rate in graph and negate it'''
    result = [[-log(edge) for edge in row] for row in graph]
    return result


def arbitrage(currency_tuple: tuple, rates_matrix: Tuple[Tuple[float, ...]]):
    ''' Calculates arbitrage situations and prints out the details of this calculations'''

    trans_graph = negate_logarithm_convertor(rates_matrix)

    # Pick any source vertex -- we can run Bellman-Ford from any vertex and get the right result

    source = 0
    n = len(trans_graph)
    min_dist = [float('inf')] * n

    pre = [-1] * n
    
    min_dist[source] = source

    # 'Relax edges |V-1| times'
    for _ in range(n-1):
        for source_curr in range(n):
            for dest_curr in range(n):
                if min_dist[dest_curr] > min_dist[source_curr] + trans_graph[source_curr][dest_curr]:
                    min_dist[dest_curr] = min_dist[source_curr] + trans_graph[source_curr][dest_curr]
                    pre[dest_curr] = source_curr

    # if we can still relax edges, then we have a negative cycle
    for source_curr in range(n):
        for dest_curr in range(n):
            if min_dist[dest_curr] > min_dist[source_curr] + trans_graph[source_curr][dest_curr]:
                # negative cycle exists, and use the predecessor chain to print the cycle
                print_cycle = [dest_curr, source_curr]
                # Start from the source and go backwards until you see the source vertex again or any vertex that already exists in print_cycle array
                while pre[source_curr] not in  print_cycle:
                    print_cycle.append(pre[source_curr])
                    source_curr = pre[source_curr]
                print_cycle.append(pre[source_curr])
                print("Arbitrage Opportunity: \n")
                print(" --> ".join([currencies[p] for p in print_cycle[::-1]]))


if __name__ == "__main__":
    arbitrage(currencies, rates)

# Time Complexity: O(N^3)
# Space Complexity: O(N^2)

运行结果:

现在你能回答以下这几个问题了吗? 1,BFM-find 和 BFM-detect 步骤有什么不同? 2,BFM-find 和 BFM-detect 的时间复杂度有什么不同? 3,BFM-find 里面的步骤涉及前驱链,什么是前驱链? 涉及前驱链的步骤到底做了什么? 4,为什么算法运行前要对汇率取-ln? 5,为什么汇率在取-ln之前要移动小数点再乘以几百? 6,BFM 算法基于图的邻接矩阵表示。什么是图的邻接矩阵表示?BFM 算法的步骤中如何使用图的邻接矩阵表示?

依然不能?回去,重看:

看完之后如果有帮助,请 **** 我。

https://gist.github.com/anilpai/fe4e11b5c59d8c02813900813396400b
https://gist.github.com/anilpai/dd00a9671c062390c848952eaddbbe1e
打赏
【算法】算法描述
LogoCurrency Arbitrage using Bellman Ford AlgorithmMedium
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.1981&rep=rep1&type=pdfciteseerx.ist.psu.edu
LogoNotebook on nbviewer
https://gist.githubusercontent.com/anilpai/dd00a9671c062390c848952eaddbbe1e/raw/0a65b53371470d7565988e3ec12c0d46f594895e/currency_arbitrage.py
我们终于迎来了黎明的曙光