finta icon indicating copy to clipboard operation
finta copied to clipboard

Examples - backtest.py is not working

Open itpmngt opened this issue 4 years ago • 5 comments

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

itpmngt avatar Nov 17 '20 12:11 itpmngt

I'll take a look. Thanks for reporting.

peerchemist avatar Nov 17 '20 13:11 peerchemist

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

itpmngt avatar Nov 18 '20 11:11 itpmngt

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.

peerchemist avatar Nov 18 '20 12:11 peerchemist

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

scfox avatar May 19 '21 00:05 scfox

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

cmann50 avatar Jun 05 '21 21:06 cmann50