New to VectorBT (vbt) here, but already loving it!
I am practising creating custom indicators using IndicatorFactory and from_talib(). However, I get an error that I can't find how to fix...
Here is the code:
import vectorbt as vbt
import numpy as np
import pandas as pd
import talib
from numba import njit
btc_price = vbt.YFData.download(symbols='BTC-GBP', period='100d', interval='1h').get("Close")
RSI = vbt.IndicatorFactory.from_talib('RSI')
@njit
def produce_signal(rsi, entry, exit):
trend = np.where(rsi > exit, -1, 0)
trend = np.where(rsi < entry, 1, trend)
return trend
def custom_indicator(close, rsi_window=14, entry=30, exit=70):
rsi = RSI.run(close, rsi_window).real.to_numpy()
return produce_signal(rsi, entry, exit)
ind = vbt.IndicatorFactory(
class_name="Combination",
short_name="comb",
input_names=["close"],
param_names=["rsi_window", "entry", "exit"],
output_names=["value"],
).from_apply_func(
custom_indicator,
rsi_window=14,
entry=30,
exit=70,
)
res = ind.run(btc_price,
rsi_window=np.arange(2, 40, step=2, dtype=int),
entry=np.arange(10, 40, step=2, dtype=int),
exit=np.arange(60, 90, step=2, dtype=int),
param_product = True
)
print(res.value)
entries = res.value == 1
exits = res.value == -1
pf = vbt.Portfolio.from_signals(btc_price,
entries,
exits,
freq='1h',
sl_stop=[0.02],
sl_trail=True,
)
print(pf.stats())
pf.plot().show()
And I get this error:
Traceback (most recent call last):
File "/Users/XXXXX/PycharmProjects/pythonProject/VectorBT test optimisation.py", line 41, in <module>
RSI = vbt.IndicatorFactory.from_talib('RSI')
File "/Users/XXXXX/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/vectorbt/indicators/factory.py", line 3441, in from_talib
info = abstract.Function(func_name)._Functioninfo
AttributeError: 'Function' object has no attribute '_Functioninfo'. Did you mean: '_Function__name'?
I checked on various forums, but can't find anyone else with this error. So probably related to my own code, but can't find where...
Thanks for your help!