| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 파이썬
- 삼각함수의그래프
- 피타고라스 정리
- 작도
- 확률실험
- 프로젝트 오일러
- 큰 수의 법칙
- 시뮬레이션
- 재귀함수
- 프랙탈
- 제곱근의뜻
- 지오지브라
- 오일러
- 몬테카를로
- 블록코딩
- 큰수의법칙
- java
- 상합
- 하합
- Geogebra
- counting sunday
- 이항분포
- 정오각형
- algeomath
- 수학탐구
- 리만합
- project euler
- 구분구적법
- 알지오매스
- python
Archives
- Today
- Total
이경수 선생님의 수학실험실
1년동안 수익률 -23% 이상을 경험한 종목의 비중은 얼마나 될까? 본문
1년동안 수익률 -23% 이상을 경험한 종목들의 비중을 연도별로 알아 보았습니다.
2014년 26.62%, 2015년 22.52%의 종목이 -23% 이상의 수익률을 경험하였고,
2016년은 -23% 수익률을 경험한 종목이 다른 해(2014, 2015)보다 높게 나타난 것을 볼 수 있습니다.
개발환경
kiwoom OpenAPI+
python3.5
sqlite3
import sqlite3
import sqlite3
from Kiwoom import *
from PyQt5.QtWidgets import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc
from matplotlib import style
MARKET_KOSPI = 0
MARKET_KOSDAK = 10
class Down23:
def run(self):
#self.input_codes()
#self.check_down()
self.draw_chart()
def input_codes(self):
self.kiwoom = Kiwoom()
self.kiwoom.CommConnect()
self.kospi_code = self.kiwoom.GetCodeListByMarket(MARKET_KOSPI)
self.kosdak_code = self.kiwoom.GetCodeListByMarket(MARKET_KOSDAK)
# Get 'code' data
codes = []
for cd in self.kospi_code:
codes.append(cd)
for cd in self.kosdak_code:
codes.append(cd)
con = sqlite3.connect("C:\\Users\\Kyoungsoo\\PycharmProjects\\Analysis\\stock_info.db")
cursor = con.cursor()
cursor.execute("DROP TABLE Codes1701")
cursor.execute("CREATE TABLE Codes1701(Code text, Codename text)")
for code in codes:
name = self.kiwoom.dynamicCall("GetMasterCodeName(QString)", code)
cursor.execute("INSERT INTO Codes1701(Code, Codename) VALUES(?, ?)", (code, name))
con.commit()
con.close()
def check_down(self, success = 0, fail = 0, sf = 0):
start_day = '2016-01-01'
end_day = '2016-12-31'
# Database connect
con = sqlite3.connect("C:\\Users\\Kyoungsoo\\PycharmProjects\\Analysis\\stock_info.db")
cursor = con.cursor()
#cursor.execute(("DROP TABLE down23"))
#cursor.execute("CREATE TABLE down23(Code text, StartDate text, EndDate text, SDPrice int, MinPrice int, SF int)")
cursor.execute("SELECT Code From Codes1701")
rows = cursor.fetchall()
codes = []
for row in rows:
codes.append(row[0])
for cd in codes:
code = '"' + cd + '"'
cursor.execute("SELECT Close FROM opt_10081 "
"WHERE opt_10081.Code = " + code + " and Date BETWEEN " + '"' + start_day + '"' + " AND " + '"' + end_day + '"'
"ORDER BY opt_10081.Date asc")
rows = cursor.fetchall()
try:
price = []
for row in rows:
price.append(row[0])
start_day_price = price[0]
min_price = min(price)
if start_day_price * 0.77 >= min_price:
success += 1
sf = 1
else:
fail += 1
sf = 0
except:
start_day_price = 0
min_price = 0
sf = 2
# Insert data
cursor.execute("INSERT INTO down23(Code, StartDate, EndDate, SDPrice, MinPrice, SF) "
"VALUES(?,?,?,?,?,?)",
(cd, start_day, end_day, start_day_price, min_price, sf))
print(cd, start_day, end_day, start_day_price, min_price, sf)
con.commit()
con.close()
def draw_chart(self):
start_day = '2016-01-01'
font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name()
rc('font', family=font_name)
style.use('ggplot')
# Database connect
con = sqlite3.connect("C:\\Users\\Kyoungsoo\\PycharmProjects\\Analysis\\stock_info.db")
cursor = con.cursor()
cursor.execute("SELECT SF FROM down23 WHERE StartDate= " + '"' + start_day + '"')
rows = cursor.fetchall()
sfs = []
for row in rows:
sfs.append(row[0])
s_count = sfs.count(1)
f_count = sfs.count(0)
s_rate = s_count / (s_count + f_count)
f_rate = f_count / (s_count + f_count)
s_rate = round(s_rate * 100, 2)
f_rate = round(f_rate * 100, 2)
item = ['77% 이하', '77% 초과']
rate = [s_rate, f_rate]
fig = plt.figure(figsize=(4, 6))
ax = fig.add_subplot(1, 1, 1)
pos = np.arange(2)
rects = plt.bar(pos, rate, align='center', width=0.5, color='r')
plt.xticks(pos, item)
for i, rect in enumerate(rects):
ax.text(rect.get_x() + rect.get_width() / 2.0, 0.90 * rect.get_height(), str(rate[i]) + '%',
ha='center')
plt.ylabel('비율(%)')
plt.title(start_day + ' 기준 1년 이내 최저 종가')
plt.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
down23 = Down23()
down23.run()
'Algorithm Trading' 카테고리의 다른 글
| 과거 10년간 n% 상승을 경험한 종목의 비중은 어떻게 될까?(KOSPI) (0) | 2017.02.21 |
|---|---|
| 2017년 1월 주가순자산비율(PBR)의 분포는 어떤 모양일까? (0) | 2017.02.01 |
| 2017년 1월 주가수익률(PER)의 분포는 어떤 모양일까? (0) | 2017.01.31 |
| 1년동안 30% 이상의 수익률을 경험한 종목의 비중은 얼마나 될까? (0) | 2017.01.26 |
Comments