Finology 大数据金融

通过大数据以量化金融

在使用 git push 或 Github Desktop 等其他 Git 操作时,可能遇到以下错误:

1
2
3
4
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

这是由于默认的 SSH 22 端口被防火墙或网络策略限制,导致无法连接到 GitHub 的服务器。

为了避免这一问题,可以将连接改为 SSH 的 443 端口。以下是详细的解决方法,包括 Windows 和 Linux/Mac 的操作步骤。

Linux/Mac 下操作步骤

  1. 修改 SSH 配置文件
    SSH 的配置文件通常位于 ~/.ssh/config,如果文件不存在,可以手动创建一个:
1
touch ~/.ssh/config

打开文件并添加以下内容:

1
2
3
4
5
6
Host github.com
HostName ssh.github.com # **这是最重要的部分**
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
  1. 验证 SSH 配置
    配置完成后,通过以下命令测试连接是否正常:
1
ssh -T git@github.com

如果配置成功,应该看到类似以下输出:

1
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
  1. 配置 Git 使用新端口
    为确保 Git 使用新的 443 端口,可以运行以下命令:
1
git config --global url."ssh://git@ssh.github.com:443".insteadOf "ssh://git@github.com"

Windows 下操作步骤

  1. 找到 SSH 配置文件
    在 Windows 下,SSH 配置文件通常位于用户目录的 .ssh 文件夹中(例如:C:\Users<你的用户名>.ssh\config)。如果文件不存在,可以手动创建一个:

打开资源管理器并导航到 C:\Users<你的用户名>.ssh。
在 .ssh 文件夹下,新建一个文件,命名为 config(没有扩展名)。
2. 编辑 SSH 配置文件
用记事本或其他文本编辑器打开 config 文件,添加以下内容:

1
2
3
4
5
6
Host github.com
HostName ssh.github.com # **这是最重要的部分**
User git
Port 443
PreferredAuthentications publickey
IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa

注意:
IdentityFile 的路径需要根据你实际存储 SSH 密钥的位置调整,通常是 id_rsa 或 id_ed25519。

  1. 验证 SSH 配置
    打开命令提示符或 PowerShell,运行以下命令测试连接:
1
ssh -T git@github.com

如果配置正确,你应该看到以下输出:

1
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
  1. 配置 Git 使用新端口
    在命令提示符或 PowerShell 中运行以下命令:

最近这一步不配置,也可以正常使用 Github Desktop 了。

1
git config --global url."ssh://git@ssh.github.com:443".insteadOf "ssh://git@github.com"

总结
当 22 端口被占用或限制 时,通过将 SSH 连接切换到 443 端口,即可解决无法访问 GitHub 的问题。这种方法适用于任何操作系统,尤其是在防火墙限制较严的网络环境中。

之前一直是通过matplotlib来画图的,数据量大了以后,画图的速度较慢。

如果使用plotly,效率较高,主要是通过浏览器来渲染图片的,通过js效果,还可以随意放大缩小查看细节。

基本绘图

折线图

1
2
3
import plotly.express as px
fig1 = px.line(df["balance"])
fig1.show()

或者更简便一些

1
2
import plotly.express as px
px.line(df["balance"])

柱状图

1
px.bar(df["pnl"])

散点图

1
px.scatter(df["drawdown"])

对象方式绘图

创建绘图区域

1
2
3
4
5
6
7
8
9
10
import plotly.graph_objects as go
from plotly.subplots import make_subplots

# 创建绘图区域, 4行1列
fig = make_subplots(
rows=4,
cols=1,
subplot_titles=["累计盈亏", "净值回撤", "交易盈亏", "盈亏分布"],
vertical_spacing=0.06
)

创建四幅子图

Scatter取代了Line

1
2
3
4
5
6
7
8
9
10
# 绘制资金曲线

balance_line = go.Scatter(
x=df.index,
y=df["balance"],
mode="lines",
name="累计盈亏"
)

highlevel_scatter = go.Scatter(x=df.index, y=df["highlevel"], name="高水位")

这个有填充的效果

1
2
3
4
5
6
7
8
9
# 绘制回撤区域
drawdown_scatter = go.Scatter(
x=df.index,
y=df["drawdown"],
fillcolor="red",
fill='tozeroy',
mode="lines",
name="回撤"
)
1
2
# 绘制交易盈亏
pnl_bar = go.Bar(y=df["pnl"], name="交易盈亏")
1
2
# 绘制盈亏分布
pnl_histogram = go.Histogram(x=df["pnl"], nbinsx=100, name="盈亏分布")

把子图添加到画布上面

1
2
3
4
5
6
7
8
9
10
# 绘制图表
fig.add_trace(balance_line, row=1, col=1)
fig.add_trace(highlevel_scatter, row=1, col=1)
fig.add_trace(drawdown_scatter, row=2, col=1)
fig.add_trace(pnl_bar, row=3, col=1)
fig.add_trace(pnl_histogram, row=4, col=1)

fig.update_layout(height=1000, width=1000)

fig.show() # 可以省略

安装异常

1
2
Failed to build pyqlib
ERROR: Could not build wheels for pyqlib, which is required to install pyproject.toml-based projects
1
2
3
4
5
6
7
C:\Users\simon\AppData\Local\Temp\pip-build-env-uuivrj87\overlay\Lib\site-packages\Cython\Compiler\Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: D:\development\python\qlib\qlib\data\_libs\rolling.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyqlib

需要安装”Microsoft C++ Build Tools”。

需要更新安装 cython

1
pip install cython --upgrade
0%