From be738e6d25daec4fbf8cbe849c6983434bc5846c Mon Sep 17 00:00:00 2001 From: Peter Dekkers Date: Wed, 21 Aug 2024 21:35:58 +0200 Subject: [PATCH] Added ECB converter 2 --- roboquant/brokers/simbroker.py | 2 +- roboquant/monetary.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/roboquant/brokers/simbroker.py b/roboquant/brokers/simbroker.py index 14b71cf..a924bbf 100644 --- a/roboquant/brokers/simbroker.py +++ b/roboquant/brokers/simbroker.py @@ -182,7 +182,7 @@ def _calculate_short_positions(self): reserved += short_value return reserved - def _calculate_buyingpower(self): + def _calculate_buyingpower(self) -> Amount: """Calculate buying power, based on: buying_power = cash - open_orders - short_positions diff --git a/roboquant/monetary.py b/roboquant/monetary.py index a44bb75..84981f4 100644 --- a/roboquant/monetary.py +++ b/roboquant/monetary.py @@ -23,6 +23,9 @@ def __rmatmul__(self, other: float | int): assert isinstance(other, (float, int)) return Amount(self, other) + def __call__(self, other: float | int): + return Amount(self, other) + # Commonly used currencies USD = Currency("USD") @@ -48,6 +51,10 @@ def convert(self, amount: "Amount", to_currency: Currency, time: datetime) -> fl """Convert the monetary amount into another currency at the provided time.""" ... + def register(self): + """Register this converter to be used for conversions between amounts""" + Amount.register_converter(self) + class NoConversion(CurrencyConverter): """The default currency converter that doesn't convert between currencies"""