-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest Script.py
More file actions
73 lines (65 loc) · 2.06 KB
/
Test Script.py
File metadata and controls
73 lines (65 loc) · 2.06 KB
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
# %%
from datetime import date
from src.analyzer.analyzer import Analyzer
from src.data.feed import CSVDataFeed
from src.data.rebalancing_schedule import PeriodicSchedule
from src.env.base_env import BaseEnv
from src.env.portfolio import BenchmarkPortfolio, RLPortfolio
from src.utils.load_path import load_data_path
DATA_PATH = load_data_path()
# %%
config = {
'benchmark_portfolio': {
'name': 'benchmark_portfolio',
'rebalancing_type': "equally_weighted",
'investment_universe': ["MKT_Index", "SMB_Index", 'HML_Index', 'RF_Index'],
'initial_balance': int(10000),
'initial_weights': [0.25, 0.25, 0.25, 0.25],
'restrictions': {"direction": "long_only"},
'rebalancing_schedule': PeriodicSchedule(frequency="WOM-3FRI")
},
'rl_portfolio': {
'name': 'rl_portfolio',
'rebalancing_type': None,
'investment_universe': ["MKT_Index", "SMB_Index", 'HML_Index', 'RF_Index'],
'initial_balance': int(10000),
'initial_weights': [0.25, 0.25, 0.25, 0.25],
'restrictions': {"direction": "long_only"},
'rebalancing_schedule': PeriodicSchedule(frequency="WOM-3FRI")
},
'broker': {
"rl_portfolio": None,
"benchmark_portfolio": None,
"start_date": date(2000, 12, 31),
"end_date": date(2020, 12, 31),
"busday_offset_start": 250,
"transaction_cost": 0.05
},
'agent': {
"reward_scaling": int(1),
"obs_price_hist": int(250),
}
}
# Specify the portfolio configurations
config['broker']['rl_portfolio'] = RLPortfolio(config['rl_portfolio'])
config['broker']['benchmark_portfolio'] = BenchmarkPortfolio(config['benchmark_portfolio'])
# random.seed(1)
feed = CSVDataFeed(
DATA_PATH + "/example_factor_clean.csv",
)
env = BaseEnv(config=config, data_feed=feed)
env.reset()
done = False
while not done:
action = env.action_space.sample()
obs, rew, done, _ = env.step(action)
# %%
analyzer = Analyzer(env)
# %%
df = analyzer.data
# %%
analyzer.get_prices()
# %%
analyzer.get_cash("rl")
# %%
analyzer.get_rewards()