Downside Deviation script help

Hello,

I am starting to script a downside deviation/sortino based script via attached instructions. This script is incomplete as I got stuck on the step of removing positive returns.

Is there a way to look at a variable’s value and keep it if its a negative return, but over ride it and make it zero if its a positive return?

Ex: IF R1 is less than zero, keep its value; but if R1 is greater than zero then make R1 zero.

 

Here is what I have so far:

//Downside Deviation - Sortino

//Set minimum acceptable rate of return ( MAR )
MAR = .01;

//Setup periods
M12020 = MONTHNUM() == 1 and YEARNUM() == 2020;
M22020 = MONTHNUM() == 2 and YEARNUM() == 2020;
M32020 = MONTHNUM() == 3 and YEARNUM() == 2020;
//etc

//Get end of month values
V1 = VALUEWHEN(M12020);
V2 = VALUEWHEN(M22020);
V3 = VALUEWHEN(M32020);
//etc

//Calculate the returns and subtract MAR

R1 = ((V2/V1)-1) - MAR;
R2 = ((V3/V2)-1) - MAR;

//Keep the negative return values; adjust positive return values to zero.

 

Jeff

 

sortino-excel-instructions.jpg

Hi Jeff,

Use the following IF statement which will use the value of R1 if R1< 0 is true, and zero if false (ie R1 > 0):

R1 = ((V2/V1)-1) - MAR;
IF(R1<0,R1,0)

Also, when posting formulas please use the <>Code button in the format bar which removes all formatting when copying and pasting in to Optuma [I updated your original post]. See this pinned post for instructions:

How to Add Code to Forum Posts

Thanks!