Skip to content

Commit 6635163

Browse files
committed
fix: helpers.subtract_years() should add +1 years when the month is december (12)
1 parent 20292c6 commit 6635163

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The package is supplied with **free** «end of day» historical stock markets da
6161

6262
## Getting started
6363

64-
### 1. Compare several assets from different stock markets. Get the USD-adjusted perfomance
64+
### 1. Compare several assets from different stock markets. Get USD-adjusted performance
6565

6666
```python
6767
import okama as ok

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import okama as ok
22

3-
print(ok.symbols_in_namespace('CBR').info)
3+
x = ok.AssetList(['SXR8.XETR', 'SXRG.XETR', 'XRS2.XETR'])
4+
print(x.get_cagr(5))

okama/assets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(self,
117117
self.first_date: pd.Timestamp = max(self.first_date, pd.to_datetime(first_date))
118118
self.ror = self.ror[self.first_date:]
119119
if last_date:
120+
# TODO: self.assets_last_dates should be less or equal to self.last_date
120121
self.last_date: pd.Timestamp = min(self.last_date, pd.to_datetime(last_date))
121122
self.ror: pd.DataFrame = self.ror[self.first_date: self.last_date]
122123
self.period_length: float = round((self.last_date - self.first_date) / np.timedelta64(365, 'D'), ndigits=1)

okama/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ def subtract_years(dt: pd.Timestamp, years: int) -> pd.Timestamp:
425425
"""
426426
if isinstance(years, int):
427427
if dt.month == 12:
428-
dt = dt.replace(year=dt.year - years, month=1) # for December
428+
new_dt = dt.replace(year=dt.year - years + 1, month=1) # for December
429429
else:
430-
dt = dt.replace(year=dt.year - years, month=dt.month + 1)
430+
new_dt = dt.replace(year=dt.year - years, month=dt.month + 1)
431431
else:
432432
raise TypeError('The period should be integer')
433-
return dt
433+
return new_dt
434434

435435

436436
class Index:

0 commit comments

Comments
 (0)