def test_money_initialized_with_valid_inputs(self): # Arrange # Act result1 = Money(1.00, Currency.USD) result2 = Money(1000.0, Currency.USD) result3 = Money(2, Currency.USD) # Assert self.assertEqual(1.00, result1.as_double()) self.assertEqual(1000.00, result2.as_double()) self.assertEqual(2.00, result3.as_double())
def test_as_double_returns_expected_result(self): # Arrange, Act money = Money(1, USD) # Assert assert 1.0 == money.as_double() assert "1.00" == str(money)
def test_from_str_with_no_decimal(self): # Arrange # Act money = Money(1, USD) # Assert assert 1.0 == money.as_double() assert "1.00" == str(money)
def test_money_from_string_with_no_decimal(self): # Arrange # Act money = Money(1, Currency.USD) # Assert self.assertEqual(1.00, money.as_double()) self.assertEqual('1.00', str(money))
def test_from_string_with_no_decimal(self): # Arrange # Act money = Money(1, USD) # Assert self.assertEqual(1.0, money.as_double()) self.assertEqual("1.00", str(money))
def add_trade(self, position_id: PositionId, realized_pnl: Money) -> None: """ Add trade data to the analyzer. Parameters ---------- position_id : PositionId The position ID for the trade. realized_pnl : Money The realized PnL for the trade. """ currency = realized_pnl.currency realized_pnls = self._realized_pnls.get(currency, pd.Series(dtype=float64)) realized_pnls.loc[position_id.value] = realized_pnl.as_double() self._realized_pnls[currency] = realized_pnls