Kevin_in_GA 4,599 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 riskadjusted 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 userspecified 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 riskfree 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 – Riskfree Rate) / Standard Deviation of Portfolio
The riskfree rate is subtracted from the portfolio return because a riskfree asset, often exemplified by shortterm Treasuries or Certificates of Deposit, has no risk premium since the return of a riskfree asset is certain. Therefore, if a portfolio’s return is equal to or less than the riskfree 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 riskfree 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,599 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,599 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 976 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 976 posts msg #118874 
3/31/2014 1:46:15 PM
Hi,
Thank you for the feedback. We will revisit adding this measure.
StockFetcher Support
