Skip to content

what about multiple stocks/data inputs? #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JustinGuese opened this issue Jan 12, 2024 · 5 comments
Closed

what about multiple stocks/data inputs? #1105

JustinGuese opened this issue Jan 12, 2024 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@JustinGuese
Copy link

Hi, I like the direction where backtesting.py is going, but I am missing some backtrader functionality... Maybe the most important - currently only one stock is supported right?

Because if I have a strategy which uses 2 stocks, how would I deal with that? The backtrader way was using self.datas instead of data, which then becomes an array with all the stock datas, and then obviously the buy/sell functions would need a ticker parameter...
Or is there already a way to achieve this?

@JustinGuese
Copy link
Author

or is that functionality actually already there?

class _Data:
    """
    A data array accessor. Provides access to OHLCV "columns"
    as a standard `pd.DataFrame` would, except it's not a DataFrame
    and the returned "series" are _not_ `pd.Series` but `np.ndarray`
    for performance reasons.
    """
    def __init__(self, df: pd.DataFrame):
        self.__df = df
        self.__i = len(df)
        self.__pip: Optional[float] = None
        self.__cache: Dict[str, _Array] = {}
        self.__arrays: Dict[str, _Array] = {}
        self._update()

so would I pass something like
data = { "MSFT" : yf.download("MSFT"), "AAPL" : ...?

@PabloCanovas
Copy link

PabloCanovas commented Mar 24, 2024

Check out https://github.com/dodid/minitrade, a fork from this project which allows for multiasset backtesting.
Would love to have this functionality here under @kernc project though!

@BradKML
Copy link

BradKML commented May 29, 2024

Seconding this since it is getting more important to mess with pair trading. Also @PabloCanovas do you know of any equivalents for bt?

@s-kust
Copy link

s-kust commented Aug 14, 2024

You may want to take a look at https://github.com/s-kust/python-backtesting-template/

You can easily run backtests of your strategy for several (or several dozen) tickers simultaneously. The results of these backtests are combined and saved in the output.xlsx file.

@kernc kernc marked this as a duplicate of #1120 Feb 2, 2025
@kernc kernc marked this as a duplicate of #1095 Feb 2, 2025
@kernc
Copy link
Owner

kernc commented Feb 19, 2025

Duplicate of either #20 or #508.

@kernc kernc closed this as completed Feb 19, 2025
@kernc kernc added the duplicate This issue or pull request already exists label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants