IBKR Quant Blog



Quant

Quantopian - Idea to Algorithm: The Full Workflow Behind Developing a Quantitative Trading Strategy


Quantitative finance is, at the core, a process which is attempting to turn thought into money. In that light, it is no different from many other jobs, the main question is what path quants take in order to turn their thinking in cash. We’ll lay out some brief thoughts here on very high level workflows quants use, and link to supporting materials for those that would like to learn more.

Algorithm

Step 1: Hypothesize

"In general, we look for a new law by the following process: First we guess it. Then we – now don't laugh, that's really true. Then we compute the consequences of the guess to see what, if this is right, if this law that we guessed is right, to see what it would imply. And then we compare the computation results to nature, or we say compare to experiment or experience, compare it directly with observations to see if it works. If it disagrees with experiment, it's wrong. In that simple statement is the key to science. It doesn't make any difference how beautiful your guess is, it doesn't make any difference how smart you are, who made the guess, or what his name is. If it disagrees with experiment, it's wrong. That's all there is to it." - Richard Feynman

Quantitative finance applies the scientific method and automation to the process of predicting market behavior and using that knowledge to make money. The first step is always to come up with a model of the world. A good model allows you to predict what will happen in the future, a bad model gives false confidence. Knowing whether a model is good or bad often boils down to being brutally specific about what the model is and what assumptions are being made. For instance, a sloppy model would be “Stocks I read about in the newspaper are likely to go up tomorrow.”. This model is sloppy for many reasons. There is no definition of “read”, nor is the set of stocks you read about well defined. What if you tend to read only certain pages or sections? Why do you think they should ‘go up’ tomorrow? What is the mechanism underlying this behavior? In general, science forces us to be explicit about all of this, and by being explicit, methods of testing our models become obvious. For example, let’s break down the above model into a more scientific statement. "If a stock’s company name or ticker appears printed in the Wall Street Journal’s website today, its returns 5 days forward will have increased volatility." This is by no means a perfect hypothesis, but it unwraps the statement a bit, makes things more specific, and defines a framework for testing. We can start devising a program to count all mentions of a ticket in the WSJ. We can measure volatility via variance of the returns.

Implicitly, your hypothesis must come from your current model of how the world works. That is the reasoning underlying the hypothesis. As such, your work should be directed by where your understanding of the world breaks -- this is a core principle in the natural sciences. If your model disagrees with real observations in the real world it means that the model is wrong in some way. You should spend time examining how your model is wrong so that you can improve it, not examining where it’s right.
 

Step 2: Your Predictions Must be Correlated with Future Outcomes

Now that you have a model, you want to check if those predictions do indeed correlate with future returns. If they do, then that satisfies our first check. In industry, this is sometimes referred to as the ‘information coefficient’ of a model. What it means to correlated is also discussed in the linked lecture.

It’s important to note that this is not nearly enough. Your predictions have to survive the rest of the way through the process to realized returns. There are many steps ahead which can contort your predictions and lessen their correlations with future outcomes. This image is an example analysis from the linked lecture:
 

Forward
 

Step 3: Your Predictions Must Survive Portfolio Optimization

Let’s say you have a model which you believe fits well, and you’ve tested it rigorously and scientifically. That model will yield predictions of how the market should behave. Based on these predictions you can come up with a way to place trades that should take advantage of these predictions. This process is known as portfolio design, and is an often overlooked part of the workflow. Your portfolio should be designed to be risk aware/constrained, and try to take maximum advantage of your predictions. This lecture describes a canonical example of what quants refer to as a cross sectional portfolio.

One example I like to give is that of playing tennis against Federer. If you went up against Federer in a match, you’d want the match to last one serve (sample the process once). That way the volatility is maximized and you have the highest chance of beating him in a fluke. Meanwhile he wants a very long match with many events that sample both of your skills and decrease the volatility. As such you generally want to make as many independent predictions as possible if you truly think you can beat the market.

Basically, you want to take advantage of your predictions without taking on too much risk. As such you can imagine a function R(P) that for each portfolio P, tells you whether or not P takes on too much risk. You want to get your portfolio weights as close as possible to your predictions without violating R(P). This process is known as constrained optimization and is discussed at length here.

The portfolio weights that you end up with will not be exactly as you would have wanted due to these constraints. As such some of the correlation with future outcomes will be lost.
 

Step 4: Your Portfolio Weights Must Survive Portfolio Execution

Now that you have risk-constrained portfolio weights, we need to actually trade them. This is a very complicated process and the subject of a large amount of research. Your trades, if not placed carefully, can incur a large amount of trading costs. This will effectively be a discount on your final realized returns. Also, sometimes market conditions do not allow you to place precisely the trades you wanted. That means that the conversion of portfolio weights to real positions will contort your weights, and we now have a set of positions which are twice contorted from our original predictions.
 

Step 5: Realized Returns

Finally, only if your realized predictions have sufficient correlation with future returns will you make money. There have been two major steps which have contorted your original predictions at this point, so your original predictions must have been pretty good to survive this far. At this point you can still have issues converting your gains to cash as liquidating positions can be difficult for the same reasons trading is difficult.

Join Quantopian for a live comprehensive quantitative finance tutorial on March 7, 2018! Register for the webinar here: www.ibtweet.com/qtwm1

 

Resources to Learn More

What I’ve tried to convey here is a very high level understanding of what a quant workflow looks like, and some of the broad principles necessary to work in the space. I linked many lectures which convey much deeper information, and in general there is always room for improvement. Quantitative finance, like any science, is an iterative process in which your knowledge can always be more complete. If you’d like to learn more I encourage you to:

  • Read more of our lectures and get your hands dirty with code on our platform. You will understand many of these concepts more deeply when you have played around with real examples.
  • Go through our getting started tutorial to see what an institutional grade algorithm looks like from start to finish.
  • Go straight to our template quantitative finance algorithm .

 

Disclaimer:

The material in this post 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.

 

Learn more about Quantopian here: https://www.quantopian.com/

 

This article is from Quantopian and is being posted with Quantopian’s permission. The views expressed in this article are solely those of the author and/or Quantopian and IB is not endorsing or recommending any investment or trading discussed in the article. This material is for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IB to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


16651




Disclosures

We appreciate your feedback. If you have any questions or comments about IBKR Quant Blog please contact ibkrquant@ibkr.com.

The material (including articles and commentary) provided on IBKR Quant Blog is offered for informational purposes only. The posted material is NOT a recommendation by Interactive Brokers (IB) that you or your clients should contract for the services of or invest with any of the independent advisors or hedge funds or others who may post on IBKR Quant Blog or invest with any advisors or hedge funds. The advisors, hedge funds and other analysts who may post on IBKR Quant Blog are independent of IB and IB does not make any representations or warranties concerning the past or future performance of these advisors, hedge funds and others or the accuracy of the information they provide. Interactive Brokers does not conduct a "suitability review" to make sure the trading of any advisor or hedge fund or other party is suitable for you.

Securities or other financial instruments mentioned in the material posted are not suitable for all investors. The material posted does not take into account your particular investment objectives, financial situations or needs and is not intended as a recommendation to you of any particular securities, financial instruments or strategies. Before making any investment or trade, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice. Past performance is no guarantee of future results.

Any information provided by third parties has been obtained from sources believed to be reliable and accurate; however, IB does not warrant its accuracy and assumes no responsibility for any errors or omissions.

Any information posted by employees of IB or an affiliated company is based upon information that is believed to be reliable. However, neither IB nor its affiliates warrant its completeness, accuracy or adequacy. IB does not make any representations or warranties concerning the past or future performance of any financial instrument. By posting material on IB Quant Blog, IB is not representing that any particular financial instrument or trading strategy is appropriate for you.