Пример #1
0
__author__ = 'Austin Ouyang'

from util.statemachine import StateMachine
from util.transitions import Transitions
from util.backtest import Backtest
from util.setup_backtest import *
import cProfile
import pstats

if __name__ == "__main__":

    m = StateMachine()
    t = Transitions()  # next state functions for state machine

    m.add_state("initialize", t.initialize_transitions)
    m.add_state("load_daily_data", t.load_daily_data_transitions)
    m.add_state("check_orders", t.check_orders_transitions)
    m.add_state("update_range_bar", t.update_range_bar_transitions)
    m.add_state("compute_indicators", t.compute_indicators_transitions)
    m.add_state("check_strategy", t.check_strategy_transitions)
    m.add_state("check_range_bar_finished",
                t.check_range_bar_finished_transitions)
    m.add_state("show_results", t.write_results_transitions)
    m.add_state("finished", None, end_state=1)

    m.set_start("initialize")

    bt = Backtest()
    set_backtest_options(bt)
    cProfile.run('m.run(bt)', 'backtest_profile')
Пример #2
0
__author__ = "Austin Ouyang"

from util.statemachine import StateMachine
from util.transitions import Transitions
from util.backtest import Backtest
from util.setup_backtest import *
import cProfile
import pstats


if __name__ == "__main__":

    m = StateMachine()
    t = Transitions()  # next state functions for state machine

    m.add_state("initialize", t.initialize_transitions)
    m.add_state("load_daily_data", t.load_daily_data_transitions)
    m.add_state("check_orders", t.check_orders_transitions)
    m.add_state("update_range_bar", t.update_range_bar_transitions)
    m.add_state("compute_indicators", t.compute_indicators_transitions)
    m.add_state("check_strategy", t.check_strategy_transitions)
    m.add_state("check_range_bar_finished", t.check_range_bar_finished_transitions)
    m.add_state("show_results", t.write_results_transitions)
    m.add_state("finished", None, end_state=1)

    m.set_start("initialize")

    bt = Backtest()
    set_backtest_options(bt)
    cProfile.run("m.run(bt)", "backtest_profile")
Пример #3
0
def main(*args):
    m = StateMachine()

    t = Transitions()       # next state functions for state machine

    m.add_state("initialize_state", t.initialize_transitions)
    m.add_state("single_unmarked_state", t.single_unmarked_transitions)
    m.add_state("matching_pairs_in_zone_state", t.matching_pairs_in_zone_transitions)
    m.add_state("matching_pairs_in_row_state", t.matching_pairs_in_row_transitions)
    m.add_state("matching_pairs_in_col_state", t.matching_pairs_in_col_transitions)
    m.add_state("single_in_zone_state", t.single_in_zone_transitions)
    m.add_state("single_in_row_state", t.single_in_row_transitions)
    m.add_state("single_in_col_state", t.single_in_col_transitions)
    m.add_state("show_results_state", t.show_results_transitions)
    m.add_state("stuck_state", t.stuck_transitions)
    m.add_state("error_state", t.error_transitions)

    m.add_state("finished_state", None, end_state=1)

    m.set_start("initialize_state")

    if len(args) == 1:
        filename = args[0]
    else:
        if len(args) > 1:
            print "Too many input arguments."

        filename = raw_input("Enter path of csv file: ")

    m.run(filename)
Пример #4
0
    def run_backtest_callback(self):

        m = StateMachine()
        t = Transitions()  # next state functions for state machine

        m.add_state("initialize", t.initialize_transitions)
        m.add_state("load_daily_data", t.load_daily_data_transitions)
        m.add_state("check_orders", t.check_orders_transitions)
        m.add_state("update_range_bar", t.update_range_bar_transitions)
        m.add_state("compute_indicators", t.compute_indicators_transitions)
        m.add_state("check_strategy", t.check_strategy_transitions)
        m.add_state("check_range_bar_finished",
                    t.check_range_bar_finished_transitions)
        m.add_state("show_results", t.write_results_transitions)
        m.add_state("finished", None, end_state=1)

        m.set_start("initialize")

        self.bt.instr_name = str(self.comboBox_instrument.currentText())
        self.bt.RANGE = int(self.spinBox_range.value())

        self.bt.init_day = str(self.dateEdit_start_date.date().toString(
            "yyyy-MM-dd")) + " 17:00:00"
        self.bt.final_day = str(
            self.dateEdit_end_date.date().toString("yyyy-MM-dd")) + " 16:59:59"

        #self.bt.log_intrabar_data = self.checkBox_log_intrabar_data.isChecked()  # setting true can significantly slowdown backtesting
        #self.bt.write_trade_data = self.checkBox_write_trade_data.isChecked()
        #self.bt.trade_data_root = '/home/aouyang1/Dropbox/Futures Trading/FT_QUICKY_v3/BASE (copy)'

        #self.bt.write_bar_data = self.checkBox_write_bar_data.isChecked()
        #self.bt.bar_data_root = '/home/aouyang1/Dropbox/Futures Trading/Backtester/FT_QUICKY_GC_BASE'

        cProfile.runctx('m.run(self.bt)', globals(), locals(),
                        'backtest_profile')
        self.bar_len = self.bt.range_bar.cnt
        self.tabWidget.setTabEnabled(1, True)

        print " "

        p = pstats.Stats('backtest_profile')
        p.strip_dirs().sort_stats('cumulative').print_stats('transitions')

        self.horizontalScrollBar_range_bar.setMaximum(self.bar_len -
                                                      self.bars_in_view)
        self.horizontalScrollBar_range_bar.setPageStep(self.bars_in_view)
        self.horizontalScrollBar_range_bar.setValue(self.bar_len -
                                                    self.bars_in_view)

        self.plot_bars()
Пример #5
0
	def run_backtest_callback(self):

		m = StateMachine()
		t = Transitions()  # next state functions for state machine

		m.add_state("initialize", t.initialize_transitions)
		m.add_state("load_daily_data", t.load_daily_data_transitions)
		m.add_state("check_orders", t.check_orders_transitions)
		m.add_state("update_range_bar", t.update_range_bar_transitions)
		m.add_state("compute_indicators", t.compute_indicators_transitions)
		m.add_state("check_strategy", t.check_strategy_transitions)
		m.add_state("check_range_bar_finished",
					t.check_range_bar_finished_transitions)
		m.add_state("show_results", t.write_results_transitions)
		m.add_state("finished", None, end_state=1)

		m.set_start("initialize")

		self.bt.instr_name = str(self.comboBox_instrument.currentText())
		self.bt.RANGE = int(self.spinBox_range.value())

		self.bt.init_day = str(self.dateEdit_start_date.date().toString(
			"yyyy-MM-dd")) + " 17:00:00"
		self.bt.final_day = str(
			self.dateEdit_end_date.date().toString("yyyy-MM-dd")) + " 16:59:59"

		#self.bt.log_intrabar_data = self.checkBox_log_intrabar_data.isChecked()  # setting true can significantly slowdown backtesting
		#self.bt.write_trade_data = self.checkBox_write_trade_data.isChecked()
		#self.bt.trade_data_root = '/home/aouyang1/Dropbox/Futures Trading/FT_QUICKY_v3/BASE (copy)'

		#self.bt.write_bar_data = self.checkBox_write_bar_data.isChecked()
		#self.bt.bar_data_root = '/home/aouyang1/Dropbox/Futures Trading/Backtester/FT_QUICKY_GC_BASE'

		cProfile.runctx('m.run(self.bt)', globals(), locals(),
						'backtest_profile')
		self.bar_len = self.bt.range_bar.cnt
		self.tabWidget.setTabEnabled(1, True)

		print " "

		p = pstats.Stats('backtest_profile')
		p.strip_dirs().sort_stats('cumulative').print_stats('transitions')

		self.horizontalScrollBar_range_bar.setMaximum(
			self.bar_len - self.bars_in_view)
		self.horizontalScrollBar_range_bar.setPageStep(self.bars_in_view)
		self.horizontalScrollBar_range_bar.setValue(
			self.bar_len - self.bars_in_view)

		self.plot_bars()