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


Python Position.update_position_price方法代码示例

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


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

示例1: TestLongEURUSDPosition

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import update_position_price [as 别名]
class TestLongEURUSDPosition(unittest.TestCase):

    """
    Unit tests that cover going short EUR/USD with an account
    denominated currency of GBP, using 2,000 units of EUR/USD.
    """

    def setUp(self):
        home_currency = "GBP"
        position_type = "short"
        currency_pair = "EURUSD"
        units = Decimal("2000")
        ticker = TickerMock()
        self.position = Position(
            home_currency, position_type,
            currency_pair, units, ticker
        )

    def test_calculate_init_pips(self):
        pos_pips = self.position.calculate_pips()
        self.assertEqual(pos_pips, Decimal("-0.00015"))

    def test_calculate_init_profit_base(self):
        profit_base = self.position.calculate_profit_base()
        self.assertEqual(profit_base, Decimal("-0.19954"))

    def test_calculate_init_profit_perc(self):
        profit_perc = self.position.calculate_profit_perc()
        self.assertEqual(profit_perc, Decimal("-0.00998"))

    def test_calculate_updated_values(self):
        """
        Check that after the bid/ask prices move, that the updated
        pips, profit and percentage profit calculations are correct.
        """
        prices = self.position.ticker.prices
        prices["GBPUSD"] = {
            "bid": Decimal("1.50486"), "ask": Decimal("1.50586")}
        prices["USDGBP"] = {
            "bid": Decimal("0.66451"), "ask": Decimal("0.66407")}
        prices["EURUSD"] = {
            "bid": Decimal("1.07811"), "ask": Decimal("1.07827")}
        self.position.update_position_price()

        # Check pips
        pos_pips = self.position.calculate_pips()
        self.assertEqual(pos_pips, Decimal("0.00005"))
        # Check profit base
        profit_base = self.position.calculate_profit_base()
        self.assertEqual(profit_base, Decimal("0.06641"))
        # Check profit percentage
        profit_perc = self.position.calculate_profit_perc()
        self.assertEqual(profit_perc, Decimal("0.00332"))
开发者ID:cmorgan,项目名称:qsforex,代码行数:55,代码来源:position_test.py

示例2: TestLongGBPUSDPosition

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import update_position_price [as 别名]
class TestLongGBPUSDPosition(unittest.TestCase):
    def setUp(self):
        getcontext.prec = 2
        position_type = "long"
        market = "GBP/USD"
        units = Decimal("2000")
        exposure = Decimal("2000.00")
        bid = Decimal("1.50328")
        ask = Decimal("1.50349")
        self.position = Position(
            position_type, market, 
            units, exposure, bid, ask
        )

    def test_calculate_init_pips(self):
        pos_pips = self.position.calculate_pips()
        self.assertEqual(pos_pips, Decimal("-0.00021"))

    def test_calculate_init_profit_base(self):
        profit_base = self.position.calculate_profit_base(self.position.exposure)
        self.assertEqual(profit_base, Decimal("-0.27939"))

    def test_calculate_init_profit_perc(self):
        profit_perc = self.position.calculate_profit_perc(self.position.exposure)
        self.assertEqual(profit_perc, Decimal("-0.01397"))

    def test_calculate_updated_values(self):
        """
        Check that after the bid/ask prices move, that the updated
        pips, profit and percentage profit calculations are correct.
        """
        bid = Decimal("1.50486")
        ask = Decimal("1.50586")
        self.position.update_position_price(bid, ask, self.position.exposure)
        # Check pips
        pos_pips = self.position.calculate_pips()
        self.assertEqual(pos_pips, Decimal("0.00137"))
        # Check profit base
        profit_base = self.position.calculate_profit_base(self.position.exposure)
        self.assertEqual(profit_base, Decimal("1.82077"))
        # Check profit percentage
        profit_perc = self.position.calculate_profit_perc(self.position.exposure)
        self.assertEqual(profit_perc, Decimal("0.09104"))
开发者ID:diminkan,项目名称:qsforex,代码行数:45,代码来源:position_test.py


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