Exemple #1
0
    'config.dir'] = "/Users/zhang/PycharmProjects/strategy_engine_v2/interface"
# 如果没有日志目录的话,则创建
if not os.path.exists("log"):
    os.makedirs("log")

from se import BeanContainer, AccountRepo
from se.domain2.account.account import AbstractAccount
import pandas as pd
from trading_calendars import get_calendar

from se.domain2.engine.engine import Engine, Scope
from strategies.strategy import TestStrategy2

engine = Engine()
scope = Scope(["SPCE_STK_USD_SMART"], trading_calendar=get_calendar("NYSE"))
strategy = TestStrategy2(scope)

# 回测
start = pd.Timestamp("2021-02-01", tz='Asia/Shanghai')
end = pd.Timestamp("2021-02-18", tz='Asia/Shanghai')
result = engine.run_backtest(strategy, start, end, 10000, "test60",
                             "ibAdjustedDailyBar")
print("done")

# 查看结果
# repo: AccountRepo = BeanContainer.getBean(AccountRepo)
# account: AbstractAccount = repo.find_one("test56")
# s = pd.Series(account.history_net_value)
# s.plot()
# print("done")
Exemple #2
0
            buy_order = LimitOrder(self.code, OrderDirection.BUY,
                                   dest_quantity - hold_quantity, current_time,
                                   down_price)
            account.place_order(buy_order)

    def __init__(self, scope: Scope, n=5, p=0.02):
        super().__init__(scope)
        self.n = n
        self.p = p
        self.code = scope.codes[0]


# from trading_calendars import get_calendar

# scope = Scope(codes=['CCL_STK_USD_SMART'], trading_calendar=get_calendar("NYSE"))
# start = Timestamp("2020-01-01", tz='Asia/Shanghai')
# end = Timestamp("2020-01-30", tz='Asia/Shanghai')
# Engine().run_backtest(TestStrategy1(scope), start, end, 10000, "test3")

if __name__ == "__main__":
    # 计算策略的回报序列
    from trading_calendars import get_calendar
    import pandas as pd
    calendar = get_calendar("NYSE")
    engine = Engine()
    scope = Scope(['CCL_STK_USD_SMART'], calendar)
    st = TestStrategy1(scope, n=5, p=0.01)
    start = pd.Timestamp("2020-01-01", tz='Asia/Shanghai')
    end = pd.Timestamp("2020-01-30", tz='Asia/Shanghai')
    result = engine.run_backtest(st, start, end, 10000, "test16")
    print("done")
Exemple #3
0
from se.strategies.strategy import TestStrategy2
import pandas as pd

engine = Engine()
scope = Scope(["SPCE_STK_USD_SMART"], trading_calendar=get_calendar("NYSE"))
strategy = TestStrategy2(scope)

# 初始化配置
config_file_name = 'config.ini'
config = ConfigParser()
config.read(config_file_name)

# 回测
start = pd.Timestamp("2020-01-01", tz='Asia/Shanghai')
end = pd.Timestamp("2020-12-01", tz='Asia/Shanghai')
result = engine.run_backtest(strategy, start, end, 10000, "test55")
print("done")

# 实盘测试
# acc = IBAccount("ib_test1", 10000)
#
# # acc_repo: AccountRepo = BeanContainer.getBean(AccountRepo)
# # acc = acc_repo.find_one("ib_test1")
# #
# acc.with_order_callback(strategy).with_client(config.get('ib', 'host'), config.getint('ib', 'port'),
#                                               config.getint('ib', 'client_id'))
#
#
# def mocked_event_generator(event_definition: EventDefinition):
#     if isinstance(event_definition.time_rule, MarketOpen):
#         t = Timestamp("2021-01-21 22:30:00", tz='Asia/Shanghai')