- BitaMin, data analysis & data science assosiation, 12th and 13th joint project (2024.03.06 ~ 2024.06.05.)
- Time Series and Reinforcement Learning for Stock Trading
| 송규헌 | 송휘종 | 서영우 | 이태경 | 정유진 | 정준우 |
|---|---|---|---|---|---|
| Github | Github | Github | Github | Github | Github |
Maximizing Portfolio Value by Time Series Forecasting and system trading using Reinforcement Learning.
- Use Time Series Forecasting to predict the stock prices (high, low, maximum fluctuation rate, etc.) for the next 5 days and then select the 6 stocks with the highest (high-low) difference.
- Train Reinforcement Learning on the selected stocks and implement system trading
- recommend making a conda virtual environment
- Python 3.7+
- PyTorch 1.13.1
conda install python==3.7
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
conda install pandas
conda install matplotlib
conda install -c conda-forge ta-lib
pip install -r trading_requirements.txtcd rltrader/src/- refer to quantylab for detailed parameters descriptions.
e.g.) --mode: set 'train' when training model--ver: leave it with 'v1' for out code--name: set name of output directory and model file--start_date&--end_date: 'year-month-day-hour-minute'(%Y%m%d%H%M) format
python main.py --mode train --ver v1 --name 001470_202404151325_202405241530 --stock_code 001470 --rl_method ppo --net cnn --backend pytorch --balance 500000000 --start_date 202404151325 --end_date 202405241530When training procedure ends model parameters, output images and log are stored in /rltrader/models/ and /rltrader/output/
check the start_date and end_date of stock. start_date should be the 120 time steps before you want to start the test because of input size of CNN.
e.g.) if you want to backtrade from 2024.05.27 09:01 to 2024.05.31 15:30 then you should set the start_date as 202405241322 which is 120 time steps before the 2024.05.27 09:01.
Also you should set --name same as the train name in order to make sure rltrader use trained model for inference.
python main.py --mode test --ver v1 --name 001470_202404151325_202405241530 --stock_code 001470 --rl_method ppo --net cnn --backend pytorch --balance 500000000 --start_date 202405241320 --end_date 202405311530
- Make KoreaInvestment account.
- Follow the menu ‘트레이딩’ > ‘모의투자’ > ‘주식/선물옵션 모의투자 > 모의투자안내’ > ‘신청/재도전’
- Set initial balance and trading period as you wish.
- Go to API center KIS API.
- Apply for an API(url).
- Set your api.json file as below and place the file under
/bitamin1213_trading/rltrader/src/quantylab/rltrader/
{ "real_invest" : { "account" : "실전투자계좌번호8자리-01", "app_key" : "실전투자계좌 APP Key 복사해서 붙여넣기", "app_secret" : "실전투자계좌 APP Secret 복사해서 붙여넣기", "access_token" : "" },"mock_invest" : { "account" : "모의투자계좌번호8자리-01", "app_key" : "모의투자계좌 APP Key 복사해서 붙여넣기", "app_secret" : "모의투자계좌 APP Secret 복사해서 붙여넣기", "access_token" : "" }
}
cd /bitamin1213_trading/rltrader/src/quantylab/rltrader
python utils.py
You should run system trading code day by day. 'predict' method is just for a day trading.
python main.py --mode predict --ver v1 --name 001470_202404151325_202405241530 --stock_code 001470 --rl_method ppo --net cnn --backend pytorch --balance 500000000 --start_date 202405241320 --end_date 202405281530 --is_start_end 2 --is_mock 1
--is_start_end: 0 for Monday, 1 for Tuesday~Thursday, 2 for Friday.--is_mock: 0 for real investment, 1 for mock investment.
