StockFetcher Forums · General Discussion · New SF function request - Sharpe ratio<< >>Post Follow-up
Kevin_in_GA
4,553 posts
msg #98359
Ignore Kevin_in_GA
1/1/2011 9:15:36 PM

I have been spending time this past year working on several different concepts for trading, one of which focuses on looking at risk-adjusted returns. I have written the necessary code to do this in SF, but think that this could be easily implemented by the SF team into a simple function that would automatically calculate the Sharpe ratio (annualized or not) for any stock or ETF over a user-specified time frame.

1. The Sharpe ratio

The Sharpe ratio (aka Sharpes measure), developed by William F. Sharpe, is the ratio of a portfolio’s total return minus the risk-free rate divided by the standard deviation of the portfolio, which is a measure of its risk. The Sharpe ratio is simply the risk premium per unit of risk, which is quantified by the standard deviation of the portfolio.

Risk Premium = (Total Portfolio Return – Risk-free Rate) / Standard Deviation of Portfolio

The risk-free rate is subtracted from the portfolio return because a risk-free asset, often exemplified by short-term Treasuries or Certificates of Deposit, has no risk premium since the return of a risk-free asset is certain. Therefore, if a portfolio’s return is equal to or less than the risk-free rate, then it makes no sense to invest in the risky assets.

Hence, the Sharpe ratio is a measure of the performance of the portfolio compared to the risk taken — the higher the Sharpe ratio, the better the performance and the greater the profits for taking on additional risk.

Coding this in Stockfetcher is pretty easy. This is what I have done to make this work:

First, calculate the return of the stock or ETF over the last 21days (one calendar month, but this value should be a variable that the user can easily set):

SET{21DAYSAGO, CLOSE 21 DAYS AGO}
SET{21DAYRETURN, CLOSE - 21DAYSAGO}
SET{21DAYPERCENTRETURN, 21DAYRETURN / 21DAYSAGO}


Next, subtract from this the risk-free rate of return. I use the current value of the 13 week treasury bill (SF has this as ^IRX) and divide it by 100 to keep the percentages the same:

SET{RFR, IND(^IRX, CLOSE)}
SET{RISKFREERETURN, rfr / 100}
SET{PERFORMANCE, 21DAYPERCENTRETURN - RISKFREERETURN}


You could also use the roc(21,1) function for PERFORMANCE, but it needs to be divided by 100 as well if you do this - or just divide the final result by 100 when you are done.

Now determine the volatility of the investment - this is simply the standard deviation of the prices divided by the average price:

SET{STD, CSTDDEV(CLOSE,21)}
SET{VOLATILITY, STD / MA(21)}


Now it's easy to calculate the Sharpe ratio for any stock or ETF:

SET{SHARPE, PERFORMANCE / VOLATILITY}

Can't this be written in SF as a simple function, perhaps looking like

sharpe(days) where the user can set the time period for review?

Thanks for all your help in adding new functionality during 2010. We all appreciate it.



Kevin_in_GA
4,553 posts
msg #98481
Ignore Kevin_in_GA
1/7/2011 2:22:50 PM

Tom B and crew:

Just a reminder on this request. I think this would be helpful to many new users who may be solely focused on return and ignoring risk entirely.

Also, if one looks at the ^SPX in terms of its Sharpe ratio, this calculation is surprisingly informative and helpful in avoiding corrections (or spotting them for shorting opportunities).

Any chance of seeing this function as part of the SF toolkit?

Kevin

Kevin_in_GA
4,553 posts
msg #98822
Ignore Kevin_in_GA
1/31/2011 3:02:34 PM

Tom and crew:

Any response here? I also sent an email to the SF support team on this specific request and have yet to hear if there is any plan to implement this anytime soon.

Thanks.

stockfetcher
963 posts
msg #98823
1/31/2011 3:05:28 PM

Hi,

We have passed this feature request on to our development team. Currently we do not have an estimated time when the functionality may be available.

Thank you,

StockFetcher Support


tylercabral
14 posts
msg #118860
Ignore tylercabral
3/30/2014 8:34:59 PM

Any word on this? It has been 2 years.

alf44
2,025 posts
msg #118861
Ignore alf44
modified
3/30/2014 8:45:32 PM

.

2 Years ???

REALLY ???

.

You are SOOO impatient !!!

LOL

.

tylercabral
14 posts
msg #118869
Ignore tylercabral
3/31/2014 12:09:18 PM

Sorry I keep thinking its 2013 still. Its been 3 years.

stockfetcher
963 posts
msg #118874
3/31/2014 1:46:15 PM

Hi,

Thank you for the feedback. We will revisit adding this measure.

StockFetcher Support

StockFetcher Forums · General Discussion · New SF function request - Sharpe ratio<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus