We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 28359f9 commit f28c60eCopy full SHA for f28c60e
ccy/__init__.py
@@ -1,6 +1,6 @@
1
"""Python currencies"""
2
3
-__version__ = "1.6.0"
+__version__ = "1.7.0"
4
5
6
from .core.country import (
ccy/core/daycounter.py
@@ -25,16 +25,6 @@ def alldc() -> dict[str, DayCounterMeta]:
25
return copy(_day_counters)
26
27
28
-def act_act_years(dt: date) -> float:
29
- y = dt.year
30
- r = y % 4
31
- a = 0.0
32
- if r > 0:
33
- a = 1.0
34
- dd = (dt - date(y, 1, 1)).total_seconds() / 86400
35
- return y + dd / (365.0 + a)
36
-
37
38
class DayCounterMeta(type):
39
def __new__(cls, name: str, bases: Any, attrs: Any) -> DayCounterMeta:
40
new_class = super(DayCounterMeta, cls).__new__(cls, name, bases, attrs)
@@ -81,4 +71,10 @@ class ActAct(DayCounter):
81
71
name = "ACT/ACT"
82
72
83
73
def dcf(self, start: date, end: date) -> float:
84
- return act_act_years(end) - act_act_years(start)
74
+ return self.act_act_years(end) - self.act_act_years(start)
75
+
76
+ def act_act_years(self, dt: date) -> float:
77
+ y = dt.year
78
+ days_in_year = 365 if y % 4 else 366
79
+ dd = (dt - date(y, 1, 1)).total_seconds() / 86400
80
+ return y + dd / days_in_year
ccy/tradingcentres/__init__.py
@@ -9,7 +9,7 @@
9
isoweekend = frozenset((6, 7))
10
oneday = timedelta(days=1)
11
12
-_tcs: dict[str, TradingCentre] = {}
+trading_centres: dict[str, TradingCentre] = {}
13
14
15
def prevbizday(dte: date, nd: int = 1, tcs: str | None = None) -> date:
@@ -25,7 +25,7 @@ def centres(codes: str | None = None) -> TradingCentres:
if codes:
lcs = codes.upper().replace(" ", "").split(",")
for code in lcs:
- tc = _tcs.get(code)
+ tc = trading_centres.get(code)
if tc:
tcs.centres[tc.code] = tc
return tcs
@@ -37,13 +37,17 @@ class TradingCentre:
calendar: holidays.HolidayBase
def isholiday(self, dte: date) -> bool:
- return dte not in self.calendar
+ return dte in self.calendar
41
42
43
@dataclass
44
class TradingCentres:
45
centres: dict[str, TradingCentre] = field(default_factory=dict)
46
47
+ @property
48
+ def code(self) -> str:
49
+ return ",".join(sorted(self.centres))
50
51
def isbizday(self, dte: date) -> bool:
52
if dte.isoweekday() in isoweekend:
53
return False
@@ -77,7 +81,7 @@ def prevbizday(self, dte: date, nd: int = 1) -> date:
return dte
-_tcs.update(
+trading_centres.update(
85
(tc.code, tc)
86
for tc in (
87
TradingCentre(
pyproject.toml
[tool.poetry]
name = "ccy"
-version = "1.6.0"
+version = "1.7.0"
description = "Python currencies"
authors = ["Luca Sbardella <luca@quantmind.com>"]
license = "BSD"
readme.md
@@ -14,3 +14,7 @@ join and add more.
* Documentation is available as [ccy jupyter book](https://quantmind.github.io/ccy/).
* Install the command line tool with `pip install ccy[cli]`.
16
* Show all currencies in the command line via `ccys show`
17
+* Trading centres are available when installing the `holidays` extra via
18
+ ```
19
+ pip install ccy[holidays]
20
tests/test_tcs.py
@@ -1,18 +1,17 @@
-import datetime
+from datetime import date
import pytest
-from ccy.tradingcentres import nextbizday, prevbizday
-from ccy import tradingcentres
+from ccy.tradingcentres import nextbizday, prevbizday, centres
7
8
@pytest.fixture()
def dates():
return [
- datetime.date(2010, 4, 1), # Thu
- datetime.date(2010, 4, 2), # Fri
- datetime.date(2010, 4, 3), # Sat
- datetime.date(2010, 4, 5), # Mon
- datetime.date(2010, 4, 6), # Tue
+ date(2010, 4, 1), # Thu
+ date(2010, 4, 2), # Fri
+ date(2010, 4, 3), # Sat
+ date(2010, 4, 5), # Mon
+ date(2010, 4, 6), # Tue
]
@@ -34,6 +33,7 @@ def test_prevBizDay(dates):
def test_TGT():
- tcs = tradingcentres("TGT")
- assert not tcs.isbizday(datetime.date(2009, 12, 25))
- assert not tcs.isbizday(datetime.date(2010, 1, 1))
+ tcs = centres("TGT")
+ assert tcs.code == "TGT"
+ assert not tcs.isbizday(date(2009, 12, 25))
+ assert not tcs.isbizday(date(2010, 1, 1))
0 commit comments