Made by DevTae
This is the repository that summarizes about my own project named DevTae/StockTools
-
Project Overview
StockDatabase
,StockDatabaseHelper
- Constructing File-System Database
- Downloading Adjusted Price Datas, Theme, Industry datas
- Calculating Many Price Indicators as like Ichimoku
- Auto Update Helper Tool
StockBacktester
- Searching stocks using specific functions with conditions
- Backtesting Simple Profitability Ratio Result Using Custom Signal
- Calculating Trendlines on Each Stock Chart
- Calculating Statistical Clusters about Theme and Industry
StockSearcher
,AutoTradingBot
- After the validation process of conditions, that conditions are applied on StockSearcher logic
- The user could find the attractive stocks, and register them on AutoTradingBot
- AutoTradingBot is used to buy registered stocks in cheap price using indicators
-
Technical Contents
-
Screenshots in 'StockDatabase' and 'StockBacktester' Project
- I have saved about a lot of stock datas in File-System database from Korea market (KOSPI, KOSDAQ) until 2023/02/17.
- There are so many informations as like
Stock Price
,Volume
,Adjusted Stock Price
,MarketCap
in each daily data. - Below this, that is the structure of
class diagram
. - Example code is here
- There are so many informations as like
📦Stock
┣ 📂StockInfo // 종목에 대한 정보가 담겨 있음.
┃ ┣ 📂Market
┃ ┃ ┣ 📜Country // ex. "한국주식(키움)", ...
┃ ┃ ┣ 📜Code // ex. 0, 1, 2, ...
┃ ┃ ┣ 📜Name // ex. "코스피", "코스닥", ...
┃ ┃ ┗ 📜Index // Static Variable 에 있는 Country 배열의 Index
┃ ┣ 📜Code // ex. "005930"
┃ ┣ 📜Name // ex. "삼성전자"
┃ ┣ 📜DebutedDate // ex. "20190301" (상장일)
┃ ┗ 📜ActiveSharesRatio // ex. 60.5 (유통비율)
┣ 📂PriceData
┃ ┣ 📂DailyData
┃ ┃ ┣ 📜Date
┃ ┃ ┣ 📜Open // 시가
┃ ┃ ┣ 📜AdjustedOpen // 시가 수정주가
┃ ┃ ┣ 📜High // 고가
┃ ┃ ┣ 📜AdjustedHigh // 고가 수정주가
┃ ┃ ┣ 📜Low // 저가
┃ ┃ ┣ 📜AdjustedLow // 저가 수정주가
┃ ┃ ┣ 📜Close // 종가
┃ ┃ ┣ 📜AdjustedClose // 종가 수정주가
┃ ┃ ┣ 📜Volume // 거래량
┃ ┃ ┣ 📜AdjustedVolume // 수정 거래량
┃ ┃ ┣ 📜Shares // 상장 주식 수
┃ ┃ ┣ 📜MarketCap // 시가총액
┃ ┃ ┣ 📜AdjustedEvent // 수정주가 이벤트 발생 코드 (in Kiwoom API docs)
┃ ┃ ┣ 📜AdjustedRatio // 수정주가 변동 비율
┃ ┃ ┗ 📜CheckAdjusted // 수정주가 변동 여부 확인 column
┃ ┗ 📂WeeklyData
┣ 📜LastUpdatedDate // 마지막 업데이트 날짜
┣ 📜LastAdjustedDate // 마지막 수정주가 변동 날짜
┗ 📜LastAdjustedIndex // 마지막 수정주가 변동 index
Saving of 72% previous processing time
in calculating indicator named Leading Span of Ichimoku
about a data set of 10 million
There are two ways to get the Maximum and Minimum Value in Specific Range to calculate the Leading Span of Ichimoku (n : a number of all daily datas contained every stocks)
-
Calculate the Maximum and Minimum value using the
Linear way
- Whenever the index is changed, try to get a maximum and minimum value
calculating every 52 elements
- It would be needed the time
Θ(52 * n)
to calculate all daily datas on each stock
- Whenever the index is changed, try to get a maximum and minimum value
-
Calculate the Maximum and Minimum value using the
Segment Tree Algorithm
- Before calculating, make a Segment Tree (it needs
Θ(n * log(n))
) - Whenever the index is changed, try to get a maximum and minimum value
using Segment Tree
- It would be needed the time
Θ(log(n) * n)
to calculate all daily datas on each stock
- Before calculating, make a Segment Tree (it needs
-
Θ(52 * n)
vsΘ(log(n) * n)
- I estimated that
n
is the average of having daily datas on each stock n
=9,952,847 daily datas
/2367 stocks
=4204
Θ(52 * n) = 218,608
vsΘ(log(n) * n) = 50,448
- The winner is the
Θ(log(n) * n)
- I estimated that
While developing the logic, I applied the Segment Tree Algorithm
.
As a result, I made a saving of 72% previous processing time
about a data set of 10 million
. (You could see the detailed process in here)
-
Below codes are the examples of searching condition function
// it will return true, when "20 SMA crosses up 60 SMA" using simple moving average "while remaining convergence" public static bool IsCrossUpCandle(ref DailyData[] dailyDatas, ref Indicator[] indicators, int start_index, int index) { if(index <= 0) return false; if(index - start_index < 5) return false; // 1. 20 SMA < 60 SMA * 1.05 float SMA20, SMA60; if(float.TryParse(indicators[index].Values[(int)IndicatorDailyCode.SMA20], out SMA20) && float.TryParse(indicators[index].Values[(int)IndicatorDailyCode.SMA60], out SMA60)) { if(SMA20 < SMA60 * 1.05) { // 2. pivot close CrossUp float close_p = float.Parse(dailyDatas[start_index].AdjustedClose); float close_0 = float.Parse(dailyDatas[index].AdjustedClose); float close_1 = float.Parse(dailyDatas[index - 1].AdjustedClose); if(close_0 > close_p && close_1 < close_p) { return true; } } } return false; }
-
I used
delegate variable
for reducing code complexity when I needed to use a lot of conditional functions.public delegate bool CondFunc(ref DailyData[] dailyDatas, ref Indicator[] indicators, int point_index2, int index); ... // select condFunc using switch operation and so on CondFunc condFunc = IsCrossUpCandle; ... // get daily datas and indicator of stocks bool result = this.condFunc(ref dailyDatas, ref indicators, 5, 0); ... // search and analyze results ... ...
- It could be totally possible to analyze the price patterns of stock using this program with backtesting results.
- Until now, I have studied and analyzed so many stocks and price patterns using this program
- Moreover, I tried to analyze the stock price using
Deep Learning Model
.- You could see on this link
- Update the daily datas automatically
from Kiwoom API and Naver Finance
in asynchronous way
- Backtesting Simulation with many buying/selling strategy as like
SMA Golden-Cross Signal
(on the bottom right)
- Showing the chart of searched backtesting results with many indicators like
trendlines
,theme clusters
-
The source code of this project is saved on private repository, because I worried about the misusing some strategies in this project to their buying / selling decision.
-
Whenever if you have any questions for this project, contact me for anything using email.
- e-mail is here. → dev.taehyeon.kim@gmail.com
Thank you for reading!