forked from cmf-team/importance-sampling-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
38 lines (29 loc) · 1.04 KB
/
models.py
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
from arch import arch_model
from scipy.stats import norm
class RiskMetrics:
'''
Longerstaey, Jacques, and Martin Spencer. "Riskmetricstm—technical
document." Morgan Guaranty Trust Company of New York: New York 51
(1996): 54.
'''
def __init__(self, alpha):
self.alpha = alpha
self.lambd = 0.94
self.window_size = 74
def forecast(self, feat):
raise Exception(NotImplementedError)
class HistoricalSimulation:
def __init__(self, alpha, window_size):
self.alpha = alpha
self.window_size = window_size
def forecast(self, feat):
raise Exception(NotImplementedError)
class GARCH11:
def __init__(self, alpha, window_size):
self.alpha = alpha
self.window_size = window_size
def forecast(self, feat):
model = arch_model(feat[-self.window_size:], p=1, q=1, rescale=False)
res = model.fit(disp='off')
sigma2 = res.forecast(horizon=1, reindex=False).variance.values[0, 0]
return norm.ppf(1 - self.alpha, scale=sigma2**0.5)