Skip to content

A few questions on the backtest output plot #676

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
bravegag opened this issue Jul 1, 2022 · 3 comments
Closed

A few questions on the backtest output plot #676

bravegag opened this issue Jul 1, 2022 · 3 comments
Labels
question Not a bug, but a FAQ entry

Comments

@bravegag
Copy link

bravegag commented Jul 1, 2022

I have been looking into this project, and everything looks great. I have a few questions on the main plot visualization example https://kernc.github.io/backtesting.py/#example, which would appreciate if someone could help.

  1. Why is the top part of the plot called equity? and what is that data there? If it is a wealth index or cumulative returns of the Strategy I would just call it Strategy instead of Equity and also add a WI or so to know it is a wealth index of the strategy. Equity is confusing as there are many asset classes which could be implemented e.g. FX, FI, Crypto.
  2. The second plot top bottom, is it showing the trades? what is the meaning of the size of the triangle? the abs of the return or the amount invested? how do I see the size of the trade?
  3. The third plot top bottom, I assume is showing the raw dataset, the legend states that the vertical bars are the trades but I see vertical bars everywhere and they don't match the color or trade direction looking at the plot on top so it is a bit confusing. It would also be nice to give a title to that plot and not leave it to the imagination.
  4. I would suggest being able to see a fifth plot with the buy / sell signal alone, if possible and x-axis aligned to the other plots. This will help figure out trade entry issues or any possible signal to implementation lags.
@eervin123
Copy link
Contributor

eervin123 commented Jul 1, 2022

This project has a Discussions section you should probably throw this over there for the community to answer. https://github.com/kernc/backtesting.py/discussions


plot output

Regarding
1.) The term equity is often used to reflect the amount of capital you have in a given strategy. Particularly when using margin and shorting. I can see how it might be confusing at first glance when thinking about it from an asset class perspective "equity, fixed Income, alternatives, commodities, etc.", but it is very common with backtesting programming libraries.

2.) The second plot top to bottom is indeed showing the trades. The size of the triangle represents the relative size of the trade. For example, in the beginning you might only be trading 100 shares of Google, but assuming your strategy is profitable, towards the end of the backtest, you are hopefully trading thousands of shares of Google, and the size of the triangle will reflect that. The direction of the triangle is whether it was a Long (arrow up) or a short trade (arrow down), the color of the triangle is the profitability of the trade (red = loss, green = profit).

3.) Third plot is the Price series, your indicators from your strategy, and the trades. The trades are the "tractor beams" as I call them. See the picture below. I have circled a profitable (green) trade. Red represents a losing trade. Regarding Title, I am pretty sure you can customize the charts. I know I have previously fiddled with the legend to suit my needs. Check out the documentation to see what all you can do without fiddling with the source code. https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Backtest.plot

image

4.) You can do this with the trades dataframe that is produced as a result of running the backtest.
image
those last three _strategy _equity_curve and _trades all contain useful information for you to plot or analyze or save for later analysis.

@kernc
Copy link
Owner

kernc commented Jul 1, 2022

Adding to @eervin123's great answer:

  1. equity = cash + assets
  2. Additionally, as the y-axis label indicates, the triangle's y-offset denotes its return.

@kernc kernc closed this as completed Jul 1, 2022
@kernc kernc added the question Not a bug, but a FAQ entry label Jul 1, 2022
@bravegag
Copy link
Author

Thanks a lot both! it makes a lot of sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

3 participants