如何在 VectorBT 中创建自定义进入/退出信号?

发布于 2025-01-13 07:35:54 字数 1037 浏览 0 评论 0原文

感谢您的阅读! 我正在尝试回测我在 Pinescrpt 中编写的策略,并且我努力创建我的入场条件。

这就是代码

import numpy as np
import pandas as pd
import vectorbt as vbt
from datetime import datetime
from binance.client import Client
symbols=['SOLUSDT', 'BNBUSDT']
price = 

vbt.BinanceData.download(symbols, 
start= '5 days ago UTC', 
end= 'Now UTC', 
interval='30m', missing_index='drop'
).get(['High', 'Low', 'Open', 'Close'])
high = price[0]
low = price[1]
open = price[2]
close = price[3]
stoch = vbt.STOCH.run(
high=high, 
low=low, 
close = close, 
k_window = 14 
)

,我想补充一点,

entries = abs(stoch.percent_k['SOLUSDT'] -
 stoch.percent_k['SOLUSDT']) > 50 # (mi intention with abs is to get the absolute value)

    exits = abs(stoch.percent_k['SOLUSDT'] - 
 stoch.percent_k['SOLUSDT']) < 5
    portfolio = vbt.Portfolio.from_signals(price[3], entries, exits, init_cash=10000)

我假装在一个交易品种中触发一个短期订单,并在第二个交易品种中同时触发一个长期订单与这些信号。

如果有人建议在哪里可以找到有关此特定包的教育资源(除了官方网站),我们也欢迎。我已经阅读了文档中的示例,但对于我的水平来说,它仍然有点过于复杂。

thanks for reading!
I'm trying to backtest a strategy that I wrote in Pinescrpt, and I struggle to create my entry conditions.

So this is the code

import numpy as np
import pandas as pd
import vectorbt as vbt
from datetime import datetime
from binance.client import Client
symbols=['SOLUSDT', 'BNBUSDT']
price = 

vbt.BinanceData.download(symbols, 
start= '5 days ago UTC', 
end= 'Now UTC', 
interval='30m', missing_index='drop'
).get(['High', 'Low', 'Open', 'Close'])
high = price[0]
low = price[1]
open = price[2]
close = price[3]
stoch = vbt.STOCH.run(
high=high, 
low=low, 
close = close, 
k_window = 14 
)

And I want to add

entries = abs(stoch.percent_k['SOLUSDT'] -
 stoch.percent_k['SOLUSDT']) > 50 # (mi intention with abs is to get the absolute value)

    exits = abs(stoch.percent_k['SOLUSDT'] - 
 stoch.percent_k['SOLUSDT']) < 5
    portfolio = vbt.Portfolio.from_signals(price[3], entries, exits, init_cash=10000)

I pretend to trigger a short order in a symbol and a long order in the second simultaneously with those signals.

And if anyone has a recommendation about where to find educational resources about this particular package (besides the official web) is welcome. I have read the examples in the doc, but it still fills a bit too complex for my level.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文