Skip to content

Strange/Incorrect Strategy Results on a Simple Example #1294

@ts-kontakt

Description

@ts-kontakt

I tried to reproduce the results from the main page example using the unmodified SmaCross(Strategy), but I used the last 5 years of SPY data instead.

import yfinance as yf
ticker = yf.Ticker("SPY")
SPY = ticker.history(period="5y")

bt = Backtest(SPY, SmaCross, commission=.002,
exclusive_orders=True)
`

The result was Return [%]: -36.07, which seems impossible — I’ve checked in other backtesters and got very different results.

After inspecting stats._trades, I noticed that losses are being shown even when ExitPrice > EntryPrice.

Image

Where could the problem be?

backtesting 0.6.4
pandas  2.2.3
numpy 2.1.3
yfinance 0.2.65

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions