-
Notifications
You must be signed in to change notification settings - Fork 12
/
comparison.py
29 lines (20 loc) · 856 Bytes
/
comparison.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
from adp.generator import GaussianGenerator
from adp.pwladp.trainer import ADPStrategyTrainer
from adp.strategy import ADPStrategy
from adp.value_function import PWLDynamicFunction
from data import Data, Returns
from markowitz.model import Markowitz
# Train
Returns_train = Returns['2015']
# Test
Returns_test = Data.asfreq('W-FRI', method='pad').pct_change()[1:]['2016']
strategy = ADPStrategy(value_function_class=PWLDynamicFunction)
# Process trainer
trainer = ADPStrategyTrainer(gamma=0.1, generator=GaussianGenerator(r=0.001))
test_perf = []
trainer.train(strategy)
adp_return = strategy.score(Returns_test+1)
markowitz = Markowitz(mean=Returns_train.mean(), cov=Returns_train.cov())
port = markowitz.optimize().getPortfolio()
marko_return = ((Returns_test + 1).prod() * port).sum() - 1
print('Markowitz return: {:.1%}'.format(marko_return))