Skip to content

Commit f28c60e

Browse files
committedDec 31, 2024
release
1 parent 28359f9 commit f28c60e

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed
 

‎ccy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Python currencies"""
22

3-
__version__ = "1.6.0"
3+
__version__ = "1.7.0"
44

55

66
from .core.country import (

‎ccy/core/daycounter.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ def alldc() -> dict[str, DayCounterMeta]:
2525
return copy(_day_counters)
2626

2727

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-
3828
class DayCounterMeta(type):
3929
def __new__(cls, name: str, bases: Any, attrs: Any) -> DayCounterMeta:
4030
new_class = super(DayCounterMeta, cls).__new__(cls, name, bases, attrs)
@@ -81,4 +71,10 @@ class ActAct(DayCounter):
8171
name = "ACT/ACT"
8272

8373
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

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
isoweekend = frozenset((6, 7))
1010
oneday = timedelta(days=1)
1111

12-
_tcs: dict[str, TradingCentre] = {}
12+
trading_centres: dict[str, TradingCentre] = {}
1313

1414

1515
def prevbizday(dte: date, nd: int = 1, tcs: str | None = None) -> date:
@@ -25,7 +25,7 @@ def centres(codes: str | None = None) -> TradingCentres:
2525
if codes:
2626
lcs = codes.upper().replace(" ", "").split(",")
2727
for code in lcs:
28-
tc = _tcs.get(code)
28+
tc = trading_centres.get(code)
2929
if tc:
3030
tcs.centres[tc.code] = tc
3131
return tcs
@@ -37,13 +37,17 @@ class TradingCentre:
3737
calendar: holidays.HolidayBase
3838

3939
def isholiday(self, dte: date) -> bool:
40-
return dte not in self.calendar
40+
return dte in self.calendar
4141

4242

4343
@dataclass
4444
class TradingCentres:
4545
centres: dict[str, TradingCentre] = field(default_factory=dict)
4646

47+
@property
48+
def code(self) -> str:
49+
return ",".join(sorted(self.centres))
50+
4751
def isbizday(self, dte: date) -> bool:
4852
if dte.isoweekday() in isoweekend:
4953
return False
@@ -77,7 +81,7 @@ def prevbizday(self, dte: date, nd: int = 1) -> date:
7781
return dte
7882

7983

80-
_tcs.update(
84+
trading_centres.update(
8185
(tc.code, tc)
8286
for tc in (
8387
TradingCentre(

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ccy"
3-
version = "1.6.0"
3+
version = "1.7.0"
44
description = "Python currencies"
55
authors = ["Luca Sbardella <luca@quantmind.com>"]
66
license = "BSD"

‎readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ join and add more.
1414
* Documentation is available as [ccy jupyter book](https://quantmind.github.io/ccy/).
1515
* Install the command line tool with `pip install ccy[cli]`.
1616
* 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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import datetime
1+
from datetime import date
22

33
import pytest
4-
from ccy.tradingcentres import nextbizday, prevbizday
5-
from ccy import tradingcentres
4+
from ccy.tradingcentres import nextbizday, prevbizday, centres
65

76

87
@pytest.fixture()
98
def dates():
109
return [
11-
datetime.date(2010, 4, 1), # Thu
12-
datetime.date(2010, 4, 2), # Fri
13-
datetime.date(2010, 4, 3), # Sat
14-
datetime.date(2010, 4, 5), # Mon
15-
datetime.date(2010, 4, 6), # Tue
10+
date(2010, 4, 1), # Thu
11+
date(2010, 4, 2), # Fri
12+
date(2010, 4, 3), # Sat
13+
date(2010, 4, 5), # Mon
14+
date(2010, 4, 6), # Tue
1615
]
1716

1817

@@ -34,6 +33,7 @@ def test_prevBizDay(dates):
3433

3534

3635
def test_TGT():
37-
tcs = tradingcentres("TGT")
38-
assert not tcs.isbizday(datetime.date(2009, 12, 25))
39-
assert not tcs.isbizday(datetime.date(2010, 1, 1))
36+
tcs = centres("TGT")
37+
assert tcs.code == "TGT"
38+
assert not tcs.isbizday(date(2009, 12, 25))
39+
assert not tcs.isbizday(date(2010, 1, 1))

0 commit comments

Comments
 (0)