Skip to content

BitaMin, data analysis & data science assosiation, 12th and 13th joint project.

License

Notifications You must be signed in to change notification settings

maple5795/bitamin1213_trading

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍊BitaMin Project

  • 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

Team

송규헌 송휘종 서영우 이태경 정유진 정준우
song9-avatar shj uosstat taekyoung y8jinn junwoo
Github Github Github Github Github Github

✅Table of Contents


💼Project Introduction

Overview)

◾ Project Topic
Maximizing Portfolio Value by Time Series Forecasting and system trading using Reinforcement Learning.
◾ Goals
  • 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
◾Flowchart

project flowchart image

🔖Reference

We used baseline code of quantylab's rltrader for training model. Modified for real-time trading.

🤗Environment

  • 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.txt

🦾Training

  • cd rltrader/src/
  • refer to quantylab for detailed parameters descriptions.
    e.g.)
  • 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 202405241530
  • --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

When training procedure ends model parameters, output images and log are stored in /rltrader/models/ and /rltrader/output/

🛠️Test (Backtrading)

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

🛠️Test (System Trading)

setting
You should place 'api.json' in order to use KIS API for trading.
  • 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" : ""        
        }    
    

    }

  • Get access token by runnig utils.py
  • 
    cd /bitamin1213_trading/rltrader/src/quantylab/rltrader
    python utils.py
    
system trading
For real-time system trading, use 'predict' keyword. Setting start_date is same as backtrading, 120 time steps before.
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.
Access_token is revoked after the system trading code ends. So you should get access_token before running predict code everyday.

About

BitaMin, data analysis & data science assosiation, 12th and 13th joint project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 99.2%
  • Other 0.8%