示例#1
0
    def setUp(self):
        self.pubsub = MockRedis()
        self.config = PyConfig("test_config.ini")
        self.symbols = ['GOOG']
        self.strategy = StrategyFactory.create_strategy(
            self.config.get(CONF_ANALYZER_SECTION, CONF_STRATEGY_NAME),
            self.symbols, self.config)

        self.strategy2 = StrategyFactory.create_strategy(
            self.config.get(CONF_ANALYZER_SECTION, CONF_STRATEGY_NAME),
            self.symbols, self.config.getSection(CONF_ANALYZER_SECTION))
示例#2
0
    def setUp(self):
        self.pubsub = MockRedis()
        self.config = PyConfig("test_config.ini")
        self.symbols = ['GOOG']
        self.strategy = StrategyFactory.create_strategy(
                self.config.get(CONF_ANALYZER_SECTION, CONF_STRATEGY_NAME),
                self.symbols,
                self.config)

        self.strategy2 = StrategyFactory.create_strategy(
                self.config.get(CONF_ANALYZER_SECTION, CONF_STRATEGY_NAME),
                self.symbols,
                self.config.getSection(CONF_ANALYZER_SECTION))
示例#3
0
    def _setup_strategy(self):
        """ setup tradingEngine"""
        strategy = StrategyFactory.create_strategy(
            self.config.get(CONF_ANALYZER_SECTION, CONF_STRATEGY_NAME), self.securities, self.config
        )

        # register on trading engine
        # import ipdb; ipdb.set_trace()
        self.trading_engine.register(strategy)
示例#4
0
    redis_conn = StrictRedis(**config)
    engine = create_engine('sqlite://')
    session_factory = sessionmaker(bind=engine)
    Session = scoped_session(session_factory)
    session = Session()

    Base.metadata.create_all(engine)
    usd = Currency(name='Dollar', code='USD')
    nasdaq = Exchange(name='NASDAQ', currency=usd)
    stock_ebay = Stock(symbol='EBAY', exchange=nasdaq, ISIN='US2786421030', description='')

    owner = Owner(name='Lucky')
    broker = Broker(name='Cheap Broker')
    account = Account(owner=owner, broker=broker)
    pesos = Currency(name='Pesos', code='ARG')
    account.deposit(Money(amount=1000, currency=pesos))
    config_file = "backtest_smaPortfolio.ini"
    config = PyConfig(config_file)
    strategy = StrategyFactory.create_strategy(config.get(CONF_ULTRAFINANCE_SECTION, CONF_STRATEGY_NAME),
                                               config.getSection(CONF_ULTRAFINANCE_SECTION))

    th_tick_feeder = BackTesterThread(config, redis_conn, securities=[stock_ebay])

    start = datetime.now()
    end = datetime.now() - timedelta(days=30)
    th_trading_engine = TradingEngineThread(redis_conn.pubsub(), securities=[stock_ebay], strategy=strategy)

    th_tick_feeder.start()
    th_trading_engine.start()
    Session.remove()
示例#5
0
    usd = Currency(name='Dollar', code='USD')
    nasdaq = Exchange(name='NASDAQ', currency=usd)
    stock_ebay = Stock(symbol='EBAY',
                       exchange=nasdaq,
                       ISIN='US2786421030',
                       description='')

    owner = Owner(name='Lucky')
    broker = Broker(name='Cheap Broker')
    account = Account(owner=owner, broker=broker)
    pesos = Currency(name='Pesos', code='ARG')
    account.deposit(Money(amount=1000, currency=pesos))
    config_file = "backtest_smaPortfolio.ini"
    config = PyConfig(config_file)
    strategy = StrategyFactory.create_strategy(
        config.get(CONF_ULTRAFINANCE_SECTION, CONF_STRATEGY_NAME),
        config.getSection(CONF_ULTRAFINANCE_SECTION))

    th_tick_feeder = TickFeederThread(config,
                                      redis_conn,
                                      securities=[stock_ebay])

    start = datetime.now()
    end = datetime.now() - timedelta(days=30)
    th_trading_engine = TradingEngineThread(redis_conn.pubsub(),
                                            securities=[stock_ebay],
                                            strategy=strategy)

    th_tick_feeder.start()
    th_trading_engine.start()
    Session.remove()