Esempio n. 1
0
# -*- coding: UTF-8 -*-

# 載入相關套件及函數
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
import backtest_function

# 取得歷史資料
Data = backtest_function.GetI020()

# 透過迴圈取得每天的資料
for date in backtest_function.GetDate(Data):

    # 取得當日的時間
    I020 = [line for line in Data if line[0] == date]

    # 取得轉換時間字串至時間格式
    Time = [
        datetime.datetime.strptime(line[0] + ' ' + line[1], "%Y%m%d %H%M%S%f")
        for line in I020
    ]

    # 價格由字串轉數值
    Price = [int(line[3]) for line in I020]

    # 數量由字串轉數值
    Qty = [int(line[4]) for line in I020]

    # 取得內外盤差額
    BSPower = 0
Esempio n. 2
0
# -*- coding: UTF-8 -*-

# 載入相關套件及函數
import backtest_function
# 取I020(成交資料)
I020 = backtest_function.GetI020()

# 定義停利停損點數
TakeProfit = 30
StopLoss = 10

# 開始回測
for date in backtest_function.GetDate(I020):
    # 取當日資料
    Data = [i for i in I020 if i[0] == date]
    # 取當日9:00前的價格資料
    Data1 = [int(i[3]) for i in Data if int(i[1]) < 90000000000]
    # 取當日9:00~11:00資料
    Data2 = [
        i for i in Data
        if int(i[1]) >= 90000000000 and int(i[1]) <= 110000000000
    ]
    # 定義上下界
    ceil = max(i for i in Data1)
    floor = min(i for i in Data1)
    # 倉位為0
    index = 0
    # 開始判斷
    for i in range(len(Data2)):
        # 當前時間、價格
        time = Data2[i][1]