Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
jbaron committed Aug 19, 2024
1 parent b57b100 commit 4f2af54
Showing 5 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion roboquant/__init__.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
`Account`, `Asset` and `Event`.
"""

__version__ = "0.9.0"
__version__ = "0.9.1"

import logging

13 changes: 0 additions & 13 deletions roboquant/account.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
from decimal import Decimal

from roboquant.asset import Asset
from roboquant.event import Event
from roboquant.order import Order
from roboquant.monetary import Amount, Wallet, USD, Currency

@@ -147,15 +146,3 @@ def __repr__(self) -> str:
f"last update : {self.last_update}"
)
return result

def _update(self, event: Event, price_type: str = "DEFAULT"):
"""The broker normally invokes this method during the sync.
This method will take care of:
- update the positions with the latest market prices as found in the event
"""
self.last_update = event.time

for asset, position in self.positions.items():
if price := event.get_price(asset, price_type):
position.mkt_price = price
16 changes: 7 additions & 9 deletions roboquant/monetary.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
from collections import defaultdict
from csv import reader
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from typing import ClassVar, Any, Dict, List

@@ -158,6 +158,9 @@ def __add__(self, other: "Amount") -> "Wallet":
"""
return Wallet(self, other)

def __matmul__(self, other: Currency) -> float:
return self.convert(other, datetime.now(tz=timezone.utc))

def convert(self, currency: Currency, time: datetime) -> float:
"""Convert this amount to another currency and return that value.
If a conversion is required, it will invoke the registered `Amount.converter`.
@@ -207,6 +210,9 @@ def __sub__(self, other: "Amount | Wallet"):
result[k] -= v
return result

def __matmul__(self, other: Currency) -> float:
return self.convert(other, datetime.now(tz=timezone.utc))

def deepcopy(self) -> "Wallet":
result = Wallet()
result.update(self)
@@ -218,11 +224,3 @@ def convert(self, currency: Currency, time: datetime) -> float:

def __repr__(self) -> str:
return " + ".join([f"{a}" for a in self.amounts()])


if __name__ == "__main__":
ECBConversion().download()
Amount.register_converter(ECBConversion())
amt = 100 @ EUR + 10_000 @ JPY
dt = datetime.fromisoformat("2024-01-01T00:00:00Z")
print(amt.convert(USD, dt))
12 changes: 5 additions & 7 deletions roboquant/signal.py
Original file line number Diff line number Diff line change
@@ -24,15 +24,13 @@ def __str__(self):
class Signal:
"""Signal that a strategy can create. It contains both a rating and the type of signal.
A rating is a float normally between -1.0 and 1.0, where -1.0 is a strong sell and 1.0 is a strong buy.
But this range isn't enfoced. It is up to the used trader to handle these values.
A rating is a float normally between -1.0 and 1.0, where -1.0 is a strong sell, and 1.0 is a strong buy.
But this range isn't enforced. It is up to the used trader to handle these values.
Examples:
```
Signal.buy("XYZ")
Signal.sell("XYZ", SignalType.EXIT)
Signal("XYZ", 0.5, SignalType.ENTRY)
```
Signal.buy("XYZ")
Signal.sell("XYZ", SignalType.EXIT)
Signal("XYZ", 0.5, SignalType.ENTRY)
"""

asset: Asset
3 changes: 3 additions & 0 deletions tests/unit/test_monetary.py
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ def test_ecb_conversion(self):
amt1 = Amount(GBP, 100.0)
self.assertAlmostEqual(117.8856, amt1.convert(EUR, now), 4)

# convert an amount to its own currency
self.assertEqual(amt1.value, amt1@amt1.currency)

Amount.register_converter(NoConversion())


0 comments on commit 4f2af54

Please sign in to comment.