예제 #1
0
# 建立部位管理物件
OrderRecord = Record()

# 取得回測參數
StartDate = sys.argv[1]
EndDate = sys.argv[2]
# 每日進場標記、高低點判斷
LastOrderDay = ''
CeilPrice = {}
FloorPrice = {}
Spread = {}
StopLoss = 30
TakeProfit = 70

# 回測取報價物件
KBar = GOrder.GetTAKBar(StartDate, EndDate, 'TXF', 'Future', '1', '1')
# 開始回測
for n in range(0, len(KBar['time'])):
    # 將日期取出
    Date = KBar['time'][n].strftime('%Y%m%d')
    # 如果無未平倉部位 並時間為指定的進場時間 則進場
    if OrderRecord.GetOpenInterest() == 0:
        # 在9點15 判斷當日高低點
        if KBar['time'][n].strftime('%H%M') <= "0916":
            # 新的一天則新增一組key
            if Date not in CeilPrice.keys():
                CeilPrice[Date] = KBar['high'][n]
                FloorPrice[Date] = KBar['low'][n]
                Spread[Date] = (CeilPrice[Date] - FloorPrice[Date]) * 0.2
            else:
                CeilPrice[Date] = max(CeilPrice[Date], KBar['high'][n])
예제 #2
0
# 建立部位管理物件
OrderRecord=Record() 

# 取得回測參數
StartDate=sys.argv[1]
EndDate=sys.argv[2]
# 每日進場標記、高低點判斷
LastOrderDay=''
CeilPrice={}
FloorPrice={}
Spread={}
MoveStopLoss=0.02

# 回測取報價物件
KBar=GOrder.GetTAKBar(StartDate,EndDate,'3008','Stock','1','1')
# 開始回測
for n in range(0,len(KBar['time'])):
    # 將日期取出
    Date=KBar['time'][n].strftime('%Y%m%d')
    # 如果無未平倉部位 並時間為指定的進場時間 則進場
    if OrderRecord.GetOpenInterest()==0 :
        # 在9點15 判斷當日高低點
        if KBar['time'][n].strftime('%H%M') <= "0916" :
            # 新的一天則新增一組key
            if Date not in CeilPrice.keys():
                CeilPrice[Date] = KBar['high'][n]
                FloorPrice[Date] = KBar['low'][n]
                Spread[Date]=(CeilPrice[Date]-FloorPrice[Date])*0.2
            else:
                CeilPrice[Date] = max(CeilPrice[Date],KBar['high'][n])
예제 #3
0
# 載入必要模組
from haohaninfo import GOrder
from chart import ChartKBar_MA
import sys

# 取得回測參數
Excgange = sys.argv[1]
Product = sys.argv[2]
StartDate = sys.argv[3]
EndDate = sys.argv[4]
Klen = sys.argv[5]
LongPeriod = int(sys.argv[6])
ShortPeriod = int(sys.argv[7])

# 登入帳號密碼(讀者須修正該帳號密碼為自己的,否則無法執行策略)
GOrder.Login('TestAccount', 'TestPasswd')

# K線物件
KBar = GOrder.GetTAKBar(StartDate, EndDate, Product, Excgange, '0', Klen)

# 繪製K線圖加上MA線圖
ChartKBar_MA(KBar, LongPeriod, ShortPeriod)