-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_types.py
75 lines (57 loc) · 1.96 KB
/
option_types.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from models.abstract import BaseOption
from models.openai_env import OptionEnv
from models.baseline_tfa_dqn import TFAModel
from models.binomial_tree import EUBinomialTree, USBinomialTree
from models.black_scholes import BlackScholes
from models.monte_carlo import EUMonteCarlo, ASMonteCarlo
MODELS = {
"eu": ["Black Scholes", "Binomial Tree", "Monte Carlo"],
"us": ["Binomial Tree", "Deep Q-Network"],
"as": ["Monte Carlo"]
}
class USOption(BaseOption):
_model_map = {
"Binomial Tree": USBinomialTree,
"Deep Q-Network": None
}
def __init__(self, **kwargs):
self._kwargs = kwargs
super().__init__(kwargs)
def _dqn(self):
option = TFAModel(OptionEnv, self._kwargs)
option.init_agent()
option.build_replay_buffer()
option.train()
option.calculate_npv()
priced_option = option
return priced_option
def priced(self, model: str):
if model == "Deep Q-Network":
return self._dqn()
return self._model_map[model](self._kwargs)
def all(self):
return [self.priced(model) for model in self._model_map.keys()]
class EUOption(BaseOption):
_model_map = {
"Black Scholes": BlackScholes,
"Binomial Tree": EUBinomialTree,
"Monte Carlo": EUMonteCarlo
}
def __init__(self, **kwargs):
self._kwargs = kwargs
super().__init__(kwargs)
def priced(self, model: str):
return self._model_map[model](self._kwargs)
def all(self):
return [self.priced(model) for model in self._model_map.keys()]
class ASOption(BaseOption):
_model_map = {
"Monte Carlo": ASMonteCarlo
}
def __init__(self, **kwargs):
self._kwargs = kwargs
super().__init__(kwargs)
def priced(self, model: str):
return self._model_map[model](self._kwargs)
def all(self):
return [self.priced(model) for model in self._model_map.keys()]