Skip to content
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

Question - add columns to output of bt.run() #1033

Open
finithejernigan opened this issue Jul 30, 2023 · 2 comments
Open

Question - add columns to output of bt.run() #1033

finithejernigan opened this issue Jul 30, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@finithejernigan
Copy link
Sponsor

Hi,

Great package for backtesting! One question - is it possible to add additional columns to the output of the backtest (such as the indicator values) at the time of the trades? Alternatively, getting the indicator values output for each bar would also be helpful. I could hack it to do it but wondered if there was an easy way.

For example, adding additional columns for each trade with the value of each indicator?

image

Thanks so much for the great package,

@kernc
Copy link
Owner

kernc commented Aug 25, 2023

This is partly private API, but so far stable ... I think you can use (untested):

indicators = {ind.name: ind
              for ind in stats['_strategy']._indicators}

entry_bars = stats['_trades']['EntryBar']

indicators_df = pd.DataFrame(indicators).iloc[entry_bars]

We might want to include these values in the stats['_trades'] df by default ...

But what about exit_bars ... those values might be relevant for some too. 🤔

@kernc kernc added enhancement New feature or request good first issue Good for newcomers labels Aug 25, 2023
@lachyn21
Copy link

Hey I would like to work on this issue as well. I have written this feature on my forked repo for 1D array indicators to be included in the '_trades' dataframe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants