finta
finta copied to clipboard
Examples - backtest.py is not working
After a fresh install attempted to run examples/backtest.py - but:
The data file name has changed:
- from
data_file = os.path.join("tests/data/bittrex:btc-usdt.csv")
- to
data_file = os.path.join("tests/data/bittrex_btc-usdt.csv")
(semi-colon into underscore)
After fixing that attempted to run but it stumbles with an error from backtesting
RuntimeError: Indicator "DEMA(df,10)" errored with exception: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The closest SO reference I found is: https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o
Seems there is some incompatibility for using with backtesting
I'll take a look. Thanks for reporting.
I wonder if returning the name
is what is breaking it - just a guess...
It seems upstream library (backtesting) had some breaking changes, that is what happened here. I'll try to study what was changed in upstream and adopt the example. If not, I'll find a new backtesting library.
Also interested in using finta with backtest. Any update / workaround?
I was able to get around the error and make the backtesting.py indicators work by passing in the exact columns finta expects and no other columns.
from backtesting import Backtest, Strategy
from finta import TA as TAF
def convert_finta(df: pd.DataFrame) -> pd.DataFrame:
df_finta = pd.DataFrame()
df_finta["open"] = df["open"]
df_finta["high"] = df["high"]
df_finta["low"] = df["low"]
df_finta["close"] = df["close"]
df_finta["volume"] = df["volume"]
return df_finta
self.fish = self.I(TAF.FISH, tools.convert_finta(ohlc),overlay=False, name="Fish" )