StockFetcher Forums · General Discussion · Kevin_in_GA<< >>Post Follow-up
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.

Fetcher[
s&p 500

set{var1, roc(1,1)}
set{ifdown, count(var1 below 0, 1)}
set{var3, var1 * ifdown}
set{var4, var3 * var3}
set{var5a, sum(var4, 126)}
set{var5, var5a / 126}
set{downside, sqrt(var5)}
set{return, roc(126,1)}
set{sortino1, return / downside}
set{sortino, sortino1 * 0.25}

add column sortino
]



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:

Fetcher[
S&P 500
add column Sortino Ratio(126)
and draw Sortino Ratio(126)
]



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:

Fetcher[
SET{21DAYSAGO, CLOSE 21 DAYS AGO}
SET{21DAYRETURN, CLOSE - 21DAYSAGO}
SET{21DAYPERCENTRETURN, 21DAYRETURN / 21DAYSAGO}
SET{RFR, IND(^IRX, CLOSE)}
SET{RISKFREERETURN, rfr / 100}
SET{PERFORMANCE, 21DAYPERCENTRETURN - RISKFREERETURN}
SET{STD, CSTDDEV(CLOSE,21)}
SET{VOLATILITY, STD / MA(21)}
SET{SHARPE, PERFORMANCE / VOLATILITY}
market is S&P 500
and add column SHARPE
]



New version:
Fetcher[
market is S&P 500
add column Sharpe Ratio(21)
]



The Sharpe Ratio takes 3 parameters:

Sharpe Ratio(period , RFR Value , Flag)
  1. period: Days used in the calcuation.

  2. RFR Value: Either a symbol (e.g. ^IRX) or a constant as a percent (eg. 0.02). Default=^IRX

  3. 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.

Fetcher[add column Sharpe Ratio(21,SPY,1)
market is S&P 500
]



As always, please let us know if you have any questions, or run into any issues.

Thank you,
StockFetcher Support







StockFetcher Forums · General Discussion · Kevin_in_GA<< >>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 2022 - 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


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.