peerchemist / finta

Common financial technical indicators implemented in Pandas.
GNU Lesser General Public License v3.0
2.13k stars 688 forks source link

Examples - backtest.py is not working #102

Open itpmngt opened 3 years ago

itpmngt commented 3 years ago

After a fresh install attempted to run examples/backtest.py - but:

The data file name has changed:

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

peerchemist commented 3 years ago

I'll take a look. Thanks for reporting.

itpmngt commented 3 years ago

I wonder if returning the name is what is breaking it - just a guess...

peerchemist commented 3 years ago

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.

scfox commented 3 years ago

Also interested in using finta with backtest. Any update / workaround?

cmann50 commented 3 years ago

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" )

image