Help with function Sharpe Ratio And Sortino Ratio.

Back to topics list To post a new topic, please log in or register
Hermo 2014.08.09 13:17
Good morning to all

I have very basic programming concepts and I am trying to add two functions to calculate the Sharpe Ratio and Sortino Ratio for you to reflect on the information panel on my EA.

I have the code in another programming language but I find it impossible to transform MQL4 language.

Can someone help me create these functions please.

The codes that I have are:

Sharpe Ratio

Function SharpeRatio(InvestReturn, RiskFree) As Double
 Dim AverageReturn As Double
 Dim StandardDev As Double
 Dim ExcessReturn() As Double
 Dim nValues As Integer

 nValues = InvestReturn.Rows.Count
 ReDim ExcessReturn(1 To nValues)

 For i = 1 To nValues
  ExcessReturn(i) = InvestReturn(i) - RiskFree(i)
 Next i

 AverageReturn = Application.WorksheetFunction.Average(ExcessReturn)
 StandardDev = Application.WorksheetFunction.StDev(ExcessReturn)
 SharpeRatio = AverageReturn / StandardDev
End Function

Sortino Ratio

Function SortinoRatio(returns As Range, MAR As Variant) As Variant
Dim n As Integer
Dim i As Integer
Dim avgReturn As Double
Dim mm2d As Double
Dim downDev As Double
n = returns.Rows.Count
avgReturn = WorksheetFunction.Average(returns)
moment2d = 0
For i = 1 To n
   If returns(i) - MAR < 0 Then
     mm2d = mm2d + ((returns(i) - MAR) ^ 2)
   End If
downDev = Sqr(mm2d / n)
If downDev > 0 Then
   SortinoRatio = (avgReturn - MAR) / downDev
   SortinoRatio = "undefined"
End If
End Function

Thank you very much in advance.

Kind regards.


deysmacro 2014.08.09 18:37 #
What those functions are for?
Hermo 2014.08.09 19:26 #
What those functions are for?

They are ratios for read:

I use them to make an analysis of results

Thank you very much for your interest.

A greeting.


Back to topics list  

To add comments, please log in or register