mrparks 5 posts msg #123821 - Ignore mrparks |
5/19/2015 1:46:23 PM
I appreciate your in posts. In your post about the sharpe, trevor ane jensen ratios. Could you include the Sortino Ratio?
|
Kevin_in_GA 4,599 posts msg #123822 - Ignore Kevin_in_GA |
5/19/2015 4:45:09 PM
I do not think this is possible in SF code - the Sortino ratio looks at only one half of the volatility (the downside) arguing that upside volatility is not actually "risk". I cannot see a way to separate the upside volatility from the downside volatility without exceeding SF limits on user-defined functions.
Please feel free to ask SF to write a Sortino function into SF. Warning - I am still waiting for them to do this for the Sharpe ratio, and that request was placed several years ago with periodic reminders (until they wore me down and I gave up).
|
Kevin_in_GA 4,599 posts msg #124306 - Ignore Kevin_in_GA |
7/8/2015 7:49:21 PM
Here is the code for the Sortino ratio (in StrataSearch). This is entered as a custom function named sortino.
parm1 = parameter("parm1");
var1 = (close - ref(close,-1))/ref(close,-1)*100;
var2 = if(var1 less than 0,1,0);
var3 = var1 * var2;
var4 = var3*var3;
var5 = mov(var4, parm1,s);
downside = sqrt(var5);
return = proc(close,parm1);
sortino = (return / downside)*sqrt(parm1/365)
Norte that the text in bold needs to be replaced with its mathematical symbol to work (I have removed it here since it triggers some HTML code in the final post).
I have been thinking about how this might be coded in SF. If you set the number of days (parm1) at a fixed value it can be done, as shown below. Here I am using a six month lookback which I have found to be useful.
|
fotchstecker 304 posts msg #124318 - Ignore fotchstecker |
7/9/2015 8:16:04 PM
Thanks, Kevin.
|
Kevin_in_GA 4,599 posts msg #124326 - Ignore Kevin_in_GA |
7/10/2015 8:50:40 AM
Perhaps SF could code this as a function? I just gave you all the code - it would be nice to have it be able to look back over any number of days the user inputs.
|
stockfetcher 980 posts msg #124327 |
7/10/2015 8:58:00 AM
Hi Kevin,
Thank you for the example code and suggestion! We should have no problem adding that as a function to StockFetcher and will post an update when we have it available.
StockFetcher Support
|
stockfetcher 980 posts msg #124328 |
7/10/2015 10:07:33 AM
As a quick follow-up, you should now be able to use "Sortino Ratio(period)" in your filters. For example:
Please let us know if you have any questions or notice any problems with this new measure.
StockFetcher Support
|
stockfetcher 980 posts msg #124343 |
7/10/2015 2:36:52 PM
As another follow-up (from a way-back request), we now have a version of the Sharpe Ratio available. Below are a couple examples that show the original code from your request, compared with the output of the new built-in measure.
Sample code from original request:
New version:
The Sharpe Ratio takes 3 parameters:
Sharpe Ratio(period , RFR Value , Flag)
- period: Days used in the calcuation.
- RFR Value: Either a symbol (e.g. ^IRX) or a constant as a percent (eg. 0.02). Default=^IRX
- Flag: Either 0 or 1. If you are using a symbol for parameter 2, setting the flag to 1 will calculate the RFR as the price change over the desired period for the specified symbol. Default=0
An example using the Flag option. The below will calculate the 21 day Sharpe Ratio using the 21-day price change (percent) as the risk-free-rate in the formula. Obviously, this is not a "risk-free" rate of return, but may provide some flexibility in customizing the formula.
As always, please let us know if you have any questions, or run into any issues.
Thank you,
StockFetcher Support
|