Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Dec 31, 2024
1 parent 28359f9 commit f28c60e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ccy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Python currencies"""

__version__ = "1.6.0"
__version__ = "1.7.0"


from .core.country import (
Expand Down
18 changes: 7 additions & 11 deletions ccy/core/daycounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ def alldc() -> dict[str, DayCounterMeta]:
return copy(_day_counters)


def act_act_years(dt: date) -> float:
y = dt.year
r = y % 4
a = 0.0
if r > 0:
a = 1.0
dd = (dt - date(y, 1, 1)).total_seconds() / 86400
return y + dd / (365.0 + a)


class DayCounterMeta(type):
def __new__(cls, name: str, bases: Any, attrs: Any) -> DayCounterMeta:
new_class = super(DayCounterMeta, cls).__new__(cls, name, bases, attrs)
Expand Down Expand Up @@ -81,4 +71,10 @@ class ActAct(DayCounter):
name = "ACT/ACT"

def dcf(self, start: date, end: date) -> float:
return act_act_years(end) - act_act_years(start)
return self.act_act_years(end) - self.act_act_years(start)

def act_act_years(self, dt: date) -> float:
y = dt.year
days_in_year = 365 if y % 4 else 366
dd = (dt - date(y, 1, 1)).total_seconds() / 86400
return y + dd / days_in_year
12 changes: 8 additions & 4 deletions ccy/tradingcentres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
isoweekend = frozenset((6, 7))
oneday = timedelta(days=1)

_tcs: dict[str, TradingCentre] = {}
trading_centres: dict[str, TradingCentre] = {}


def prevbizday(dte: date, nd: int = 1, tcs: str | None = None) -> date:
Expand All @@ -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
Expand All @@ -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


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

@property
def code(self) -> str:
return ",".join(sorted(self.centres))

def isbizday(self, dte: date) -> bool:
if dte.isoweekday() in isoweekend:
return False
Expand Down Expand Up @@ -77,7 +81,7 @@ def prevbizday(self, dte: date, nd: int = 1) -> date:
return dte


_tcs.update(
trading_centres.update(
(tc.code, tc)
for tc in (
TradingCentre(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ccy"
version = "1.6.0"
version = "1.7.0"
description = "Python currencies"
authors = ["Luca Sbardella <luca@quantmind.com>"]
license = "BSD"
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
* Show all currencies in the command line via `ccys show`
* Trading centres are available when installing the `holidays` extra via
```
pip install ccy[holidays]
```
22 changes: 11 additions & 11 deletions tests/test_tcs.py
Original file line number Diff line number Diff line change
@@ -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


@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
]


Expand All @@ -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 comments on commit f28c60e

Please sign in to comment.