Commit 58ec879a authored by Johannes Blaschke's avatar Johannes Blaschke

tweaked ForexDay data model

parent a5ba1047
Pipeline #1 failed with stages
......@@ -30,8 +30,9 @@ class CurrencyPair(CurrencyRates):
Pair of currencies, allowing their exchange rate to be calculated. The pair is directional:
exchange rates are calculated from the "in" currency in units of the "out" currency.
"""
def __init__(self, c_in: str = "EUR", c_out: str = "USD", quant: float = 10000) -> None:
super().__init__()
def __init__(self, c_in: str = "EUR", c_out: str = "USD", quant: float = 10000,
force_decimal: bool = False) -> None:
super().__init__(force_decimal=force_decimal)
self.currency_in: str = c_in
self.currency_out: str = c_out
......@@ -57,7 +58,9 @@ class ForexDay(object):
n_list: int = int(timedelta(days=1) / resolution)
t_list: List[datetime] = [as_datetime(c_date) + self.resolution * n for n in range(n_list)]
self.data: List[Tuple[datetime, float]] = [(t, cp.get_pair_rate(t)) for t in t_list]
self.data: Dict[datetime, float] = dict()
for current_t in t_list:
self.data[current_t] = cp.get_pair_rate(current_t)
def __repr__(self) -> str:
......@@ -68,14 +71,14 @@ class ForexDay(object):
"""
Returns a list of times for which the exchange rates where determined.
"""
return [elem[0] for elem in self.data]
return sorted(self.data.keys())
def get_rates(self) -> List[float]:
"""
Returns a list of exchange rates corresponding to the times returned by `get_times`.
"""
return [elem[1] for elem in self.data]
return sorted([elem for _, elem in zip(self.data.keys(), self.data.values())])
def mean_rate(self) -> float:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment