forked from AI4Finance-Foundation/FinRL-Meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trade.py
35 lines (30 loc) · 1.65 KB
/
trade.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
from test import test
from neo_finrl.env_stock_trading.env_stock_papertrading import AlpacaPaperTrading
def trade(start_date, end_date, ticker_list, data_source, time_interval,
technical_indicator_list, drl_lib, env, model_name, API_KEY,
API_SECRET, APCA_API_BASE_URL, trade_mode='backtesting',
if_vix = True, **kwargs):
if trade_mode == 'backtesting':
#use test function for backtesting mode
test(start_date, end_date, ticker_list, data_source, time_interval,
technical_indicator_list, drl_lib, env, model_name, if_vix=True,
**kwargs)
elif trade_mode == 'paper_trading':
#read parameters
try:
net_dim = kwargs.get("net_dimension", 2 ** 7)
cwd = kwargs.get("cwd", "./" + str(model_name)) #current working directory
state_dim = kwargs.get("state_dim")
action_dim = kwargs.get("action_dim")
except:
raise ValueError('Fail to read parameters. Please check inputs for net_dim, cwd, state_dim, action_dim.')
#initialize paper trading env
AlpacaPaperTrading(ticker_list, time_interval, drl_lib, model_name,
cwd, net_dim, state_dim, action_dim,
API_KEY, API_SECRET, APCA_API_BASE_URL,
technical_indicator_list, turbulence_thresh=30,
max_stock=1e2, latency = None)
#run paper trading
AlpacaPaperTrading.run()
else:
raise ValueError("Invalid mode input! Please input either 'backtesting' or 'paper_trading'.")