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

Polygon Backtesting does not include dividends #402

Open
grzesir opened this issue Mar 17, 2024 · 8 comments
Open

Polygon Backtesting does not include dividends #402

grzesir opened this issue Mar 17, 2024 · 8 comments

Comments

@grzesir
Copy link
Contributor

grzesir commented Mar 17, 2024

When Backtesting using the polygon data provider, dividends are not included in the calculation.

Steps to replicate: run a Backtest using a symbol that only has dividends (eg. USFR). Notice that the Backtest does not include the dividends

@grzesir
Copy link
Contributor Author

grzesir commented Mar 17, 2024

@jimwhite I figure you would find this relevant since you're working on the polygon stuff now, and this can make a pretty big difference in backtests. It's on my list of things to do but I won't be able to get to it for a few months given my workload.

@jimwhite
Copy link
Collaborator

Yeah, I reported this. Wanted to let you know and folks should be aware. I have family stuff that will keep me busy for a while so I don't know when I'll get to it. If someone wants to work on this it should be very straightforward to extend what I did in #397 to options.

@grzesir
Copy link
Contributor Author

grzesir commented Mar 17, 2024

I believe @davidlatte and I had a discussion about how to implement this a few months ago. From what I remember it actually was not a lot of work, only a few files needed to be changed.

By the way @jimwhite let me know if you'd like free access to our pro plan for the work you have been putting into lumibot. We have an algorithm library that I think you would really appreciate and a very active community with regular events.

@jimwhite
Copy link
Collaborator

Oh, sorry I didn't actually read this issue, I thought you were cc'ing me on the issue I reported because of the timing.

I will take you up on the free Pro plan because I would like to chat with folks using lumibot. I have plans for many improvements to lumibot but I am preoccupied with family stuff atm. Hopefully I'll get back to this within the next few weeks.

@grzesir
Copy link
Contributor Author

grzesir commented Mar 21, 2024

@jimwhite sounds great. I agree, family first. I just had a baby 3 weeks ago myself, so I definitely understand. I wish you and your family all the best.

I'm happy to give you a complimentary pro plan. You will love our community, algorithm library and other resources. To set it up, I think it would be easiest if we jump on a call. You can book a time on my calendar here: https://calendly.com/lumi-rob/30min

@jimwhite
Copy link
Collaborator

jimwhite commented Apr 4, 2024

I'm looking in the code and I see various functions for getting dividends and strategy executor calling Strategy._update_cash_with_dividends but I don't find any data sources that actually provide dividend values, nor are there tests for dividends.

A few questions:

  1. Are there any backtesting configurations that track the portfolio value correctly wrt dividends? If so, which one?

  2. Are there any data sources that populate Bars with dividend values? It looked to me as though not only does the Polygon Pandas data source not get dividends but neither do Alpaca, Tradier, or IBKR. What I see in that code are stubs filling in zero for dividend values.

  3. Why is the portfolio cash value updated by this strategy executor logic? Shouldn't this be maintained by the broker, and in the case of backtesting, by backtesting/backtesting_broker.py? IOW, don't we want backtesting to follow the same logic as trading when interacting with the broker?

self.strategy._update_cash_with_dividends()

if not has_data_source or (has_data_source and self.broker.data_source.SOURCE != "PANDAS"):

@jimwhite
Copy link
Collaborator

jimwhite commented Apr 6, 2024

Answer to q1 from Discord: Dividend calculations should work for Yahoo backtesting.

A first step here would be to implement a test demonstrating that.

@grzesir
Copy link
Contributor Author

grzesir commented Apr 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants