Finology 大数据金融

通过大数据以量化金融

之前文章下面一直使用的是Valine评论框,Valine已经不开源了,所以也遭到了开源社区的抛弃。

使用新版本的 Hexo NexT,哪怕是安装了主题作者提供的 Valine 插件,也不能正常使用。

不过有非常完美的替代方案,使用 Waline,数据结构都是相同的,迁移起来非常方便。

在 Hexo NexT 主题下配置 Waline 评论系统和邮件提醒的方法:

一、安装插件

1
npm install @waline/hexo-next

并在 _config.next.yml 配置文件里面配置参数

这下面有些参数可能是没有用的,这个自行研究一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
waline:
enable: true # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version.
appid: # your leancloud application appid
appkey: # your leancloud application appkey
serverURL: # https://my-waline-beryl.vercel.app/ Vercel 地址
avatar: mm # gravatar style
meta: [nick, mail, link] # Custom comment header
pageSize: 10 # pagination size
visitor: true # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
comment_count: true # If false, comment count will only be displayed in post page, not in home page
recordIP: false # Whether to record the commenter IP
enableQQ: false # Whether to enable the Nickname box to automatically get QQ Nickname and QQ Avatar
requiredFields: [] # Set required fields: [nick] | [nick, mail]
libUrl: # Waline.min.js file URL in CDN (or local path)

二、注册leanCloud

推荐注册海外版,使用国内版的话,在域名上会有限制,需要备案之类的。

三、Vercel部署

根据官网的安装方法,一步步操作就行

https://waline.js.org/guide/get-started/

在部署的时候,如果需要配置邮件提醒,还需要添加如下环境变量。

在使用 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() # 可以省略
0%