Back to Community
Reinvest Dividends?

I'm traditionally a BogleHead-type investor, with a basket of index funds (stocks/bonds) and a target allocation, then re-balance occasionally when the allocation gets out of whack. I'm interested in investigating some other strategies, for at least some percentage of the allocation. And, even some strategies that would hold long enough where dividends would still come into play.

But on Quantopian, there doesn't seem to be a way to actually benchmark new algos to my current strategy. Over time, reinvested dividends are a nice bump to performance. I can't seem to find a way to accomplish this. Dividends are just converted to cash, and the equity price is decremented. If the API sent out some kind of signal of a dividend event, then I could possibly kludge something together to reinvest, but that doesn't seem to be present in the API.

So:
1. The documentation indicates that dividends are not relayed to algorithms as events that can be accessed by the API, but Quantopian will add that feature in the future. Any clue as to when this will happen?
2. Any way to accomplish dividend reinvesting on Quantopian?

Who else would find this feature useful?

11 responses

It's up to you (and your algorithm) what to do with the extra cash from dividends. In most cases, dividends will probably be reinvested naturally as a result of ones logic. Typically, one rebalances a portfolio minutely, daily, monthly, or whatever. Typically, at that time, one simply takes the total portfolio value (which includes any cash recently deposited from dividends) and divides it among a basket of equities. This effectively 'reinvests' any accrued dividends. You don't typically need to know that a dividend occurred, one just needs to look at available cash.

Attached is a very simple example of an algorithm which invests 100% of the portfolio value in AAPL. Notice the custom indicator showing 'shares'. It gets a bump every quarter or two because more shares are being bought (ie reinvested) with the deposited dividends.

It should also be noted that the benchmark set on a backtest assumes that dividends are reinvested into that benchmark. A benchmark of SPY, for example, will be higher than if one were to simply lookup the starting price and the ending price. The reason is that the benchmark ALSO includes the reinvested dividends. Just something to remember.

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5989f26c9258c453e80bee8d
There was a runtime error.

Thanks for your comments!

I re-balance after the portfolio has become some % out of balance, instead of re-balancing at predetermined times (quarterly, whatever). One of the first things I would like to look at is how the total returns change using that % as a variable, kind of mixing in a little momentum. So, I could possibly see scenarios where re-balancing may not even occur every year. Then, without some kind of way to directly reinvest dividends, I could end up with a small percentage of slippage just from a dividend cash pool.

I guess, nobody around here really considers such conservative portfolios, and that's why it is not a feature ... ?

You can add a daily schedule_function to re-balance only when the condition context.portfolio.cash > some value is met

Robert,

I too came to quantopian from a bogleheads mindset. So my first "algorithms" were designed to perform a robot investing service for me. This includes automatic rebalancing at triggers, tax loss harvesting, and checking daily for cash available. If there's cash available it calculates the amount to allocate to each asset in an attempt to try and track the starting target allocation. My hope was that I could reduce taxes if I am always "buying to rebalance."

I posted an algorithm on this thread that has that functionality: why use WealthFront when you can use Quantopian for free?

Seems like Bogleheads are winning the argument. Actively managed mutual funds and traditional hedge funds are losing investors on average, AFAIK. Think quant funds are holding up better and gaining assets in 2017 though. It's easy to duplicate many publicly available strategies on here without paying fees, think lots of financial companies would be in trouble if the public knew that. Quantopian also beats every other stock screening site in my opinion if you just use it for that. I originally found Quantopian when I was looking for a more powerful stock screener.

It seems like when the market dipped in 2015, lots of people sold actively managed mutual funds and switched to index funds. I tried automating fundamental metric screens and saw several that worked well between 2010 and 2015, but didn't do as well over the last two years. Has anyone else noticed this effect?

Thank you all for the comments!

""" You can add a daily schedule_function to re-balance only when the condition context.portfolio.cash > some value is met
""" Thanks! I'll check it out. My problem will still be which ETFs to assign cash that shows up in the account. Different ETFs will have different % payouts, and the basket of ETFs will also have different % allocations.

""" If there's cash available it calculates the amount to allocate to each asset in an attempt to try and track the starting target allocation. My hope was that I could reduce taxes if I am always "buying to rebalance." I posted an algorithm on this thread that has that functionality: why use WealthFront when you can use Quantopian for free?
""" Thanks! I'll check that out as well! I see you've ID'd the fundamental issue, in that you have to make some assumptions to "attempt" to track the original allocation.

""" Has anyone else noticed this effect?
""" I wish I could tell you. That's what I'm investigating Quantopian to try and find out. But, it looks like I'll just have to use Python and download the Yahoo data and write my simple little algos there, then come back to Quantopian later to compare if there exists any more sophisticated/complicated strategy trading individual stocks that can perform any better. It just seems a little silly that with all the power of Quantopian, I have to run off and create my own system to benchmark the simplest thing ...

use schedule_function to schedule a function that runs either monthly or quarterly that checks whether there's enough free cash accumulated to be worth reinvesting taking into account brokerage commission fees, and if so reinvests it in whatever security is dipping most below your desired target ratio for each holding. That's the least expensive way to do it and will help keep your portfolio balanced without having to rebalance it all the time.

""" use schedule_function to schedule a function that runs either monthly or quarterly that checks whether there's enough free cash accumulated to be worth reinvesting taking into account brokerage commission fees, and if so reinvests it in whatever security is dipping most below your desired target ratio for each holding. That's the least expensive way to do it and will help keep your portfolio balanced without having to rebalance it all the time.
""" Thanks for the suggestion. But, as outlined above, that doesn't cover my needs ...

I'm not sure I follow. Do you mean it's important to you that when ETF-X pays out a dividend that it gets its own and only its own dividend reinvested into itself? If that's what you need, I think you can pull dividend payout rates from the morningstar fundamentals datafeed, and then you can use those figures to divvy up the dividend cash reinvestments accordingly.

I don't know much about investing, but if you're going to rebalance anyways when your position ratios get out of whack, I don't see why you don't just divvy up the dividend pool in a way that helps keep those ratios close to your desired balance. To do it all you have to do is just multiply the current amount you have of that security by current price of that security and divide by portfolio value. Then compare those values to your original desired weights, and divvy the dividend up to the ones that are falling behind. I would think with investing that the less you rebalance, the less you'll pay in fees and taxes.

Robert,

I'd echo "Viridian Hawk's" question concerning the true need? If you just want to keep reinvesting dividends it can actually be beneficial to not use DRIP and to instead explicitly buy assets that have become under-represented. This will reduce taxes associated with being forced to sell assets that have grown too large relative to the target allocation. That code in my buy_longs() function I posted does that work for you: https://www.quantopian.com/posts/why-use-wealthfront-when-you-can-use-quantopian-as-the-robo-investor

If you need to benchmark your strategies to a simple asset allocation mix, one way to do is by building a super simple "algorithm" that invests in your target allocation, and load in the backtest results. I attached a notebook that does just this actually for a similar use case as to what you may have?

I've been working on a "dynamic efficient asset allocation" model that looks at the trailing 3 months to compute the most efficient combination of a large universe of passive index ETFs that stretch across many asset classes. Then it buys 12.5% to each asset (total of 8) each month, recomputes and rebalances the following month.

I wanted to see how effective my strategy was compared to some simple asset allocation models based off Vanguard's target date funds. So I created a few benchmarks that bought just that one asset (so it includes dividends), imported the performance of that algorithm, and compared different static allocations to the dynamic asset allocation model. The attached notebook goes through that comparison and also includes a full tear sheet of my strategy.

Let me know if you're interested in this model, I'm still trying to figure out the logistics of allowing others to use it without directly sharing the code - instead use fetcher() and make a publicly available CSV file. Some of the research I did to develop this strategy and universe of assets is detailed on my blog, with much more explanatory posts to come! https://engineeredportfolio.com/

Loading notebook preview...
Notebook previews are currently unavailable.

[Do you mean it's important to you that when ETF-X pays out a dividend that it gets its own and only its own dividend reinvested into itself?]

Yes.

[I think you can pull dividend payout rates from the morningstar fundamentals datafeed, and then you can use those figures to divvy up the dividend cash reinvestments accordingly.]

Possibly. There will only be about a half dozen ETFs to start with. But, at this point, I'm just starting with Python and the Yahoo data because I think it will be easier. Besides other unknowns with the Quantopian approach, I'd have to unroll then re-roll the the dividend price adjustments that they have made (I think).

[question concerning the true need?]

We're seeking alpha, right? But, alpha beyond what? If I can't be certain that I can accurately model (for backtest comparisons) what I'm doing today manually, than how can I use that as a benchmark that against some new algorithm? How could I justify the time/cost/effort of developing/implementing some more sophisticated algo, if I can't be certain of it's alpha against my benchmark?

Yes. I want to be able to precisely reinvest dividends directly back into their source ETFs. So, I'm not working with Quantopian right now. Maybe, some day in the future ...