Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Tactical Bond Strategy

Hi,

Below is my draft implementation of Tactical Bond Strategy described here: http://seekingalpha.com/article/2073493-tactical-bond-strategy-for-rising-treasury-rates

As you can see results are not even comparable with author's GAR 12.1% and STD 5.4%.
The reason of that difference is a way of processing dividends. Author developed this algo using ETFREply, which differs from Quantopian in this respect.

I've asked the author about that and here is his reply:

The MA is calculated not on the price of bond, but on the total return of bond (that includes the dividends).
Does Quantopian track total return or price only? This is a fundamental question that needs answering.

Reading here https://www.quantopian.com/help#ide-dividends I understood that calculation of MA in my algo uses only price of the bond etf not counting dividends. Is there any way to implement this kind of algo on Quantopian?

Regards,
Ed

15 responses

IIRC quantopian puts dividends into your cash. So you could write an algo that monitors your position + changes in cash, and recalculate your MA accordingly.

@Jason is correct, dividends are added to your cash portfolio. They're not automatically reinvested back into your portfolio.

His suggestion sounds like a plausible implementation - let us know how it goes!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

someone could give the example to handle the Jason point about dividends reinvested back to portfolio!

i'm planning on giving this a try later today (implement this as a strategy in my framework and post the results) though handling kids, so plans are always... adjustable :P

hi, i started looking into this, and I guess it's not possible, because you don't know which bond will give you the dividend. additionally you'd have to be invested to see the dividend. so you'd need some external data loaded through the fetcher to know dividend history. if someone has this info let me know and I can continue on this.

Hey Jason,

Found a way to load dividend history through an external source (Quandl was perfect for this). I couldn't find one for TBX's dividend history, but the other three were there.

Hope this helps!

-Seong

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Based on Quantopian says: "Currently, dividends are added as cash to your portfolio and are not automatically reinvested."
so as the following code in this strategy, about dividends that whether should be auto reinvest in next rebalancing_days?
Sorry, I am confused about why we still need to handle the dividends through external data source ?


        # buy new 'best' security  
        shares = (context.portfolio.cash + current_value)/data[best].price  

you can automatically reinvest by using the order_target_percent(1.0) (ie: rebalancing)

however this strategy needs to know the mavg including dividend gains, thus the external source used to determine dividends. I'm still working on the "robust mean revision" strategy but i'll take a look at this next

Seong, thanks for the idea. I've found that yahoo provides more accurate and up to date dividend data than quandl and implemented getting dividends using yahoo finance API.

PS: This might be interesting for Quantopian devs. While playing with this I've noticed strange behavior of record visualization in 'Build Algorithm' mode. Sometimes it showed wrong values. It works just fine in 'Full Backtest' mode though. I can provide more details if you're interested.

Why recently I run the strategy again, got following error message, it running well in before:

Something went wrong on our end. Sorry for the inconvenience. Please email us so we can help.
TypeError: int() argument must be a string or a number, not 'NoneType'
There was a runtime error on line 153.

The algorithm was trying to evaluated None to a sid object, and failing. Some time after this algorithm was posted, we changed the Type for sids from an int to a custom class for Zipline purposes.

In initialize(), I changed context.current from None to 0, fixing the TypeError.

Cheers,
Alisa

Anybody know how to replace batch transform given it's deprecated? Strategy looks interesting for large accounts.

sure, enjoy!

@ed

Thanks!

Hey guys can anyone help add futures to this, would be interesting to see how selecting the best performing bond futures would work as opposed to ETFs, and you can control margin / leverage much better than trading ETFs. and dealing with margin costs. I tried adding futures from the examples get an error about roll=calendar and equities.