当前位置: 首页>>代码示例>>Python>>正文


Python PriceParser.parse方法代码示例

本文整理汇总了Python中qstrader.price_parser.PriceParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python PriceParser.parse方法的具体用法?Python PriceParser.parse怎么用?Python PriceParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qstrader.price_parser.PriceParser的用法示例。


在下文中一共展示了PriceParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def setUp(self):
     """
     Set up the Position object that will store the PnL.
     """
     self.position = Position(
         "BOT", "XOM", 100,
         PriceParser.parse(74.78), PriceParser.parse(1.00),
         PriceParser.parse(74.78), PriceParser.parse(74.80)
     )
开发者ID:femtotrader,项目名称:qstrader,代码行数:11,代码来源:test_position.py

示例2: test_open_short_position

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
    def test_open_short_position(self):
        self.assertEqual(PriceParser.display(self.position.cost_basis), -7768.00)
        self.assertEqual(PriceParser.display(self.position.market_value), -7769.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), -1.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), -1.0)

        self.position.update_market_value(
            PriceParser.parse(77.72), PriceParser.parse(77.72)
        )

        self.assertEqual(PriceParser.display(self.position.cost_basis), -7768.00)
        self.assertEqual(PriceParser.display(self.position.market_value), -7772.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), -4.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), -4.0)
开发者ID:femtotrader,项目名称:qstrader,代码行数:16,代码来源:test_position.py

示例3: test_calculate_round_trip

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
    def test_calculate_round_trip(self):
        """
        After the subsequent sale, carry out two more sells/shorts
        and then close the position out with two additional buys/longs.

        The following prices have been tested against those calculated
        via Interactive Brokers' Trader Workstation (TWS).
        """
        self.position.transact_shares(
            "SLD", 100, PriceParser.parse(77.68), PriceParser.parse(1.00)
        )
        self.position.transact_shares(
            "SLD", 50, PriceParser.parse(77.70), PriceParser.parse(1.00)
        )
        self.position.transact_shares(
            "BOT", 100, PriceParser.parse(77.77), PriceParser.parse(1.00)
        )
        self.position.transact_shares(
            "BOT", 150, PriceParser.parse(77.73), PriceParser.parse(1.00)
        )
        self.position.update_market_value(
            PriceParser.parse(77.72), PriceParser.parse(77.72)
        )

        self.assertEqual(self.position.action, "SLD")
        self.assertEqual(self.position.ticker, "PG")
        self.assertEqual(self.position.quantity, 0)

        self.assertEqual(self.position.buys, 250)
        self.assertEqual(self.position.sells, 250)
        self.assertEqual(self.position.net, 0)
        self.assertEqual(
            PriceParser.display(self.position.avg_bot, 3), 77.746
        )
        self.assertEqual(
            PriceParser.display(self.position.avg_sld, 3), 77.688
        )
        self.assertEqual(PriceParser.display(self.position.total_bot), 19436.50)
        self.assertEqual(PriceParser.display(self.position.total_sld), 19422.00)
        self.assertEqual(PriceParser.display(self.position.net_total), -14.50)
        self.assertEqual(PriceParser.display(self.position.total_commission), 5.00)
        self.assertEqual(PriceParser.display(self.position.net_incl_comm), -19.50)

        self.assertEqual(
            PriceParser.display(self.position.avg_price, 5), 77.67600
        )
        self.assertEqual(PriceParser.display(self.position.cost_basis), 0.00)
        self.assertEqual(PriceParser.display(self.position.market_value), 0.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), 0.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), -19.50)
开发者ID:femtotrader,项目名称:qstrader,代码行数:52,代码来源:test_position.py

示例4: test_price_from_long

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def test_price_from_long(self):
     parsed = PriceParser.parse(self.long)
     self.assertEqual(parsed, 200)
     if PY2:
         self.assertIsInstance(parsed, long)  # noqa
     else:
         self.assertIsInstance(parsed, int)
开发者ID:mhallsmoore,项目名称:qstrader,代码行数:9,代码来源:test_priceparser.py

示例5: run

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
def run(config, testing, tickers, filename):

    # Benchmark ticker
    benchmark = 'SP500TR'

    # Set up variables needed for backtest
    title = [
        'Moving Average Crossover Example',
        __file__,
        ','.join(tickers) + ': 100x400'
    ]
    events_queue = queue.Queue()
    csv_dir = config.CSV_DATA_DIR
    initial_equity = PriceParser.parse(500000.00)

    # Use Yahoo Daily Price Handler
    price_handler = YahooDailyCsvBarPriceHandler(
        csv_dir, events_queue, tickers
    )

    # Use the MAC Strategy
    strategy = MovingAverageCrossStrategy(tickers, events_queue)

    # Use an example Position Sizer,
    position_sizer = FixedPositionSizer()

    # Use an example Risk Manager,
    risk_manager = ExampleRiskManager()

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

    # Use the ExampleCompliance component
    compliance = ExampleCompliance(config)

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

    # Use the default Statistics
    statistics = TearsheetStatistics(
        config, portfolio_handler, title, benchmark
    )

    # Set up the backtest
    backtest = Backtest(
        price_handler, strategy,
        portfolio_handler, execution_handler,
        position_sizer, risk_manager,
        statistics, initial_equity
    )
    results = backtest.simulate_trading(testing=testing)
    statistics.save(filename)
    return results
开发者ID:mhallsmoore,项目名称:qstrader,代码行数:60,代码来源:mac_backtest_tearsheet.py

示例6: run

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
def run(cache_name, cache_backend, expire_after, data_source, start, end, config, testing, tickers, filename, n, n_window):

    # Set up variables needed for backtest
    events_queue = queue.Queue()
    initial_equity = PriceParser.parse(500000.00)

    session = init_session(cache_name, cache_backend, expire_after)

    period = 86400  # Seconds in a day

    if len(tickers) == 1:
        data = web.DataReader(tickers[0], data_source, start, end, session=session)
    else:
        data = web.DataReader(tickers, data_source, start, end, session=session)

    # Use Generic Bar Handler with Pandas Bar Iterator
    price_event_iterator = PandasBarEventIterator(data, period, tickers[0])
    price_handler = GenericPriceHandler(events_queue, price_event_iterator)

    # Use the Display Strategy
    strategy1 = DisplayStrategy(n=n, n_window=n_window)
    strategy2 = BuyAndHoldStrategy(tickers, events_queue)
    strategy = Strategies(strategy1, strategy2)

    # Use an example Position Sizer
    position_sizer = FixedPositionSizer()

    # Use an example Risk Manager
    risk_manager = ExampleRiskManager()

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

    # Use the ExampleCompliance component
    compliance = ExampleCompliance(config)

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

    # Use the default Statistics
    statistics = SimpleStatistics(config, portfolio_handler)

    # Set up the backtest
    backtest = Backtest(
        price_handler, strategy,
        portfolio_handler, execution_handler,
        position_sizer, risk_manager,
        statistics, initial_equity
    )
    results = backtest.simulate_trading(testing=testing)
    statistics.save(filename)
    return results
开发者ID:femtotrader,项目名称:qstrader,代码行数:59,代码来源:pandas_bar_display_prices_backtest.py

示例7: setUp

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def setUp(self):
     """
     Set up the Portfolio object that will store the
     collection of Position objects, supplying it with
     $500,000.00 USD in initial cash.
     """
     ph = PriceHandlerMock()
     cash = PriceParser.parse(500000.00)
     self.portfolio = Portfolio(ph, cash)
开发者ID:Gwill,项目名称:qstrader,代码行数:11,代码来源:test_portfolio.py

示例8: test_realised_unrealised_calcs

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
    def test_realised_unrealised_calcs(self):
        self.assertEqual(
            PriceParser.display(self.position.unrealised_pnl), -1.00
        )
        self.assertEqual(
            PriceParser.display(self.position.realised_pnl), 0.00
        )

        self.position.update_market_value(
            PriceParser.parse(75.77), PriceParser.parse(75.79)
        )
        self.assertEqual(
            PriceParser.display(self.position.unrealised_pnl), 99.00
        )
        self.position.transact_shares(
            "SLD", 100,
            PriceParser.parse(75.78), PriceParser.parse(1.00)
        )
        self.assertEqual(
            PriceParser.display(self.position.unrealised_pnl), 99.00
        )  # still high
        self.assertEqual(
            PriceParser.display(self.position.realised_pnl), 98.00
        )

        self.position.update_market_value(
            PriceParser.parse(75.77), PriceParser.parse(75.79)
        )
        self.assertEqual(
            PriceParser.display(self.position.unrealised_pnl), 0.00
        )
开发者ID:Gwill,项目名称:qstrader,代码行数:33,代码来源:test_position.py

示例9: run

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
def run(config, testing, tickers, filename):

    # Set up variables needed for backtest
    events_queue = queue.Queue()
    csv_dir = config.CSV_DATA_DIR
    initial_equity = PriceParser.parse(500000.00)

    # Use Yahoo Daily Price Handler
    price_handler = YahooDailyCsvBarPriceHandler(
        csv_dir, events_queue, tickers
    )

    # Use the Buy and Hold Strategy
    strategy = BuyAndHoldStrategy(tickers, events_queue)
    strategy = Strategies(strategy, DisplayStrategy())

    # Use an example Position Sizer
    position_sizer = FixedPositionSizer()

    # Use an example Risk Manager
    risk_manager = ExampleRiskManager()

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

    # Use the ExampleCompliance component
    compliance = ExampleCompliance(config)

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

    # Use the default Statistics
    statistics = SimpleStatistics(config, portfolio_handler)

    # Set up the backtest
    backtest = Backtest(
        price_handler, strategy,
        portfolio_handler, execution_handler,
        position_sizer, risk_manager,
        statistics, initial_equity
    )
    results = backtest.simulate_trading(testing=testing)
    statistics.save(filename)
    return results
开发者ID:MeanRev99,项目名称:qstrader,代码行数:51,代码来源:buy_and_hold_backtest.py

示例10: test_calculating_statistics

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
    def test_calculating_statistics(self):
        """
        Purchase/sell multiple lots of AMZN, GOOG
        at various prices/commissions to ensure
        the arithmetic in calculating equity, drawdowns
        and sharpe ratio is correct.
        """
        # Create Statistics object
        price_handler = PriceHandlerMock()
        self.portfolio = Portfolio(price_handler, PriceParser.parse(500000.00))

        portfolio_handler = PortfolioHandlerMock(self.portfolio)
        statistics = SimpleStatistics(self.config, portfolio_handler)

        # Check initialization was correct
        self.assertEqual(PriceParser.display(statistics.equity[0]), 500000.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[0]), 00)
        self.assertEqual(statistics.equity_returns[0], 0.0)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "BOT", "AMZN", 100,
            PriceParser.parse(566.56), PriceParser.parse(1.00)
        )
        t = "2000-01-01 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[1]), 499807.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[1]), 193.00)
        self.assertEqual(statistics.equity_returns[1], -0.0386)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "BOT", "AMZN", 200,
            PriceParser.parse(566.395), PriceParser.parse(1.00)
        )
        t = "2000-01-02 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[2]), 499455.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[2]), 545.00)
        self.assertEqual(statistics.equity_returns[2], -0.0705)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "BOT", "GOOG", 200,
            PriceParser.parse(707.50), PriceParser.parse(1.00)
        )
        t = "2000-01-03 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[3]), 499046.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[3]), 954.00)
        self.assertEqual(statistics.equity_returns[3], -0.0820)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "SLD", "AMZN", 100,
            PriceParser.parse(565.83), PriceParser.parse(1.00)
        )
        t = "2000-01-04 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[4]), 499164.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[4]), 836.00)
        self.assertEqual(statistics.equity_returns[4], 0.0236)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "BOT", "GOOG", 200,
            PriceParser.parse(705.545), PriceParser.parse(1.00)
        )
        t = "2000-01-05 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[5]), 499146.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[5]), 854.00)
        self.assertEqual(statistics.equity_returns[5], -0.0036)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "SLD", "AMZN", 200,
            PriceParser.parse(565.59), PriceParser.parse(1.00)
        )
        t = "2000-01-06 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[6]), 499335.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[6]), 665.00)
        self.assertEqual(statistics.equity_returns[6], 0.0379)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "SLD", "GOOG", 100,
            PriceParser.parse(707.92), PriceParser.parse(1.00)
        )
        t = "2000-01-07 00:00:00"
        statistics.update(t, portfolio_handler)
        self.assertEqual(PriceParser.display(statistics.equity[7]), 499580.00)
        self.assertEqual(PriceParser.display(statistics.drawdowns[7]), 420.00)
        self.assertEqual(statistics.equity_returns[7], 0.0490)

        # Perform transaction and test statistics at this tick
        self.portfolio.transact_position(
            "SLD", "GOOG", 100,
            PriceParser.parse(707.90), PriceParser.parse(0.00)
#.........这里部分代码省略.........
开发者ID:Gwill,项目名称:qstrader,代码行数:103,代码来源:test_statistics.py

示例11: test_display

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def test_display(self):
     parsed = PriceParser.parse(self.float)
     displayed = PriceParser.display(parsed)
     self.assertEqual(displayed, 10.12)
开发者ID:MeanRev99,项目名称:qstrader,代码行数:6,代码来源:test_priceparser.py

示例12: test_rounded_float

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def test_rounded_float(self):
     parsed = PriceParser.parse(self.rounded_float)
     # Expect 100,000,000
     self.assertEqual(parsed, 100000000)
     self.assertIsInstance(parsed, int)
开发者ID:MeanRev99,项目名称:qstrader,代码行数:7,代码来源:test_priceparser.py

示例13: test_price_from_int

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def test_price_from_int(self):
     parsed = PriceParser.parse(self.int)
     self.assertEqual(parsed, 200)
     self.assertIsInstance(parsed, int)
开发者ID:MeanRev99,项目名称:qstrader,代码行数:6,代码来源:test_priceparser.py

示例14: test_price_from_float

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
 def test_price_from_float(self):
     parsed = PriceParser.parse(self.float)
     self.assertEqual(parsed, 101234567)
     self.assertIsInstance(parsed, int)
开发者ID:MeanRev99,项目名称:qstrader,代码行数:6,代码来源:test_priceparser.py

示例15: run

# 需要导入模块: from qstrader.price_parser import PriceParser [as 别名]
# 或者: from qstrader.price_parser.PriceParser import parse [as 别名]
def run(config, testing, tickers, filename):

    # Set up variables needed for backtest
    events_queue = queue.Queue()
    csv_dir = config.CSV_DATA_DIR
    initial_equity = PriceParser.parse(500000.00)
    start_date = datetime.datetime(2006, 11, 1)
    end_date = datetime.datetime(2016, 10, 12)

    # Use Yahoo Daily Price Handler
    price_handler = YahooDailyCsvBarPriceHandler(
        csv_dir, events_queue, tickers,
        start_date=start_date, end_date=end_date
    )

    # Use the monthly liquidate and rebalance strategy
    strategy = MonthlyLiquidateRebalanceStrategy(tickers, events_queue)
    strategy = Strategies(strategy, DisplayStrategy())

    # Use the liquidate and rebalance position sizer
    # with prespecified ticker weights
    ticker_weights = {
        "SPY": 0.6,
        "AGG": 0.4,
    }
    position_sizer = LiquidateRebalancePositionSizer(ticker_weights)

    # Use an example Risk Manager
    risk_manager = ExampleRiskManager()

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

    # Use the ExampleCompliance component
    compliance = ExampleCompliance(config)

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

    # Use the default Statistics
    title = ["US Equities/Bonds 60/40 ETF Strategy"]
    benchmark = "SPY"
    statistics = TearsheetStatistics(
        config, portfolio_handler, title, benchmark
    )

    # Set up the backtest
    backtest = Backtest(
        price_handler, strategy,
        portfolio_handler, execution_handler,
        position_sizer, risk_manager,
        statistics, initial_equity
    )
    results = backtest.simulate_trading(testing=testing)
    statistics.save(filename)
    return results
开发者ID:femtotrader,项目名称:qstrader,代码行数:63,代码来源:monthly_liquidate_rebalance_backtest.py


注:本文中的qstrader.price_parser.PriceParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。