forked from senacor/Trader.AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock_exchange.py
60 lines (50 loc) · 3.47 KB
/
stock_exchange.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
# Start evaluation traders:
# Compare their performance over the testing period (2012-2017) against a buy-and-hold trader.
from evaluating.evaluator_utils import initialize_portfolios
from utils import read_stock_market_data
from evaluating.portfolio_evaluator import PortfolioEvaluator
from model.CompanyEnum import CompanyEnum
from dependency_injection_containers import Traders
import datetime
from definitions import PERIOD_1, PERIOD_2
if __name__ == "__main__":
# Load stock market data for training and testing period
stock_market_data = read_stock_market_data([CompanyEnum.COMPANY_A, CompanyEnum.COMPANY_B], [PERIOD_1, PERIOD_2])
# Define portfolio-name/trader mappings
portfolio_name_trader_mappings = [
# Benchmark trader
('Buy-and-hold Trader', Traders.BuyAndHoldTrader(), 'chartreuse'),
# Simple traders
('Simple Trader (perfect prediction)', Traders.SimpleTrader_with_perfect_prediction(), 'pink'),
('Simple Trader (NN binary perfect prediction)', Traders.SimpleTrader_with_nn_binary_perfect_prediction(),
'yellow'),
('Simple Trader (NN binary prediction)', Traders.SimpleTrader_with_nn_binary_prediction(), 'brown'),
# Deep Q-Learning traders
('DQL Trader (perfect prediction)', Traders.DqlTrader_with_perfect_prediction(), 'gray'),
('DQL Trader (NN binary perfect prediction)', Traders.DqlTrader_with_nn_binary_perfect_prediction(), 'magenta'),
('DQL Trader (NN binary prediction)', Traders.DqlTrader_with_nn_binary_prediction(), 'burlywood'),
# Code-Camp Task 0 traders
(
'Team Blue Simple Trader (perfect prediction)', Traders.TeamBlueSimpleTrader_with_perfect_prediction(), 'blue'),
('Team Green Simple Trader (perfect prediction)', Traders.TeamGreenSimpleTrader_with_perfect_prediction(),
'green'),
('Team Black Simple Trader (perfect prediction)', Traders.TeamBlackSimpleTrader_with_perfect_prediction(),
'black'),
('Team Red Simple Trader (perfect prediction)', Traders.TeamRedSimpleTrader_with_perfect_prediction(), 'red'),
# Code-Camp Task 1 traders
('Simple Trader (Team Blue prediction)', Traders.SimpleTrader_with_team_blue_prediction(), 'blue'),
('Simple Trader (Team Green prediction)', Traders.SimpleTrader_with_team_green_prediction(), 'green'),
('Simple Trader (Team Black prediction)', Traders.SimpleTrader_with_team_black_prediction(), 'black'),
('Simple Trader (Team Red prediction)', Traders.SimpleTrader_with_team_red_prediction(), 'red'),
# Code-Camp Task 2 traders
('Team Blue DQL Trader (perfect prediction)', Traders.TeamBlueDqlTrader_with_perfect_prediction(), 'blue'),
('Team Green DQL Trader (perfect prediction)', Traders.TeamGreenDqlTrader_with_perfect_prediction(), 'green'),
('Team Black DQL Trader (perfect prediction)', Traders.TeamBlackDqlTrader_with_perfect_prediction(), 'black'),
('Team Red DQL Trader (perfect prediction)', Traders.TeamRedDqlTrader_with_perfect_prediction(), 'red')
]
# Define portfolios for the traders and create a portfolio/trader mapping
portfolio_trader_mappings = initialize_portfolios(10000.0, portfolio_name_trader_mappings)
# Evaluate their performance over the testing period
evaluator = PortfolioEvaluator([], True)
evaluator.inspect_over_time_with_mapping(stock_market_data, portfolio_trader_mappings,
date_offset=datetime.date(2012, 1, 3))