Download MetaTrader 5
To add comments, please log in or register
Do you need a programmer? Make an order to let the developer find you!
Hermogenes Vidal Rodriguez
1450
Hermogenes Vidal Rodriguez 2014.08.09 11: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
Next
downDev = Sqr(mm2d / n)
If downDev > 0 Then
   SortinoRatio = (avgReturn - MAR) / downDev
Else
   SortinoRatio = "undefined"
End If
 
End Function

Thank you very much in advance.

Kind regards.

Hermo.


SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.09 16:37  
What those functions are for?
Hermogenes Vidal Rodriguez
1450
Hermogenes Vidal Rodriguez 2014.08.09 17:26  
deysmacro:
What those functions are for?

They are ratios for read:


I use them to make an analysis of results


http://investexcel.net/calculating-the-sharpe-ratio-with-excel/

http://investexcel.net/calculate-the-sortino-ratio-with-excel



Thank you very much for your interest.

A greeting.

Hermo.

/
To add comments, please log in or register