-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRSvol.m
43 lines (29 loc) · 1.07 KB
/
RSvol.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function sigma_hat = RSvol(O,H,L,Cl,k)
%RSvol() Computes historical volatility using Roger-Satchell estimator
% RSvol() function computes historical volatility using Roger-Satchell
% estimator and OHLC data. R-S estimator allows for arbitrary drift.
% INPUT:
% O - opens
% H - highs
% L - lows
% C - close
% k - rolling window size
% OUTPUT:
% sigma_hat - historical volatility estimate
% Petr Javorik (2016) [email protected]
% http://mmquant.net/introduction-to-volatility-models-with-matlab-sma-ewma-cc-range-estimators/
% input check
assert(k <= length(H),'Window length is greater than time series length!');
assert(length(H)==length(L) &&...
length(H)==length(O) &&...
length(H)==length(Cl),'Sizes of OHLC series are not equal.');
% RS computation
% A,B,C are terms in (5) on the left in brackets respectively
sigma_hat = zeros(size(H));
A = log(H./Cl).*log(H./O);
B = log(L./Cl).*log(L./O);
for t = k+1:length(H)
sigma_hat(t,1) = 1/k * sum(A(t-k:t-1) + B(t-k:t-1));
end
sigma_hat = sqrt(sigma_hat) * sqrt(252);
end