コード例 #1
0
ファイル: transitions.py プロジェクト: simhaonline/Futures
    def initialize_transitions(self, bt):

        self.backtest_start_time = time.time()

        bt.table_name = bt.instr_name + '_LAST_COMPRESSED'

        start_stamp = pd.Timestamp(bt.init_day).tz_localize('US/Central')
        bt.start_stamp_utc = start_stamp.tz_convert('utc')

        final_stamp = pd.Timestamp(bt.final_day).tz_localize('US/Central')
        bt.final_stamp_utc = final_stamp.tz_convert('utc')

        self.num_bdays = len(
            pd.bdate_range(bt.start_stamp_utc, bt.final_stamp_utc))

        bt.futures_db = FuturesDatabase()
        bt.range_bar = RangeBar(bt.instr_name, bt.RANGE)
        bt.daily_tick = DailyTick()
        set_strategies(bt)
        Transitions.determine_optimization(bt)

        print "Backtest start time: {}".format(
            pd.Timestamp(datetime.datetime.now()))
        print "------------------------------------------------"
        print "Instrument: {}".format(bt.instr_name)
        print "     Range: {}".format(bt.RANGE)
        print "     Start: {}".format(bt.init_day)
        print "       End: {}".format(bt.final_day)
        print "------------------------------------------------"

        new_state = "load_daily_data"

        return new_state, bt
コード例 #2
0
instr_name = 'ZB'
TICK_SIZE = 1/32.0
init_day = '2013-09-01 17:00:00'
final_day = '2014-11-30 16:59:59'

table_name = instr_name + '_LAST'
compressed_table_name = table_name + '_COMPRESSED'

start_stamp = pd.Timestamp(init_day).tz_localize('US/Central')
start_stamp_utc = start_stamp.tz_convert('utc')

final_stamp = pd.Timestamp(final_day).tz_localize('US/Central')
final_stamp_utc = final_stamp.tz_convert('utc')

futures_db = FuturesDatabase()

futures_db.drop_table_if_exist(compressed_table_name)
futures_db.create_historical_table(compressed_table_name)

df_compressed = DataFrame(columns=['Date', 'Last', 'Volume'])

while start_stamp_utc < final_stamp_utc:

    start_date = timestamp_to_SQLstring(start_stamp_utc)

    # get end of day timestamp
    end_stamp_utc = start_stamp_utc + Day() - 45*Minute()

    end_date = timestamp_to_SQLstring(end_stamp_utc)
コード例 #3
0
instr_name = 'ZB'
TICK_SIZE = 1 / 32.0
init_day = '2013-09-01 17:00:00'
final_day = '2014-11-30 16:59:59'

table_name = instr_name + '_LAST'
compressed_table_name = table_name + '_COMPRESSED'

start_stamp = pd.Timestamp(init_day).tz_localize('US/Central')
start_stamp_utc = start_stamp.tz_convert('utc')

final_stamp = pd.Timestamp(final_day).tz_localize('US/Central')
final_stamp_utc = final_stamp.tz_convert('utc')

futures_db = FuturesDatabase()

futures_db.drop_table_if_exist(compressed_table_name)
futures_db.create_historical_table(compressed_table_name)

df_compressed = DataFrame(columns=['Date', 'Last', 'Volume'])

while start_stamp_utc < final_stamp_utc:

    start_date = timestamp_to_SQLstring(start_stamp_utc)

    # get end of day timestamp
    end_stamp_utc = start_stamp_utc + Day() - 45 * Minute()

    end_date = timestamp_to_SQLstring(end_stamp_utc)
コード例 #4
0
__author__ = 'MOLTRES'

import os
import datetime

import pandas as pd

from util.futuresdatabase import FuturesDatabase


instrument_list = ['GC', 'CL', 'ZB']

futures_db = FuturesDatabase()

for instrument in instrument_list:
    table_name = instrument + '_LAST'

    futures_db.drop_table_if_exist(table_name)

    futures_db.create_historical_table(table_name)

    rootPath = "/home/aouyang1/NinjaTrader/TickData/" + instrument
    folders = os.listdir(rootPath)

    fnames = os.listdir(rootPath)
    for fileNames in fnames:
        print fileNames
        df = pd.read_csv(rootPath + '/' + fileNames, delimiter=";", names=['Date', 'Last', 'Volume'], parse_dates=[0],
                         date_parser=lambda x: datetime.datetime.strptime(x, '%Y%m%d %H%M%S'))

        futures_db.upload_dataframe_to_table(df, table_name)
コード例 #5
0
__author__ = 'MOLTRES'

import os
import datetime

import pandas as pd

from util.futuresdatabase import FuturesDatabase

instrument_list = ['GC', 'CL', 'ZB']

futures_db = FuturesDatabase()

for instrument in instrument_list:
    table_name = instrument + '_LAST'

    futures_db.drop_table_if_exist(table_name)

    futures_db.create_historical_table(table_name)

    rootPath = "/home/aouyang1/NinjaTrader/TickData/" + instrument
    folders = os.listdir(rootPath)

    fnames = os.listdir(rootPath)
    for fileNames in fnames:
        print fileNames
        df = pd.read_csv(rootPath + '/' + fileNames,
                         delimiter=";",
                         names=['Date', 'Last', 'Volume'],
                         parse_dates=[0],
                         date_parser=lambda x: datetime.datetime.strptime(
コード例 #6
0
                   'ft_quicky',
                   'ft_quicky_base']

rootname_list = ["/home/aouyang1/Dropbox/Futures Trading/FTKGC_v5/PL",
                 "/home/aouyang1/Dropbox/Futures Trading/FT_QUICKY_v3/GC/CON1/PL",
                 "/home/aouyang1/Dropbox/Futures Trading/FT_QUICKY_v3/GC/BASE/PL"]

plrange_list = [range(13, 22, 2),
                range(11, 41),
                range(11, 41)]

col_names = ['PL', 'TradeNum', 'Instrument', 'Account', 'Strategy', 'Market_pos', 'Quantity',
             'Entry_price', 'Exit_price', 'Entry_time', 'Exit_time', 'Entry_name', 'Exit_name',
             'Profit', 'Cum_profit', 'Commission', 'MAE', 'MFE', 'ETD', 'Bars']

fdb = FuturesDatabase()

for table_name, rootname, plrange in zip(table_name_list, rootname_list, plrange_list):
    #ipdb.set_trace()
    fdb.drop_table_if_exist(table_name)

    fdb.create_PL_table(table_name)

    for PL in plrange:
        rootPath = rootname + str(PL)
        filelist = os.listdir(rootPath)

        for fname in filelist:
            try:
                df = pd.read_csv(rootPath + '/' + fname, parse_dates=[8, 9],
                             date_parser=lambda x: datetime.datetime.strptime(x, '%m/%d/%Y %I:%M:%S %p'))