-
Notifications
You must be signed in to change notification settings - Fork 342
/
eval.py
68 lines (53 loc) · 2.08 KB
/
eval.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
"""
Script for evaluating Stock Trading Bot.
Usage:
eval.py <eval-stock> [--window-size=<window-size>] [--model-name=<model-name>] [--debug]
Options:
--window-size=<window-size> Size of the n-day window stock data representation used as the feature vector. [default: 10]
--model-name=<model-name> Name of the pretrained model to use (will eval all models in `models/` if unspecified).
--debug Specifies whether to use verbose logs during eval operation.
"""
import os
import coloredlogs
from docopt import docopt
from trading_bot.agent import Agent
from trading_bot.methods import evaluate_model
from trading_bot.utils import (
get_stock_data,
format_currency,
format_position,
show_eval_result,
switch_k_backend_device
)
def main(eval_stock, window_size, model_name, debug):
""" Evaluates the stock trading bot.
Please see https://arxiv.org/abs/1312.5602 for more details.
Args: [python eval.py --help]
"""
data = get_stock_data(eval_stock)
initial_offset = data[1] - data[0]
# Single Model Evaluation
if model_name is not None:
agent = Agent(window_size, pretrained=True, model_name=model_name)
profit, _ = evaluate_model(agent, data, window_size, debug)
show_eval_result(model_name, profit, initial_offset)
# Multiple Model Evaluation
else:
for model in os.listdir("models"):
if os.path.isfile(os.path.join("models", model)):
agent = Agent(window_size, pretrained=True, model_name=model)
profit = evaluate_model(agent, data, window_size, debug)
show_eval_result(model, profit, initial_offset)
del agent
if __name__ == "__main__":
args = docopt(__doc__)
eval_stock = args["<eval-stock>"]
window_size = int(args["--window-size"])
model_name = args["--model-name"]
debug = args["--debug"]
coloredlogs.install(level="DEBUG")
switch_k_backend_device()
try:
main(eval_stock, window_size, model_name, debug)
except KeyboardInterrupt:
print("Aborted")