검색결과 리스트
시스템 트레이딩에 해당되는 글 2건
- 2016.09.23 나만의 로보 어드바이저(robo-advisor) 만들기 [5]
- 2016.09.05 나만의 로보 어드바이저(robo-advisor) 만들기 [3]
글
오늘은 Python과 CybosPlus를 이용하여 장중 실시간 종목 가격 변동을 모니터링하고 특정 조건(매수 혹은 매도가 도달)만족시 이벤트를 생성하는 방법을 알아보자.
먼저 첨부된 python 코드는, 깔끔하지는 않지만, 장중 정해준 종목을 계속 모니터링하다가 정해진 이벤트(트레이딩)이 발생할 경우 발생한 트레이딩 정보와 변동률을 화면에 뿌려주는 기능을 한다.
이 코드를 조금 수정하면 이벤트가 발생한 경우에 사용자 펑션 호출하여 원하는 조건(매수 혹은 매도 조건 도달, 특정 가격이상 변동, 급작스런 가격변동 탐지등)을 만족하는가를 체크하고 만족하는 경우 특정 행동을 하도록 할 수 있을것이다.
특정 조건 만족시 매수, 혹은 매도를 실행하는 코드를 추가하면 실시간 트레이딩이 가능해지는데 이 부분은 다음 시간에 다루기로 한다.
코드 설명:
__author__ = 'Dr. Deeeep'
import win32com.client
import io
""" Memo
02: change rate
13: currentprice
18: currenttime
"""
activeFlag = [ 1, 1, 0, 0, 0, 0, 0]
itemcode = ['A017680','A052790','A032860', 'A900110', 'A033130']
############### deco, actoz, steel, EAH, cho
crArray = [ '', '', '', '', '', '']
class CpEvent0:
#print("E0: flag=", activeFlag[0])
instance = None
def OnReceived(self):
#print("E0: flag=", activeFlag[0])
if (activeFlag[0]>0):
currentprice = CpEvent0.instance.GetHeaderValue(13)
changeprice = CpEvent0.instance.GetHeaderValue(2)
changerate = round(((changeprice / (currentprice - changeprice)) * 100.0),2)
crArray[0] = changerate
prt_style_all(0, changerate, currentprice, changeprice)
#prt_style(0, changerate, currentprice, changeprice)
#print(itemcode[0], " ", changerate, " E0: ", currentprice, " ", changeprice);
class CpEvent1:
#print("E1: flag=", activeFlag[1])
instance = None
def OnReceived(self):
#print("E1: flag=", activeFlag[1])
if (activeFlag[1]>0):
currentprice = CpEvent1.instance.GetHeaderValue(13)
changeprice = CpEvent1.instance.GetHeaderValue(2)
changerate = round(((changeprice / (currentprice - changeprice)) * 100.0),2)
crArray[1] = changerate
prt_style_all(1, changerate, currentprice, changeprice)
#prt_style(1, changerate, currentprice, changeprice)
#print(itemcode[1], " ", changerate, " E1: ", currentprice, " ", changeprice);
class CpEvent2:
#print("E2: flag=", activeFlag[2])
instance = None
def OnReceived(self):
#print("E2: flag=", activeFlag[2])
if (activeFlag[2]>0):
currentprice = CpEvent2.instance.GetHeaderValue(13)
changeprice = CpEvent2.instance.GetHeaderValue(2)
changerate = round(((changeprice / (currentprice - changeprice)) * 100.0),2)
crArray[2] = changerate
prt_style_all(2, changerate, currentprice, changeprice)
#prt_style(2, changerate, currentprice, changeprice)
#print(itemcode[2], " ", changerate, " E2: ", currentprice, " ", changeprice);
class CpEvent3:
#print("E3: flag=", activeFlag[3])
instance = None
def OnReceived(self):
#print("E3: flag=", activeFlag[3])
if (activeFlag[3]>0):
currentprice = CpEvent3.instance.GetHeaderValue(13)
changeprice = CpEvent3.instance.GetHeaderValue(2)
changerate = round(((changeprice / (currentprice - changeprice)) * 100.0),2)
crArray[3] = changerate
prt_style_all(3, changerate, currentprice, changeprice)
#prt_style(3, changerate, currentprice, changeprice)
#print(itemcode[3], " ", changerate, " E3: ", currentprice, " ", changeprice);
class CpEvent4:
#print("E4: flag=", activeFlag[4])
instance = None
def OnReceived(self):
#print("E4: flag=", activeFlag[4])
if (activeFlag[4]>0):
currentprice = CpEvent4.instance.GetHeaderValue(13)
changeprice = CpEvent4.instance.GetHeaderValue(2)
changerate = round(((changeprice / (currentprice - changeprice)) * 100.0),2)
crArray[4] = changerate
prt_style_all(4, changerate, currentprice, changeprice)
#prt_style(4, changerate, currentprice, changeprice)
#print(itemcode[4], " ", changerate, " E4: ", currentprice, " ", changeprice);
def prt_style_all(classnum, chrate, curprice, chprice):
print(classnum, ", ", enter_crArray(), curprice, ",", chprice)
def prt_style(classnum, chrate, curprice, chprice):
print(classnum, enter_spc(classnum), chrate, ",", exit_spc(classnum), ",", curprice, ",", chprice)
#print(itemcode[classnum], enter_spc(classnum), chrate, ", ", curprice, ", ", chprice)
def enter_crArray():
crnum = len(crArray)
rtnline = ""
for n in range(0, crnum):
rtnline = rtnline + str(crArray[n]) + ","
return rtnline
def enter_spc(classn):
spc = ""
for n in range(0, classn):
spc = spc + " "
return spc
def exit_spc(classn):
spc = ""
rev = 4 - classn
for n in range(0, rev):
spc = spc + " "
return spc
#not working
def sprintf(buf, fmt, args):
buf.write(fmt % args)
inst0 = win32com.client.Dispatch("dscbo1.StockCur")
inst1 = win32com.client.Dispatch("dscbo1.StockCur")
inst2 = win32com.client.Dispatch("dscbo1.StockCur")
inst3 = win32com.client.Dispatch("dscbo1.StockCur")
inst4 = win32com.client.Dispatch("dscbo1.StockCur")
win32com.client.WithEvents(inst0, CpEvent0)
win32com.client.WithEvents(inst1, CpEvent1)
win32com.client.WithEvents(inst2, CpEvent2)
win32com.client.WithEvents(inst3, CpEvent3)
win32com.client.WithEvents(inst4, CpEvent4)
inst0.SetInputValue(0,itemcode[0])
inst1.SetInputValue(0,itemcode[1])
inst2.SetInputValue(0,itemcode[2])
inst3.SetInputValue(0,itemcode[3])
inst4.SetInputValue(0,itemcode[4])
CpEvent0.instance = inst0
CpEvent1.instance = inst1
CpEvent2.instance = inst2
CpEvent3.instance = inst3
CpEvent4.instance = inst4
inst0.Subscribe()
inst1.Subscribe()
inst2.Subscribe()
inst3.Subscribe()
inst4.Subscribe()
이벤트 발생시 해당 종목의 가격을 체크하여 정해진 STOPLOSS 보다 작거나 STOPGAIN보다 큰 경우 적절한 행동을 하도록 하려면 다음과 같은 class를 정해주면 된다.
class CpEvent000:
instance = None
monitoring = 1 # 0 no, 1 yes
def OnReceived(self):
if (monitoring = 1)
value13_cprice = CpEvent1.instance.GetHeaderValue(13)
value18_ctime = CpEvent1.instance.GetHeaderValue(18)
print("E1: ",value18_ctime,", ", value13_cprice)
if (value13_cprice >= stopgain_price)
print("E1: STOPGAIN, Exit")
monitoring = 0 # 정해진 일을 이곳에 코딩
elif (value13_cprice <= stoploss_price)
print("E1: STOPLOASS, Exit")
monitoring = 0 # 정해진 일을 이곳에 코딩
<to be continued..>
'금융' 카테고리의 다른 글
PER을 활용한 주식투자 전략: 중고급 투자자를 위한 가이드 (0) | 2024.02.13 |
---|---|
PBR을 활용한 주식투자 전략: 중고급 투자자를 위한 가이드 (0) | 2024.02.13 |
나만의 로보 어드바이저(robo-advisor) 만들기 [4] (0) | 2016.09.05 |
나만의 로보 어드바이저(robo-advisor) 만들기 [2] (0) | 2016.08.30 |
딥러닝 for 트레이딩 (0) | 2016.08.18 |
글
Time Series Prediction을 위한 Deep learning
이번 글에서는 주가 예측의 기본 개념인 time series prediction 을 딥러닝 기술로 구현하는 방법에 대해 알아보도록 하겠다.
위 그림은 구글 이미지 검색에서 time series prediction 으로 검색을 해서 찾아낸 그림 중 하나인데, 오늘 설명할 deep learning을 이용한 time series prediction의 개념을 쉽게 도식화 한 것이다.
time series 데이터란 시간 축에 따라 변하는 데이터를 (시간,값)의 형태로 쭉 기록한 데이터를 말하는데 주가 데이터, 뇌파 데이터, 기온 데이터 등이 이에 해당한다. 주가 데이터라면 x 축이 시간(월, 일, 주, 시, 초 등)이고 y 축이 주가 데이터(주가, 거래량, 변동률 등등)이 되겠다.
time series prediction의 가장 대표적인 알로리즘은 일정 기간의 데이터를 관찰하고 바로 다음 순간의 값을 예측하는 것이다.
<to be continued...>
'상념' 카테고리의 다른 글
딥러닝에서 Epoch의 중요성 (0) | 2016.09.29 |
---|---|
Common deep learning predictive modeling problem types (0) | 2016.09.13 |
나만의 로보 어드바이저(robo-advisor) 만들기 [1] (0) | 2016.08.30 |
ECCB 2016 app (0) | 2016.08.28 |
도메인을 하나 더 구입했는데.. (0) | 2016.08.24 |
RECENT COMMENT