Back to Community
Trading strategy worthy of Q fund ?

Hi,
Could this pairs trading stat arb market neutral strategy be something worthy of Q fund ? Not particularly this algo, but this kind of long-short pairs strategy ?
I have a separate screener that I use for finding correlated stocks ( using also PearsonR = numpy.corrcoef(xA,yB)[-1,1] , but not only) that tend to mean reverse when a major price gap (%) appears between them or that tend to keep wideing the gap / momentum, after a initial gap in price.
The idea for the future is to integrate the research tool / screener in the algo and use also machine learning model in order to minimise risk and make better decisions.

Regards,
Adrian

Clone Algorithm
90
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: 560a3d99dd3bfa107c4c3b87
There was a runtime error.
12 responses

It has very low beta.
Is it worthy?
Some times yes, but mostly no.

Clone Algorithm
7
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: 560a6b3ca96a7e107949a7d9
There was a runtime error.

Hi Vadimir,
Thank you for your reply and making the backtest begin in 2007:). No disrespect. Maybe I was misunderstood, but I specified earlier that I was curious to know the point of view of the Q team & community regarding the type of strategy used, not if this particular algo was worthy of the fund. The algo for live trading is using more pairs of stocks and refreshing the stock list on a monthly basis. These are only some pairs that behaved well in the last 2 years, but nothing lasts forever.

For experimenting, condensed and sped up.

Clone Algorithm
56
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: 560cf767eda9a5108dde8618
There was a runtime error.

Groovy! Nice code optimization, garyha!:)

Thanks and hope it helps folks find improvements.
I need to make one correction, letting any be closed rather than just the first one:

def CloseSomePositions(context, data):  
    sales = 0  
    for p in context.pairs:  
        moves = MovesCalc(context, p)  
        offset = .003  
        if 1 - offset < moves < 1 + offset or moves == None:  
            order_target_value(p[0], 0)  
            order_target_value(p[1], 0)  
            sales = 1  
    if sales:  
        return 1  
    return 0  

Hi Adrian,

It's great to see you thinking about strategies for the fund. I cloned your post and ran it through the tearsheet to analyze the behavior. At first glance, the 2 year backtest from 2013-2015 looked interesting. However, as I ran longer backtests (5 yrs, 10 yrs) it appears the algo was overfit to the last 2 year period.

Attached is the tearsheet from the last 10 years. The returns could be improved, and the algo reaches a 50% drawdown. As you continue to test your ideas and create strategies, consider the bigger picture - Why does your algorithm perform well? What is the economic rationale? How does it perform in different market regimes? Feel free to share any other ideas for feedback! And if you find something you like, start paper trading it on Quantopian. Then you'll begin to collect out of sample data and track the returns.

Alisa

Loading notebook preview...
Notebook previews are currently unavailable.
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 Adrian,

Per your asking whether "this style of strategy is interesting to Q":
Yes, Definitely -- Everything you describe here sounds like a strong economic rationale to attempt to exploit with an algo. Specifically, as you mentioned: "correlated stocks (but not only) that tend to mean reverse when a major price gap (%) appears between them or that tend to keep wideing the gap / momentum, after a initial gap in price."

I think if you can extrapolate this idea into general logic for screening over a large universe of stocks, and possibly have, say, 10 - 20 pairs on at all times, the diversification benefit of many pairs should help mitigate risk in the overall portfolio.

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.

Alisa,
What do you mean by market "regimes"? Also, how do you determine it was "overfit" for the past 2 years?

Thanks for your replies! You can find a similar shared strategy of mine, that trades only ETFs, here: https://www.quantopian.com/posts/october-prize-number-1-algo-disqualified-worthy-of-the-q-fund . Please share your code or trading strategy ideas on what can be improved to make it mode robust.
Adrian

@Adam, I'd be happy to explain. For the fund, we'll see how the algorithm performs in different market conditions, not only the performance in recent years. We'd like to see a backtest over 10 years (not an exact number) to see more data. As you're writing the algo, test how it performs in 2008, 2011 and other turbulent times. If the algorithm does well in the last 2 years, but loses money when running a 5,7, or 10 year backtest then it's very likely it was overfit to the recent data.

To prevent from overfitting, I encourage you to first think about your economic rationale. Why does this strategy work? What would cause this strategy to stop working? Then begin coding the details and testing over various periods. If you find something promising, enter it in the contest or start paper trading to see out of sample data. The more data it accumulates the better; paper trading is the true test.

The tearsheet is a very powerful tool to visualize the data. You'll see the length of drawdown periods, cumulative return trends, position concentration, and more. We held a webinar showing how to read the tearsheet plots and interpret the data; if you missed it check out this video: https://www.youtube.com/watch?v=-VmZAlBWUko

I think if you can extrapolate this idea into general logic for screening over a large universe of stocks, and possibly have, say, 10 - 20 pairs on at all times, the diversification benefit of many pairs should help mitigate risk in the overall portfolio.

This is a pre-appeal to give us enough computation time in the upcoming Modeling API to do the above! :) EDIT: woo, five minutes, thanks!

@Adrian,
I think Simon and Justin are giving good advice and pointing you in the direction of the new Pipeline API. We built it with the express goal of making it easier to extend algorithms like this to a larger number of securities. I hope it proves useful!

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.