Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
UVXY Volatility Decay

This is my first attempt at an algorithm on Quantopian. For the last few months I've been fiddling around and paper trading with the strategy of shorting UVXY whenever it spikes. Basic idea is to initiate a trailing stop short order whenever UVXY has a daily gain over a certain threshold, in this case 15%. Then just let it fall back, plus an additional few percent and cover.

I'm a software developer by trade, but have very little python experience, so please excuse any bad code.

3 responses

Welcome to Quantopian!

I'm sure you're a better software developer than me - I dabble in it, I'm not an expert. I'll need someone with more skills than me to help understand your code style.

What I can offer on this one is to look a bit more closely at how your algorithm's results pan out. I cloned your algorithm and added a custom record() function to track your leverage. In the beginning your leverage looks great, holding roughly at 1. But later on it points out is that your algo blew up financially in August of 2015. In the returns graph it looks like a little dip, but as your capital shrank your leverage went as higher than 250 and then as low as -1100. Boom!

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.

Hi Dan

Thanks for the response. I'm a little curious as to how the leverage property works. Given the calculation of leverage:

(long value + abs(short_value)) / context.portfolio.portfolio_value

and that whenever I take a position it is a 100% portfolio value short position, how would the leverage ever be a value different than 1?

Your portfolio logic targets a leverage of 1.0, and presumably it gets pretty close to the target when it rebalances. But as soon as the price of your positions change, then the leverage changes.

Looking at the gross leverage formula you quoted: Your algorithm is taking short positions. When the price of those positions goes up, the numerator goes up (the absolute value of the position is going up), and the denominator goes down (your short position lost value, and your cash was constant). At the point that your portfolio value goes negative, your leverage also goes negative.