Using Sharpe Ratio in Trading

The Sharpe Ratio is a measure of risk adjusted return. Although the formula was originally developed to compare the performance of mutual funds over time periods greater than 1 year, there is nothing to prevent its use in any other time frame, include intraday analysis.

There are several uses of Sharpe Ratio that have been underutilized by traders:

  1. Scanning. Compare large numbers of individual stocks and find those which have the largest risk adjusted gain over much smaller time frames, including intraday analysis.
  2. Longs vs. Shorts. Compare the relative merits of potential shorts and longs on a risk adjusted basis.
  3. To Trade or Not. Determine if the price action supports making a trade at all, compared to lower risk investment alternatives.
Formula for Advancing Stocks

Traditionally, Sharpe Ratio analysis has been applied to stocks that are appreciating.

Sharpe Ratio = Annualized Avg Return (%)  -  Risk Free Return (e.g. CD Rate)
Annualized Std Dev of Returns

Note that for the Sharpe Ratio to be positive, the Annualized Average Return must be greater than the Risk Free Return. If it is used to assess potential investment in a stock, this means that the stock does not begin to become an attractive investment until its annualized average return exceeds what an investor could earn in a risk free investment, such as a CD.

In many cases, the growth rate of stocks is so far in excess of the CD interest rate that the Risk Free Return factor does not contribute significantly to the value of the Sharpe Ratio. When screening for high growth rate stocks, the Risk Free Return could be considered to be zero since its contribution to the final value of Sharpe Ratio is so small. However, to be of greatest utility in evaluating all investments, including those that have relative low rates of return but high safety, the Risk Free Return component is important.

Formula for Declining Stocks

Can we use Sharpe Ratio to evaluate potential shorts? The answer is yes, provided we modify the formula slightly:

Sharpe Ratio = Annualized Avg Return (%)  +  Risk Free Return (e.g. CD Rate)
Annualized Std Dev of Returns

If the Annualized Avg Return is negative, as it will be for stocks that are declining, then to find the stocks with the greatest risk adjusted decline, the Risk Free Return should be added rather than subtracted.

The means that for a stock to be attractive as a short, it must have an annualized average return that is more negative than the Risk Free Return of a CD is positive.

In the Sharpe Ratio code provided below, the Annualized Avg Return is calculated and depending on whether this is a positive or negative number the sign of the Risk Free Return is adjusted to be either a plus or a minus. Therefore, unlike the standard Sharpe Ratio formula, the Sharpe Ratio functions provided here can be used either to identify attractive longs or shorts without further modification.

For example, in screening for potential longs and shorts, a stock with a Sharpe Ratio of +3 and a declining stock with a Sharpe Ratio of -3 represent equal opportunities to make money. We now have a way of screening the market for potential longs and shorts AND having a reasonable way to compare the relative merits of potential longs and shorts on a risk-adjusted basis! The most attractive trading opportunities in both directions will be revealed by the same scan if the results are sorted in order by absolute Sharpe Ratio value!

When scanning the market for potential longs and shorts, the Sharpe Ratio indicator is inserted into Radarscreen containing a large number of potential stocks to evaluate. The Sharpe Ratio and the absolute Sharpe Ratio values are displayed in separate columns. The Radarscreen is sorted in decreasing order sorted by absolute Sharpe Ratio. The best opportunities, both longs and shorts, will roll up to the top of the list. This list may be updated frequently during the day using the auto sort feature of Radarscreen. The best long opportunities will be those stocks with the highest positive Sharpe Ratio, and the best short opportunities will be those stocks with the largest negative Sharpe Ratio.

Example of Scanning for Long and Shorts with Sharpe Ratio

A Radarscreen Sharpe Ratio indicator used for stock scanning is shown below. In this case, the NASDAQ stocks are being scanned for the best and worst risk-adjusted performance during the most recent 40 days ending 1/22/10. The time period may be adjusted by the user and can be chosen to span a period of weeks, days or even intra-day minutes.

Best Performing Stocks - NASDAQ 100 - 40 Days

Worst Performing Stocks - NASDAQ 100 - 40 Days

Fig. 1. Radarscreen indicator scanning for best and worst risk-adjusted performance

These two screen captures are from the same Radarscreen indicator processing all 100 NASDAQ stocks simultaneously. The screen capture includes only the top 20 rows. The worst performing stocks (right chart) are found by simply sorting the Sharpe Ratio column (SR1) in ascending rather than descending order.

The Annualized Rate of Return (AnnRR) is also displayed. In this example, the best stocks are moving either up or down at an annualized rate of return in excess of 100%. This illustrates why, when using the Sharpe Ratio function as a stock scanner, the Risk Free Rate of Return component in the formula, typically represented by the CD interest rate (2-5%) is often makes a relatively insignificant contribution to the Sharpe Ratio value.

Other columns being displayed above are:

  • SegLen: The number of bars in one segment. A segment is the length of the period used to calculate the gains in the Sharpe Ratio formula. In this case, the daily gains are being calculated so the length = 1 on a daily chart.
  • Segs: The number of segments to be analyzed


Fig. 2. Scan Results - Charts with best risk-adjusted performance

Fig. 3. Scan Results - Charts with worst risk-adjusted performance

Why is "risk-adjusted" performance so important?

The Sharpe Ratio finds stocks with trends that are strong and have "low risk", that is, trends that are well-behaved and less volatile. This is important for two reasons:

  1. Well-behaved trends have a greater probability of continuing. If you want to trade a trend, improving the likelihood the trend will extend will improve profits.
  2. A low-volatility trend can be followed with a tighter trailing stop. This means, that when the trend finishes and you are stopped out by the trailing stop, you will lose or "give back" less of your profit. It does not matter if you are going long or short. In both cases, if the trend is strong AND well-behaved, you retain higher profits from your trade if you trail a tighter stop while the trend is continuing.

Advantages of Sharpe Ratio as a Screening Tool

  1. Reduces number of potential charts to review, as stocks with unacceptable volatility are automatically filtered out.
  2. Works independently of market timing. Finds well-behaved long and short opportunities regardless of market direction.
  3. This single indicator can be used for identifying BOTH potential Longs and Shorts.
  4. Compares profit potential of Longs vs. Shorts in addition to Longs vs. Longs
  5. The modified Sharpe Ratio formula automatically eliminates declining stocks as potential Shorts if their price is less than $5 since stocks in this price range cannot be shorted.
  6. Adjusts performance for risk.
  7. Automatically filters out large gap moves as a result of "news" events, since these events represent high volatility which is penalized in the SR formula. Abrupt gap moves do not present much opportunity for traders as the move is over by the time it is recognized and is unlikely to continue in the near future. In contrast, a steady, well-behaved price movement presents greater opportunities for profit by riding the trend.

Sharpe Ratio Indicator for Charts

Indicator Sharpe Ratio Q for Charts

Fig 4. Sharpe Ratio Indicator for Charts

The chart above shows a running Sharpe Ratio function using a length of 20 (yellow) and a length of 50 (green). This indicator can plot up to 4 Sharpe Ratios of different lengths simultaneously to show price risk-adjusted price performance in several different time frames.

The most recent 20 and 50 bars show a Sharpe Ratio value of -9.34 and -6.02, respectively.

This stock, PBI was identified by scanning the S&P 500 stocks for the worst performing stocks in the last 20 and 50 days, respectively. The scan is shown below:

Sharpe Ratio Indicator for Radarscreen Scanning the S&P500 stocks

Fig 5. Sharpe Ratio scan of the S&P500 stocks, sorted to identify the worst performing stocks

To identify the worst performing stocks in the S&P500 in the most recent 50 days, the Sharpe Ratio indicator for Radarscreen is being sorted in descending order by absolute Sharpe Ratio, using a length of 50 days.

Sharpe Ratios for the most recent 20 and 50 days are simultaneously displayed. However, the column being sorted is the 50 day absolute Sharpe Ratio value, identifying stock PBI as the worst risk-adjusted performer during the most recent 50 days. The Sharpe Ratio values for the 20 and 50 days analysis are -6.26 and -5.04, respectively.

The best risk-adjusted performance stocks are those shown with positive Sharpe Ratio numbers (green).

RadarScreen Indicator Input Parameters
Sharpe Ratio Indicator for Radarscreen input parameters

Price: The reference value used to calculate Sharpe Ratio. Using AvgPrice or TypicalPrice instead of Close will result in a somewhat smoother Sharpe Ratio function.

SegLength: The number of bars used for each segment of time analyzed for rate of return. On a daily chart, if daily rate of return analysis is desired, then SegLength would be 1. If weekly analysis was desired on a daily chart, then SegLength would be 5 (5 bars on a daily chart = 1 week).

SegsPerYear: The number of segments in a year. On a daily chart, SegsPerYear would be 251 (trading days in a year) if SegLength was 1. If each segment was a week's worth of data (SegLength = 5 on a daily chart), then SegsPerYear would be 52, since there are 52 weeks in a year.

Segments1, Segments2: The number of segments used to perform the calculation of Sharpe Ratio. Two separate Sharpe Ratios can be calculated simultaneously in this RS indicator.

Offset1, Offset2: The number of bars to the left of the current bar that the calculation is based upon. For example, if Offset1 = 1, then Sharpe Ratio 1 is the Sharpe Ratio as of the bar prior to the current bar.

If you noted that the market pulled back two weeks ago, and wanted to scan for the best performing stocks just prior to the pull-back, you could use Offset1 = 10 (2 weeks is 10 trading days).

CalcSeconds: The minimum number of seconds between calculations. This is used to prevent frequent recalculation of Sharpe Ratio with each tick of actively trading stocks. It is useful whenever offsets are set to zero (default). This means the current bar is being used as part of the calculation. It is useful to know how the Sharpe Ratio is changing as the price of the current bar changes. However, it is not necessary to perform the re-calculation with each tick of data. This setting reduces the frequency of re-calculation to a more reasonable value. In this case, the default of 60 indicates the Sharpe Ratio calculation will not be performed more often than once each minute.

RiskFreeReturn: This is the rate of return of a completely safe investment expressed in annual percent. Typically the current CD (certificate of deposit) rate is used.

SegColor: The color used to display the length of the Sharpe Ratio calculations. Choosing a unique color, such as cyan, provides some visual separation from the two independent calculations displayed.

OffsetColor, OffsetWarningColor, CalcColor: These are not yet implemented in the current version, but will be used in more sophisticated versions allowing up to 4 Sharpe Ratio time frames to be simultaneously calculated, and custom functions of all 4 results to be output.

What type of custom functions? Let's say you want to scan for the best performing stocks up until the market turned 2 weeks ago that also had the worst performance during the most recent 2 weeks while the market was pulling back. You could set up Sharpe Ratio 1 to have an offset of 10 (2 weeks = 10 trading days) and a Seglength of 40. This would find the stocks that had the best performance up and until the market turned.

Set up Sharpe Ratio 2 to have an offset of 0 and a Segment2 = 10 (to analyze the most recent 2 week performance). This Sharpe Ratio will find the stocks with the sharpest declines since the market turned.

Now, create a custom function = SR1 minus SR2. This custom function will find the stocks with the best performance for the 2 month period before the market turned AND the worst pull-backs since the market turn. When the market downward trend is over, such stocks may be excellent long candidates, as they have demonstrated both high volatility and a concordance with the overall market movement.





Initial posted version: 01/30/10

Latest Update: 01/24/13

*.ELD files are compiled for TS 9.1

All ELD and code text files packaged here:


The code may be visualized here:

Function SharpeRatio

Chart Indicator SharpeRatio

Chart Indicator SharpRatioQ

Radarscreen Indicator SharpeRatio.RS

Radarscreen Indicator SharpRatioQ.RS

Strategy SharpeRatio




Bookmark and Share