PureBytes Links
Trading Reference Links
|
I am posting some Code (written in BASIC) which attempts to calculate
the Risk of Ruin according the R6 formula presented in the book
“Portfolio Management Formula’s” written by Ralph Vince in 1990.
The formulas can be found on pages 141 through 147 and accompanying
source code on pages 190 through 198 (both in Basic and C).
I am fairly confident that I translated the code properly, but am not
100% sure. The code is sort of ugly, a mix of some of my variable
naming conventions as well as Vince’s.
My goal of posting this is twofold, one I would like to share the code
with all, as I feel that this is a fairly useful piece of information to
possess when you are attempting to evaluate your trading methodology and
two, I would like some sort of confirmation, via peer review, that the
algorithm is actually returning the correct values.
So with that said, below is the code for the R6 version of the Risk of
Ruin formula as well as a set of inputs with the corresponding output
from the formula. I look forward to hearing back from all of your
thoughts, comments, and suggestions/corrections.
Andrew
andrew@xxxxxxxxx
CODE BEGIN---------------------------
Public Function R6() as Double
Dim NumWinners, NumLosers As Integer
Dim Sum, AvgWin, AvgLoss, MaxLoss As Double
Dim WinPercent, FUsed, Depletion As Single
Dim VAF, FAL, PAF, Fan As Double
Dim N, X As Long
Dim Fap, YY, WHY, UAL, SEA As Double
Dim R6 As Double
FUsed = 0.5 '// Stake at Risk on Each Trade - Equivalent
to
‘// Vince's Optimal F
Depletion = 0.75 '// Size of DrawDown which is Considered Ruin
NumWinners = 35 '// Number of Winning Trades
NumLosers = 65 '// Number of Losing Trades
AvgWin = 3.71 '// Value of Average of all Winning Trades
‘// (Factor of an Avg Loss of $1.00)
AvgLoss = -1# '// Value of Average of all Losing Trades
‘// (Normalized to $1.00)
MaxLoss = -4.75 '// Value of Max Loss
‘// (Factor of an Avg Loss of $1.00)
WinPercent = (NumWinners / (NumWinners + NumLosers))
VAF = ((AvgWin / Abs(MaxLoss / FUsed)) * WinPercent) - _
(Abs((AvgLoss / Abs(MaxLoss / FUsed))) * (1 - WinPercent))
FAL = Sqr(((WinPercent * ((AvgWin / Abs(MaxLoss / FUsed)) ^ 2)) + _
((1 - WinPercent) * ((AvgLoss / Abs(MaxLoss / FUsed)) ^ 2))))
PAF = (0.5 * (1 + (VAF / FAL)))
Fan = 0#
N = 1
Fap = 1#
Do While (Fap > 0.0000001)
X = 1
YY = 0#
Fap = 1#
Do While (X <= N)
WHY = (1 / X)
If (X = 1) Then
WHY = Depletion
End If
UAL = (WHY / FAL)
SEA = ((((Abs(MaxLoss / FUsed) / X) + Abs(MaxLoss / FUsed))
- _
((1 - WHY) * Abs(MaxLoss / FUsed))) / Abs(MaxLoss /
Fused))_
/ FAL
YY = 1 - ((((1 - PAF) ^ UAL) - 1) / ((((1 - PAF) / PAF) ^
SEA) - _
1))
If X <= N Then
Fap = Fap * YY
X = X + 1
End If
Loop
Fan = Fan + Fap
N = (N + 1)
Loop
R6 = Fan
‘// Answer with the Above Input Values = 0.028930705747327 or 2.89%
End Function
CODE END---------------------------
|