Esempio n. 1
0
 def setUp(self):
     """
     Set up the PortfolioHandler object supplying it with
     $500,000.00 USD in initial cash.
     """
     initial_cash = Decimal("500000.00")
     events_queue = queue.Queue()
     price_handler = PriceHandlerMock()
     position_sizer = PositionSizerMock()
     risk_manager = RiskManagerMock()
     # Create the PortfolioHandler object from the rest
     self.portfolio_handler = PortfolioHandler(initial_cash, events_queue,
                                               price_handler,
                                               position_sizer, risk_manager)
Esempio n. 2
0
    price_handler = HistoricCSVPriceHandler(
        csv_dir, events_queue, tickers
    )

    # Use the Test Strategy
    strategy = TestStrategy( tickers, events_queue )

    # Use an example Position Sizer
    position_sizer = TestPositionSizer()

    # Use an example Risk Manager
    risk_manager = TestRiskManager()

    # Use the default Portfolio Handler
    portfolio_handler = PortfolioHandler(
        initial_equity, events_queue, price_handler,
        position_sizer, risk_manager
    )

    # Use a simulated IB Execution Handler
    execution_handler = IBSimulatedExecutionHandler(
        events_queue, price_handler
    )

    # Use the default Statistics
    statistics = SimpleStatistics(portfolio_handler)

    # Set up the backtest
    backtest = Backtest(
        tickers, price_handler,
        strategy, portfolio_handler,
        execution_handler,