WHAT IS THIS?
This is my personal port of the Logarithmic Garman-Klass as openly found at iVolatility.com.
This estimator tends to be as fast as the RiskMetrics EWMA but without the noisy overshooting and will not lag as other estimators based on pure arithmetic Standard Deviation like Close-To-Close HV, Original Garman-Klass, Parkinson’s, Rogers-Satchell’s, Yang-Zhang, etc.
Cheers, and any contributions will be welcome.
THE CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// LOGARITHM GARMAN-KLASS VOLATILITY ESTIMATOR by @Xel_arjona // Ported to ProReaCode as Formulae openly described in http://www.ivolatility.com/help/7.html lnCC = log(close/close[1]) lnCO = log(close/open) lnOC = log(open/close[1]) lnHL = log(high/low) // Lambda definition: lambda = Lookback/(Lookback+3) //Initialization with Close-To-Close Historical Volatility varCC = summation[Lookback](square(lnCC)) / Lookback //Logarithmic Garman-Klass Realized/Historical Estimate as in iVolatility.com v2 = square(lnoc) + 0.5*square(lnHL) - 0.386*square(lnCO) varLGK = varCC varLGK = exp( (1-lambda)*log(v2[1])+lambda*log(varLGK) ) LGKest = sqrt(varLGK)*sqrt(Compound) * 100 // PLOT DIRECTIVE RETURN LGKest as "LGK" |
DISCLAIMER: The Following indicator/code IS NOT intended to be a formal investment advice or recommendation by the author, nor should be construed as such. Users will be fully responsible by their use regarding their own trading vehicles/assets.
The embedded code and ideas within this work are FREELY AND PUBLICLY available on the Web for NON LUCRATIVE ACTIVITIES and must remain as is by Creative-Commons and in regard of ProRealCode regulations. Any use, copy or re-use of this code should mention it’s origin as it’s authorship.
XeL 2017
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi! I found myself that the indicator posted here contain an error, I want to edit or fix it as it is not drawing well. [ CC @nicolas ]
The correct algorithm in code should be this:
Lookback = 30
Compound = 252
///////////////////
// LOGARITHM GARMAN-KLASS VOLATILITY ESTIMATOR by @Xel_arjona
// Ported to ProRealCode as Formulae openly described in http://www.ivolatility.com/help/7.html
lnCC = log(close/close[1])
lnCO = log(close/open)
lnOC = log(open/close[1])
lnHL = log(high/low)
// Lambda definition:
lambda = Lookback/(Lookback+3)
//Initialization with Close-To-Close Historical Volatility
varCC = summation[Lookback](square(lnCC)) / Lookback
//Logarithmic Garman-Klass Realized/Historical Estimate as in iVolatility.com
if barindex < Lookback+4 then
varLGK = varCC
else
GK = square(lnOC) + 0.5*square(lnHL) - 0.386*square(lnCO)
LGK = log(varCC)
LGK = ((1-lambda)*log(GK[1])) + (lambda*log(LGK[1]))
varLGK = exp( LGK )
endif
LGKest = sqrt(varLGK)*sqrt(Compound) * 100
// PLOT DIRECTIVE
RETURN LGKest as "LGK"
The correction is on the Autoregresive definition for LGK, which should be refered to last value “LGK[1]” instead of current. Even this patch is applyed; the code itself do not print correct values (giving only zeros), but this is a possible limitation on PRT or a missundestood of mine for the internals of ProRealCode. This same kind of algorithm do some errors for other indicators of mine also. https://www.prorealcode.com/topic/plot-issue-with-custom-exponential-indicator/
Cheers and sorry for the inconvenience.