Quant Investing

I am beginning this thread, at the request of Donald, as a globally moderated thread. The reason is to share my learning on various quantitative (quant) systems with VP members and also share actionable ideas from some of my quant systems from time to time.

Members can ask questions or make comments which will be visible only after it is approved. This is opposite to what the normal flow is in other regular threads in VP. The objective is to keep the thread clutter-free and to-the-point.

AN INTRODUCTION TO QUANT

Any method of investing (or trading) which is solely dependent on numerical methods is a quantitative system.

There are many misconceptions and a general ignorance of quant systems. For most people, it means high-frequency trading as was made famous by Michael Lewis’ book Flash Boys.

However, even the Nifty, Sensex or any index, for that matter, is a quant system. So, people who are proponents of passive index-based investing are actually (unknowingly) investing in a quant-based system.

Another famous example of a quant system is Joel Greenblatt’s Magic Formula which uses return on capital and earnings yield.

What is NOT a quant system?

Another misconception with people is that they equate quant systems with systems based on technical analysis. While there is a lot of statistical and mathematical analysis used in technicals, its bedrock is that of chart reading. That is a subjective study and is NOT quantifiable. One tech analyst’s cup & handle pattern may differ from another’s.

However, indicators like moving averages, oscillators are extensively used in quant systems.

Advantages of using quant systems

  • The biggest advantage is that it completely eliminates human behavioral biases, which according to me, is the most critical factor in investing success.
  • Strategies can be backtested and stress-tested to check how they had or would have performed under different circumstances. For example, you can see how your strategy would have performed in the crash of 2008 or Mar 2020.
  • You can pick and choose the type and timeframe of systems you invest in. There are short term (1-day) or long term ( multi-year) systems that are operational. Personally, I tend to use monthly and quarterly reset systems.
  • You are ideally NOT investing in 1-2 stocks but a portfolio of stocks, usually between 5 to 50, so you are reasonably well diversified.
  • All systems have exit plans, so the usually the worst-case scenario is well covered.
  • Once a system is developed, it requires very little time to implement and execute it. For a monthly strategy, it hardly takes 10 mins a month to do the actual transactions, assuming that it is also not automated.
  • A combination of multiple strategies of different styles works extremely well across market cycles.

Disadvantages of using quant systems

  • You do not know the details about all the stocks thrown up by the system, so the conviction is NOT on individual stocks.

How can YOU use a quant system?

  • Style diversification. Every investor is comfortable in a particular style of investing. Some like value investing, some momentum, some GARP, etc. You can pick a contrasting quant style and deploy a part of your portfolio so that your portfolio has what I call “style-diversification”.
    For example, I primarily like compounders & GARP stocks and am not very good with momentum or short term trades. So, I invest in a couple of quant strategies which are pure growth and momentum-based.
  • Works very well as an idea generation method. Further study / due diligence can be done on stocks selected by a quant system.
57 Likes

I personally use and run 4-5 strategies on a monthly / quarterly basis with one strategy predominant among those. I call that the Q30 strategy. I will not be sharing / discussing it here for regulatory reasons as I also have a quant advisory service with that strategy.

However, I will share the results of some other strategies.

The following is a techno-funda quant strategy I have named TF10. (I name all my strategies for easy reference).

Backtest results for TF10.
Periodicity - Quarterly reset. i.e. Buy and hold for 3 months.
Universe - Nifty 500
Test Period - 2007 - 2020
CAGR = 21.9% (without brokerage & slippage)
Max DD (drawdowns) - 17.9%

TF10 >> Top 10 Stocks from 1-Jun-2020

  1. India Cements
  2. Escorts
  3. Cipla
  4. Cadila Healthcare
  5. Indostar Capital Finance
  6. Coromandel International
  7. Vaibhav Global
  8. Aurobindo Pharma
  9. Alembic Pharma
  10. Multi Commodity Exchange
14 Likes

The next one is a mean-reversion strategy named Flipper.

Backtest results for TF10.
Periodicity - Quarterly reset. i.e. Buy and hold for 3 months.
Universe - Nifty 500
Test Period - 2007 - 2020
CAGR = 45.5% (without brokerage & slippage)
Max DD (drawdowns) - 63.3%

Flipper >> Top 10 Stocks from 1-Jun-2020

  1. Adani Green
  2. India Cements
  3. Escorts
  4. Dr Reddys
  5. Dixon Tech
  6. Bayer
  7. Granules
  8. Cipla
  9. FDC
  10. Cadila

This strategy is a high reward - high risk one. The max DD is very high which makes this strategy practically very difficult to implement. So, if it has to be used, one needs to use stop losses either at individual stock level or at the portfolio level or both (more on how to use stop losses can be found on my blog… will put it here for reference in a subsequent thread as linking to a blog is not allowed by VP).

11 Likes

Using Stop Loss in Investing

Should you have a stop loss if you are an investor? That is the question I have have been trying to answer for myself. I have been dabbling with various quant systems and obviously stop losses is a part of the thought process in any trading system.

Stop loss is a simple yet extremely powerful concept. It can protect you from major catastrophes that can completely erode your portfolio to protect a large part of gains made (when used as protective stops). It is part of the “money management” or “allocation” strategy followed in trading systems.

Money management is perhaps one of the most important things that I learnt while studying quant systems. And I find that not knowing it was stupid. Every investor MUST know about money management and adapt it to their own investing style. More on money management later.

There are only 2 types of stocks - trending and mean-reverting.

Trending stocks are those that follow a trend (it keeps going up or down over time - since we are usually all long-only investors I will talk about price rise trends). The rising price trend is usually but not necessarily due to improving fundamentals like earnings. Examples are many like Pidilite, Asian Paints, HDFC Bank etc.

Mean reverting stocks are those where the prices keep oscillating about a mean position (which also tends to slant upwards but at a much lower slope). Practically, most stocks belong to this category.

Stop loss should be used differently for the 2 types of stock.

If you have bought a trending stock, a stop loss is a must. It helps in preventing massive losses in case your thesis is wrong or there is a major market correction. It also prevents in locking in gains by the use of a trailing stop loss. (A trailing stop loss is one where you keep raising the stop price as the price of the stock keeps going up). If you have bought a trending stock at 100, and it falls to 80, the trend is possibly broken and you need to reevaluate your thesis and hence get out of the position. Exactly, the same situation with a trailing stop. It gets hit when the trend reverses.

On the other hand, if you have bought a mean-reversion stock, where you are expecting a change in fortune, then a stop loss initially is a STUPID idea. This is precisely why Warren Buffett or any other value investor do not use stop losses. Value investing, by definition, is a mean-reversion strategy, where you are expecting the price of the stock to revert back to its mean “value”. In a mean-reverting stock, let’s say you have bought it at 100 and expect it to revert to its intrinsic value of 150 in some time period. Now if the price falls to 80, ideally your philosophy should drive you to buy more at the lower price since you are now getting a better bargain and potentially more profits when the stock does mean revert.

How to set stops?

There are many ways stops can be put. Unfortunately, there is no correct way. Different people use different methods based on their trading style, capital at risk, investment horizon etc. Some basic strategies are:

  1. Using a fixed percentage stop loss (say 10% or 20% from buy price)
  2. Based on technical chart patterns (support levels, breakout levels, gaps etc)
  3. Based on statistical indicators (Fibonacci levels, moving averages, ATR etc)
  4. Volatility based
  5. PE-based (exit at x PE)
  6. Growth level based (if earnings growth falls below x% for 2 quarters in a row)
  7. So on and so forth…

Stop levels need to be in line with your capital and time horizon. If you keep a 5% stop loss and your a long term investor, you will get stopped out 99% of the time. You need to understand the volatility of the particular stock and make sure you do not get stopped out under normal market gyrations. However, if you are a day trader and are trying to make 1% return from the stock, even a 1% stop loss may be way too high.

Portfolio level stop loss vs individual stock stop loss

The next problem is whether to have an individual stop loss for a stock or a stop at the portfolio level. Again, like in nearly everything in life, the answer is “it depends”. Individual stop-loss, in my opinion, should be more liberal, if you are a long term investor. Something like 30-40% or even 50%. But if you combine it with a market level stop loss, then it could get triggered at a lower combined level.
For example, say you have bought a stock at 100 and you have a 30% stop loss on it. You expect the stock to double in the next 4-5 years. When you bought it, the Nifty was at 11,000. Now, the markets start tanking and Nifty falls to 8800, which is a 20% loss on the index. Now, if you have a complex stop loss which takes both individual stock price and the index price, then you could actually be stopped out of the position even without the individual stock not having lost 30%.

Single or Graded Stops

You can use either single stop loss to get out of your entire position or graded stop loss to get out gradually. Example: Sell 50% at a 20% stop, and then 10% every 5% fall.

Does a stop loss reduce drawdowns or lock-in losses? What is the impact on profits?

This is the most crucial question that very few people actually ask. I have been dabbling with this for a while now. Stop loss in my studies, nearly always, reduces returns. Obviously, there are many assumptions that have gone in the data studying primary amongst which is that you are not a very poor stock picker and you make reasonable profits when the markets are doing well. If you are not sure if you are a good stock picker, then use a stop. It is like a helmet. It will save your life if you crash.
However, if you are a good stock picker and have a good track record, 9 / 10 times your stop will get hit and the stock will recover ground post that. Only in very very rare cases like a DHFL or a Yes Bank would it protect you immensely. But then again, if you were a good stock picker you would have gotten out of those even without a stop loss.

Is a stop-loss strategy a behavioural strategy more than a money management strategy?
A stop loss is mostly a behavioural strategy. It is also a strategy for those who do not know the stocks they are buying so in a way it is ignorance insurance. It protects you from the unknown and from making stupid catastrophic mistakes.

BOTTOM LINE: Since the world is dynamic and you can never know everything about everything, having an exit strategy is important for all your investments. Stop losses are part of that exit strategy.

45 Likes

Hi Basumallick

I have just join VP 2 days back. My investment strategy and portfolio is mainly compounders type. “Gautam’s Foundation Portfolio”. What I understand from your Quant Investing thread that we buy TF10 hold for three months with strict stoploss and exit. Then after 3 should we buy same stocks again or new set of stocks.
Please correct me and treat as layman.
I can spare some funds and try out this strategy.
Thanks in anticipation
regards

1 Like

@Gjsj Please do NOT trade this basket unless you understand what you are doing. You can follow these baskets of stocks and see how it works out. These are basic strategies and needs to be deployed along with money management and stop loss rules in place. If not, you can do serious damage to your portfolio.

You can use these as investment / trading ideas to work on individually.

6 Likes

Thanks for starting a thread on quant investing.
I have been trying to automate a part of my portfolio through such methods.

How does one do backtests of custom strategies on Indian Stock market data.
Are there any paid or free platforms which allow us do define and run such tests using accounting ratios , multifactor screens etc.

1 Like

The unavailability of data is perhaps the biggest problem for us in India.

Firstly, we have only good reliable fundamental data for less than 20 years. Price data also is very unclean and difficult to obtain.

I use Metastock data feed for price, volume data and various screen scrapping methods to get fundamental data. It’s not ideal, but I make do with what is possible.

If you can code then I would suggest setting the environment up yourself. Python and pandas is really good. I started with excel but its difficult for complex conditions and code is difficult to optimise.

People who have access to bloomberg terminal can use it to test. If one is using only technical data, then AmiBroker is really good as it allows testing at portfolio level.

12 Likes

Great. Thanks for sharing. I do have a few questions and would be glad if you could take a look.

I am trying to make a virtual trading bot for the NIFTY500. It’s relatively easier to do for something like NASDAQ as historical daily data is easily available.

Wondering if you use a particular source for historical data?

Ideally, I would like the bot to backtest strategies on something like Quantopian. Wondering how you go about backtesting ? Perhaps you could also add benchmark returns to the Backtest?

Finally, how do you weigh each stock? Is this based on Portfolio Optimization, or is intuitive?

I understand this is your strategy and it is completely fine if you don’t want to answer.

Thanks

1 Like

I already addressed the data question above. In the long term, building your own database is the best option if you are serious about this. Quantopian is really good. I tried it to test if some of my concepts was even worth pursuing.

I have found that keeping things as simple as possible is the best strategy. So, unless there is any major rationale to deviate, I always go with a equi-weighted portfolio.

8 Likes

Can you illustrate with an example on any strategy? For example the techno funda strategy , what exactly is it? How do we apply it? Or at least you can give references to read more about them

Current Price Rs > 100Day SMA Rs AND RSI > 40 AND ADX > 30 AND Market Capitalization in Cr > 1000 AND Net Profit 5Yr Growth % > 15

It is a simple system which I created in my initial systems. It uses current price above a long term moving average, net profit growth rate for last 5 yrs and a couple of momentum indicators like RSI and ADX. The idea is to find companies with good average growth in profits and which are in an uptrend.

I pick the top 10 stocks and equi-weight it in a portfolio. Since, fundamental data does not change frequently, its run on a quarterly basis.

14 Likes

Basu Sir, firstly let me appreciate for the excellent thread. Short, to the point and action oriented write up.Therefore, I book marked your thread link in my portfolio thread. I believe, with contribution from fellow experienced members this is going to add great value.

I have had reasonably satisfying success with my approx 1.5 year of investment journey, although nothing to brag about. Broadly, my portfolio did better than MFs & Indices, although overall returns were not great considering the Covid impact on market.

Sir, I too like quant approach not because I understand its nuances but because it eliminates human biases. Systematic approach is what I like, but in reality have never been able to execute.

I am sharing my broad level plan with the below filters and methods in place.

  1. Look at Top price gainers- past 3 to 6 months
  2. Select top 20 but quality, trending and compounder category- HDFC Bank, Asian Paints type
  3. Buy & Hold for 3 months to 6 months or more
  4. Trailing stop loss of 20% fall from high
  5. Exit 1: When TSL is breached
  6. Exit 2 : When I find a better top gainer ( replacement)
  7. Index level/Portfolio level Trailing Stop Loss of 15%

What do you think from your experience are likely Pros/Cons of the method. And on academic side, would you classify this as quant or quality or momentum startegy.

1 Like

This part is not clear to me. How are you determining quality? If it is subjective and based on your judgement then it is not a pure quant strategy.

What you are following a momentum based strategy.

Another thing to remember is it is less important to know if a strategy is quant or not but as long as it works for you, it is good. Also, since you have a system in place, my bet is you will have a better result than most buy-hold-and-pray investors, if you are able to stick to it with discipline.

9 Likes

Hi Basumallick,

Many thanks to you for starting this thread and to Donald for suggesting to start the thread. It is a very different spin on stock investing/trading. I was not aware about the existence of such a methodology. I have a few questions regarding the fundamentals and usage.

  1. Are these algorithms available as open source which an interested person can use after tweaking as per his/her needs? Are there collection of strategies easily accessible? Or is it something that users have to develop on their own from scratch? The latter sounds ominous as the user may not be able to make sense of the output if even a small thing goes (unknowingly) wrong.
  2. Does this method works purely with price variations and related information or takes into account the fundamental indicators? For the former, unbiased outcome can be understood, but for the latter the user will be inserting the bias based on what are the important variables to be considered. For instance, in the method by Joel Greenblatt, Earnings yield and ROCE are key variables, which may not be for others.
  3. Is there any upper limit on how much variables to play with? Otherwise, achieving convergence may be tricky.
  4. I understand what is generally meant by stop-loss in trading, but is this used over here as an exit criterion to get out of an executing loop?

It will be very very interesting to see how this thread develops going ahead to learn more.

1 Like

Not much is available as open source. You can get a lot of technical trading systems on different forums, but purely quant factor based investing is not that easily available. Plus, in India quant investing is at a nascent stage with very few people knowing much (and most people having massive misconceptions) about it. However, there are a few quant focused advisories (some I know are mystic wealth, capital mind, quantamental). If you are interested you need to develop your own. There are a lot of learning material available and I will also try to put up interesting articles or strategies I come across on this thread.
DISCLOSURE: I run quantamental.

As I said, quant is just using numbers. You can use numbers for technical, fundamental, technofunda… pretty much whatever you want. For example, the legendary Walter Schloss, Warren Buffett’s friend and a student of Ben Graham, was a pure fundamental quant (although at that time the term quant was not in vogue). Even Ben Graham to a large part was a pure quant who advocated buying a collection of stocks based on low P/B.

Again, for both technical and fundamental, outcomes will vary based on the parameters and values used. So, it is not right to think that only fundamental will vary based on the parameters chosen.

Ultimately, quant strategy is a reflection of the strategist, just like any other investing style. If you ask Buffett to quantify he will do it in a certain way which is consistent with his worldview and investing style. Similarly, if you ask a day trader, he will do it in a completely different way. And both can be successful.

No. There is no upper or lower limit. But one needs to be careful of making a strategy too complex. Because then we run the risk of what is called data or pattern fitting. The broader the strategy is, the better it will work over long periods. That is why, simple moving averages work well even though they have been in vogue now for nearly 100 years.

Stop loss can be used to either get out of a losing position or a profitable one by not giving back a large part of the gains.

5 Likes

Hi @basumallick few queries from my side
a. How is the drawdown calculated? Is it per trade- that means out of 10 trades you have done 3 have given negative returns then it will be considered or it will be for the entire period?
b.Are you using semi-automated methodology for executing the trades that means system is giving you hints and you execute the trades or system is selecting and executing by itself?

For a quant portfolio, you ALWAYS look at a portfolio view and not a stock specific view. So, a drawdown is the maximum fall that the overall portfolio has in any specific period of time.

Let me introduce a couple of new terms:
1. Win-Loss Ratio: What you are referring to is win-loss ratio. That is, the number of winning trades divided by the number of losing trades. Ex: If 6 stocks are profitable and 4 loss-making in a portfolio of 10, then the win-loss ratio is 6/4=1.5. The absolute win ratio is wins / total number of trades - 6/10 = 60%

2. Risk- Reward Ratio: The money made versus the money lost, on average, per trade.
Ex: In a winning trade, a person makes 100 Rs and and loses Rs 50 on a losing one, then the risk-reward ratio is 100/50 = 2

3. Expectancy Ratio: This tells us what is the profit expected vs loss made in any strategy. Ex:
(Win % x Average Win Size) – (Loss % x Average Loss Size) = (0.6 x 100) - (0.4 x 50) = 40

This means, on average you expect this strategy’s trades to return to be Rs 40 per transaction. This is important for two reasons: First, you know that you have a positive return. Second, you now have a number you can compare to other candidate systems to make decisions about which ones you employ.

b) I just use the model to tell me what trades to buy or sell. Since, trade frequency is relatively low (like once a month), it does not create a problem for me.

For fully automated trading, I think Zerodha does provide APIs for this purpose. But for me, its not required.

8 Likes

Hi Basu,

Can you share a little more on the Back Testing part?

For example with quant based system we got 10 stocks (above some moving averages plus fundamental criteria like MCAP, DEBT etc). After 3 months we have 11 stocks (some different and some same as the previous). Now if you go back in time the same must have happened in the past (say 10 years), how do you get the technical and fundamental data which kept on changing along with the invested list changing and in what universe of stocks (Is it NIFTY 500?). I know we can back test on an Index but in the quant based system we dont have index for our system.

All form of investing seems to be coming under Quants in some way or other :slight_smile: (Value, Growth etc.)

Regards,
Ravi

Any investing or trading has 4 main components. This is irrespective of whether you are a day trader or a Buffettesque investor.

  1. Universe selection
  2. Stock selection
  3. Allocation
  4. Holding period / selling

Nearly all investors spend practically all their time and effort on step 2. In fact, the entire focus of a forum like VP is step 2, i.e. identifying the right stock.

Now let us understand how a basic quant system works. You have some criteria for selecting a set of stocks. They could be anything - fundamental, technical or a combination of the two.

That takes care of part 1 of stock selection. Then you have to decide allocation. Here also you can device different strategies. You can buy based on market-cap or free-float (these are what stock index makers use) or others like buying where price has gone up the highest in the last x period or the opposite. What I am implying is the allocation can also be dynamic and based on how you view the world. I use a simple equal-weighted allocation.

So, now you have a list of stocks and you have decided how much to buy each of them. The next thing is how long will you hold. Now here is where most technical trading systems strategies differ from quant portfolio strategies. Technical strategies would look at individual stocks and decide on an exit based on some technical parameter or target price. A pf quant strategy would typically have a time based holding period, unless it is stopped out. So, you can decide to hold for a month, a quarter and year or maybe even a day.

So, say you are running a quarterly strategy. You will get 10 stocks on say 1st Jan. Then on 1st Apr you will get another list of 10 stocks. You sell everything in the 1st Jan basket and buy everything in 1st Apr basket. If there are repetitions, then you can decide to transact only the difference amount. But conceptually, you sell all of the 1st Jan stocks and buy all of the 1st Apr stocks.

When you are backtesting, what you are trying to do is to go back in time to check how your portfolio would have performed had you been running it at that time. In addition, you can try various simulations (Monte Carlo type) where you stress test your system and see how it performs. How you get the data is a very challenging part in India and you make do with what you have. You may not get the best and cleanest result but you are still better off than playing blind and not knowing anything at all about how you are investing.

8 Likes