Not sure I understand the point of having the threshold. Notice you set the default at 15. But what if you set the parameter to 0 or to 30. The calculated numbers would obviously be different, but what is the use of the absolute semideviation ratio. Presumably the important thing is the relative value of the ratio in different tests?
Here is the source code of the Marketplace Blok:
Code: Select all
' Calculate the Semideviation Ratio using weekly equity readings (every 5 bars)
VARIABLES: sum_good, sum_bad, weekly_threshold, weekly_return TYPE: floating
VARIABLES: delta, avg_weekly_return, semideviation, apr, the_ratio TYPE: floating
VARIABLES: i, numdays, numweeks TYPE: integer
numdays = test.currentDay
numweeks = 0
weekly_threshold = (1.0 + annual_Thresh)^(1.0/52.0)
sum_good = 0.0
sum_bad = 0.0
' walk forward thru time == backward thru totalequity[] array
FOR i = numdays - 1 TO 6 STEP -5
numweeks = numweeks + 1
weekly_return = test.totalequity[(i-5)] / test.totalequity[i]
delta = weekly_return - weekly_threshold
IF(delta < 0.0) THEN
sum_bad = sum_bad + (delta * delta)
ENDIF
sum_good = sum_good + weekly_return
NEXT
avg_weekly_return = sum_good / AsFloating(numweeks)
semideviation = SquareRoot(sum_bad / AsFloating(numweeks))
apr = 1.0 + ((avg_weekly_return - 1.0) * 52.0)
the_ratio = (apr - (1.0 + annual_Thresh)) / semideviation
test.AddStatistic( "Semideviation", the_ratio )