tradingai / tbase Goto Github PK
View Code? Open in Web Editor NEWBaselines of reinforcement learning trading agents for China stock market
Home Page: https://tradingai.github.io/tbase/
License: MIT License
Baselines of reinforcement learning trading agents for China stock market
Home Page: https://tradingai.github.io/tbase/
License: MIT License
使用TF-Serving做模型部署
默认的评估时间窗口太短了,适当调整以增强实验的说服力 @iminders
根据: https://github.com/tradingAI/proto/tree/master/model 中的输入输出, 将结果转换成相应的proto文件存储到s3中
具体实现 trunner(>=1.0.1)中的upload方法
T0场景下,已经拥有持仓h, 不管当天如何交易,在收盘时,一定要保证持仓仍然是h
origin issue: iminders/tbase#6
系统环境
Ubuntu 18.04
GPU: GTX 1080
Memory: 8G
运行命令: python3 -m tbase.run --num_env 2
错误信息:
Traceback (most recent call last): File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/ubuntu/gopath/src/github.com/iminders/tbase/tbase/run.py", line 56, in main() File "/home/ubuntu/gopath/src/github.com/iminders/tbase/tbase/run.py", line 50, in main agent.learn() File "/home/ubuntu/gopath/src/github.com/iminders/tbase/tbase/agents/ddpg/agent.py", line 152, in learn sample_size=self.args.sample_size) File "/home/ubuntu/gopath/src/github.com/iminders/tbase/tbase/agents/ddpg/agent.py", line 63, in explore worker.start() File "/usr/lib/python3.6/multiprocessing/process.py", line 105, in start self._popen = self._Popen(self) File "/usr/lib/python3.6/multiprocessing/context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "/usr/lib/python3.6/multiprocessing/context.py", line 284, in _Popen return Popen(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 32, in init super().init(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 19, in init self._launch(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 59, in _launch cmd, self._fds) File "/usr/lib/python3.6/multiprocessing/util.py", line 417, in spawnv_passfds False, False, None) OSError: [Errno 12] Cannot allocate memory Segmentation fault (core dumped)
如题
可能的原因:当模型在最优解附近时,再使用梯度下降或其他的基于梯度的最优化方法求解时,很有可能直接跳过最优解,从而导致交易失败。
例如:000001.SZ(平安银行), 2020.02.27日最高价: 15.15, 最低价:14.89
如果模型这时的输出决策:15.15卖出,14.89买入,再往梯度方向调整,很有可能就会出现卖出价格过高,买进价格过低,无法达成交易,最终使收益率阶梯式下降
如何避免这种现象?
或者证明无法避免这种现象
Mac os
python3 -m tbase.run --alg ddpg --codes "600237.SH" --num_env 1 --gamma 0.53 --seed 9 --max_iter_num 1000 --tensorboard_dir=./logs/ --eval_end '20200331' --print_action
Error
2020-04-01 17:00:43,908 run.py[40] INFO tbase.run set global_seeds: 9
2020-04-01 17:00:45,220 reward.py[138] INFO tenvs.envs.reward use reward function: daily_return_with_chl_penalty
********************************************************************************
2020-04-01 17:00:45,221 run.py[45] INFO Initializing agent by parameters:
2020-04-01 17:00:45,221 run.py[46] INFO Namespace(activation='tanh', alg='ddpg', clear_memory_interval=5, codes='600237.SH', data_dir='/tmp/tenvs', debug=False, device=None, end='20191231', entropy_coef=0.1, eval=False, eval_end='20200331', eval_start='20200101', explore_size=400, gamma=0.53, indexs='000001.SH,399001.SZ', investment=100000, log_deals=False, log_interval=10, look_back_days=10, lr=0.001, max_grad_norm=5, max_iter_num=1000, model_dir='/tmp/tbase/models', num_env=1, opt_fn='rmsprop', play=False, policy_net='LSTM_MLP', print_action=True, reward_fn='daily_return_with_chl_penalty', run_id=1, sample_size=200, scenario='average', seed=9, start='20190101', t_max=10, tau=0.95, tensorboard_dir='./logs/', value_loss_coef=0.5, value_net='LSTM_Merge_MLP', warm_up=10000)
2020-04-01 17:00:46,631 reward.py[138] INFO tenvs.envs.reward use reward function: daily_return_with_chl_penalty
2020-04-01 17:00:46,632 run.py[49] INFO Training agent
2020-04-01 17:00:46,632 ac_agent.py[143] INFO warmming up: explore 10000 days in enviroment
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/run.py", line 59, in <module>
main()
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/run.py", line 50, in main
agent.learn()
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/agents/ddpg/agent.py", line 69, in learn
self.warm_up()
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/agents/base/ac_agent.py", line 147, in warm_up
self.simple_explore(self.args.warm_up, self.args.sample_size)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/agents/base/ac_agent.py", line 84, in simple_explore
self.policy, explore_size, self.args.print_action)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tbase/tbase/agents/base/explore.py", line 53, in simple_explore
next_state, reward, done, info, _ = env.step(action)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tenvs/tenvs/envs/base.py", line 220, in step
only_update)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tenvs/tenvs/envs/average.py", line 85, in do_action
sell_cash_change, ok = self.sell(i, sell_price, 0)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tenvs/tenvs/envs/base.py", line 92, in sell
bid_price=price)
File "/Users/liuwen/Google/liulishuo/workspace/go/gopath/src/github.com/tradingAI/tenvs/tenvs/market.py", line 265, in sell_check
if low == high and pct_change < -self.top_pct_change:
AttributeError: 'Market' object has no attribute 'top_pct_change'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.