openseries 1.8.0__py3-none-any.whl → 1.8.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
openseries/_risk.py CHANGED
@@ -32,7 +32,7 @@ def _cvar_down_calc(
32
32
  level: float, default: 0.95
33
33
  The sought CVaR level
34
34
 
35
- Returns
35
+ Returns:
36
36
  -------
37
37
  float
38
38
  Downside Conditional Value At Risk "CVaR"
@@ -44,7 +44,7 @@ def _cvar_down_calc(
44
44
  clean = nan_to_num(data)
45
45
  ret = clean[1:] / clean[:-1] - 1
46
46
  array = sort(ret)
47
- return cast(float, mean(array[: int(ceil(len(array) * (1 - level)))]))
47
+ return cast("float", mean(array[: ceil(len(array) * (1 - level))]))
48
48
 
49
49
 
50
50
  def _var_down_calc(
@@ -66,7 +66,7 @@ def _var_down_calc(
66
66
  interpolation: LiteralQuantileInterp, default: "lower"
67
67
  type of interpolation in Pandas.DataFrame.quantile() function.
68
68
 
69
- Returns
69
+ Returns:
70
70
  -------
71
71
  float
72
72
  Downside Value At Risk
@@ -77,4 +77,4 @@ def _var_down_calc(
77
77
  else:
78
78
  clean = nan_to_num(data)
79
79
  ret = clean[1:] / clean[:-1] - 1
80
- return cast(float, quantile(ret, 1 - level, method=interpolation))
80
+ return cast("float", quantile(ret, 1 - level, method=interpolation))
openseries/datefixer.py CHANGED
@@ -21,6 +21,12 @@ from pandas import (
21
21
  )
22
22
  from pandas.tseries.offsets import CustomBusinessDay
23
23
 
24
+ from .owntypes import (
25
+ BothStartAndEndError,
26
+ CountriesNotStringNorListStrError,
27
+ TradingDaysNotAboveZeroError,
28
+ )
29
+
24
30
  if TYPE_CHECKING:
25
31
  from .owntypes import ( # pragma: no cover
26
32
  CountriesType,
@@ -59,7 +65,7 @@ def holiday_calendar(
59
65
  Argument where missing holidays can be added as
60
66
  {"2021-02-12": "Jack's birthday"} or ["2021-02-12"]
61
67
 
62
- Returns
68
+ Returns:
63
69
  -------
64
70
  numpy.busdaycalendar
65
71
  Generate a business calendar
@@ -92,7 +98,7 @@ def holiday_calendar(
92
98
  "Argument countries must be a string country code or "
93
99
  "a list of string country codes according to ISO 3166-1 alpha-2."
94
100
  )
95
- raise ValueError(msg)
101
+ raise CountriesNotStringNorListStrError(msg)
96
102
 
97
103
  return busdaycalendar(holidays=hols)
98
104
 
@@ -107,7 +113,7 @@ def date_fix(
107
113
  fixerdate: DateType
108
114
  The data item to parse
109
115
 
110
- Returns
116
+ Returns:
111
117
  -------
112
118
  datetime.date
113
119
  Parsed date
@@ -154,7 +160,7 @@ def date_offset_foll(
154
160
  following: bool, default: True
155
161
  Determines if days should be offset forward (following) or backward
156
162
 
157
- Returns
163
+ Returns:
158
164
  -------
159
165
  datetime.date
160
166
  Off-set date
@@ -179,7 +185,7 @@ def date_offset_foll(
179
185
  while not is_busday(dates=new_date, busdaycal=calendar):
180
186
  new_date += day_delta
181
187
 
182
- return new_date
188
+ return new_date # type: ignore[no-any-return]
183
189
 
184
190
 
185
191
  def get_previous_business_day_before_today(
@@ -199,7 +205,7 @@ def get_previous_business_day_before_today(
199
205
  Argument where missing holidays can be added as
200
206
  {"2021-02-12": "Jack's birthday"} or ["2021-02-12"]
201
207
 
202
- Returns
208
+ Returns:
203
209
  -------
204
210
  datetime.date
205
211
  The previous business day
@@ -242,7 +248,7 @@ def offset_business_days(
242
248
  Argument where missing holidays can be added as
243
249
  {"2021-02-12": "Jack's birthday"} or ["2021-02-12"]
244
250
 
245
- Returns
251
+ Returns:
246
252
  -------
247
253
  datetime.date
248
254
  The new offset business day
@@ -296,7 +302,7 @@ def offset_business_days(
296
302
 
297
303
  idx = where(array(local_bdays) == ddate)[0]
298
304
 
299
- return cast(dt.date, local_bdays[idx[0] + days])
305
+ return cast("dt.date", local_bdays[idx[0] + days])
300
306
 
301
307
 
302
308
  def generate_calendar_date_range(
@@ -318,7 +324,7 @@ def generate_calendar_date_range(
318
324
  countries: CountriesType, default: "SE"
319
325
  (List of) country code(s) according to ISO 3166-1 alpha-2
320
326
 
321
- Returns
327
+ Returns:
322
328
  -------
323
329
  list[dt.date]
324
330
  List of business day calendar dates
@@ -326,7 +332,7 @@ def generate_calendar_date_range(
326
332
  """
327
333
  if trading_days < 1:
328
334
  msg = "Argument trading_days must be greater than zero."
329
- raise ValueError(msg)
335
+ raise TradingDaysNotAboveZeroError(msg)
330
336
 
331
337
  if start and not end:
332
338
  tmp_range = date_range(
@@ -336,7 +342,7 @@ def generate_calendar_date_range(
336
342
  )
337
343
  calendar = holiday_calendar(
338
344
  startyear=start.year,
339
- endyear=date_fix(tmp_range[-1]).year,
345
+ endyear=date_fix(tmp_range.tolist()[-1]).year,
340
346
  countries=countries,
341
347
  )
342
348
  return [
@@ -351,7 +357,7 @@ def generate_calendar_date_range(
351
357
  if end and not start:
352
358
  tmp_range = date_range(end=end, periods=trading_days * 365 // 252, freq="D")
353
359
  calendar = holiday_calendar(
354
- startyear=date_fix(tmp_range[0]).year,
360
+ startyear=date_fix(tmp_range.tolist()[0]).year,
355
361
  endyear=end.year,
356
362
  countries=countries,
357
363
  )
@@ -368,7 +374,7 @@ def generate_calendar_date_range(
368
374
  "Provide one of start or end date, but not both. "
369
375
  "Date range is inferred from number of trading days."
370
376
  )
371
- raise ValueError(msg)
377
+ raise BothStartAndEndError(msg)
372
378
 
373
379
 
374
380
  def _do_resample_to_business_period_ends(
@@ -390,7 +396,7 @@ def _do_resample_to_business_period_ends(
390
396
  (List of) country code(s) according to ISO 3166-1 alpha-2
391
397
  to create a business day calendar used for date adjustments
392
398
 
393
- Returns
399
+ Returns:
394
400
  -------
395
401
  Pandas.DatetimeIndex
396
402
  A date range aligned to business period ends