openseries 1.9.7__py3-none-any.whl → 2.0.1__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.
@@ -1,10 +1,6 @@
1
- """Defining the _CommonModel class.
1
+ """The _CommonModel class.
2
2
 
3
- Copyright (c) Captor Fund Management AB. This file is part of the openseries project.
4
-
5
- Licensed under the BSD 3-Clause License. You may obtain a copy of the License at:
6
- https://github.com/CaptorAB/openseries/blob/master/LICENSE.md
7
- SPDX-License-Identifier: BSD-3-Clause
3
+ _CommonModel class which is the base class for OpenFrame and OpenTimeSeries.
8
4
  """
9
5
 
10
6
  from __future__ import annotations
@@ -110,7 +106,7 @@ def _get_date_range_and_factor(
110
106
  comparisons
111
107
 
112
108
  Returns:
113
- -------
109
+ --------
114
110
  tuple[dt.date, dt.date, float, DataFrame]
115
111
  earlier, later, time_factor, data
116
112
  """
@@ -153,7 +149,7 @@ def _get_base_column_data(
153
149
  End date
154
150
 
155
151
  Returns:
156
- -------
152
+ --------
157
153
  tuple[Series[float], tuple[str, ValueType], str]
158
154
  data, item, label
159
155
  """
@@ -196,7 +192,7 @@ def _calculate_time_factor(
196
192
  Fixed periods in year
197
193
 
198
194
  Returns:
199
- -------
195
+ --------
200
196
  float
201
197
  Time factor
202
198
  """
@@ -239,7 +235,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
239
235
  """Number of observations.
240
236
 
241
237
  Returns:
242
- -------
238
+ --------
243
239
  int
244
240
  Number of observations
245
241
 
@@ -251,7 +247,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
251
247
  """The first date in the timeseries.
252
248
 
253
249
  Returns:
254
- -------
250
+ --------
255
251
  datetime.date
256
252
  The first date in the timeseries
257
253
 
@@ -263,7 +259,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
263
259
  """The last date in the timeseries.
264
260
 
265
261
  Returns:
266
- -------
262
+ --------
267
263
  datetime.date
268
264
  The last date in the timeseries
269
265
 
@@ -275,7 +271,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
275
271
  """Number of days from the first date to the last.
276
272
 
277
273
  Returns:
278
- -------
274
+ --------
279
275
  int
280
276
  Number of days from the first date to the last
281
277
 
@@ -287,7 +283,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
287
283
  """Length of series expressed in years assuming all years have 365.25 days.
288
284
 
289
285
  Returns:
290
- -------
286
+ --------
291
287
  float
292
288
  Length of the timeseries expressed in years assuming all years
293
289
  have 365.25 days
@@ -300,7 +296,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
300
296
  """The average number of observations per year.
301
297
 
302
298
  Returns:
303
- -------
299
+ --------
304
300
  float
305
301
  The average number of observations per year
306
302
 
@@ -312,7 +308,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
312
308
  """https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp.
313
309
 
314
310
  Returns:
315
- -------
311
+ --------
316
312
  SeriesOrFloat_co
317
313
  Maximum drawdown in a single calendar year.
318
314
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -334,7 +330,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
334
330
  """https://www.investopedia.com/terms/c/cagr.asp.
335
331
 
336
332
  Returns:
337
- -------
333
+ --------
338
334
  SeriesOrFloat_co
339
335
  Compounded Annual Growth Rate (CAGR).
340
336
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -348,7 +344,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
348
344
  """https://www.investopedia.com/terms/a/arithmeticmean.asp.
349
345
 
350
346
  Returns:
351
- -------
347
+ --------
352
348
  SeriesOrFloat_co
353
349
  Annualized arithmetic mean of returns.
354
350
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -362,7 +358,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
362
358
  """Simple return.
363
359
 
364
360
  Returns:
365
- -------
361
+ --------
366
362
  SeriesOrFloat_co
367
363
  Simple return.
368
364
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -379,7 +375,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
379
375
  https://www.investopedia.com/terms/v/volatility.asp.
380
376
 
381
377
  Returns:
382
- -------
378
+ --------
383
379
  SeriesOrFloat_co
384
380
  Annualized volatility.
385
381
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -397,7 +393,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
397
393
  https://www.investopedia.com/terms/d/downside-deviation.asp.
398
394
 
399
395
  Returns:
400
- -------
396
+ --------
401
397
  SeriesOrFloat_co
402
398
  Downside deviation.
403
399
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -416,10 +412,9 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
416
412
  """Ratio of annualized arithmetic mean of returns and annualized volatility.
417
413
 
418
414
  Returns:
419
- -------
415
+ --------
420
416
  SeriesOrFloat_co
421
- Ratio of the annualized arithmetic mean of returns and annualized.
422
- Returns float for OpenTimeSeries, Series[float] for OpenFrame.
417
+ Ratio of the annualized arithmetic mean of returns and annualized
423
418
  volatility.
424
419
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
425
420
 
@@ -432,10 +427,9 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
432
427
  """https://www.investopedia.com/terms/s/sortinoratio.asp.
433
428
 
434
429
  Returns:
435
- -------
430
+ --------
436
431
  SeriesOrFloat_co
437
- Sortino ratio calculated as the annualized arithmetic mean of returns.
438
- Returns float for OpenTimeSeries, Series[float] for OpenFrame
432
+ Sortino ratio calculated as the annualized arithmetic mean of returns
439
433
  / downside deviation. The ratio implies that the riskfree asset has zero
440
434
  volatility, and a minimum acceptable return of zero.
441
435
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -459,10 +453,9 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
459
453
  the Sortino ratio (which uses order 2).
460
454
 
461
455
  Returns:
462
- -------
456
+ --------
463
457
  SeriesOrFloat_co
464
458
  Kappa-3 ratio calculation with the riskfree rate and.
465
- Returns float for OpenTimeSeries, Series[float] for OpenFrame
466
459
  Minimum Acceptable Return (MAR) both set to zero.
467
460
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
468
461
 
@@ -481,7 +474,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
481
474
  """https://en.wikipedia.org/wiki/Omega_ratio.
482
475
 
483
476
  Returns:
484
- -------
477
+ --------
485
478
  SeriesOrFloat_co
486
479
  Omega ratio calculation.
487
480
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -496,7 +489,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
496
489
  """https://www.investopedia.com/terms/z/zscore.asp.
497
490
 
498
491
  Returns:
499
- -------
492
+ --------
500
493
  SeriesOrFloat_co
501
494
  Z-score as (last return - mean return) / standard deviation of returns.
502
495
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -510,7 +503,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
510
503
  """https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp.
511
504
 
512
505
  Returns:
513
- -------
506
+ --------
514
507
  SeriesOrFloat_co
515
508
  Maximum drawdown without any limit on date range.
516
509
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -526,7 +519,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
526
519
  https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp.
527
520
 
528
521
  Returns:
529
- -------
522
+ --------
530
523
  datetime.date | pandas.Series[dt.date]
531
524
  Date when the maximum drawdown occurred
532
525
 
@@ -549,7 +542,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
549
542
  """Most negative percentage change.
550
543
 
551
544
  Returns:
552
- -------
545
+ --------
553
546
  SeriesOrFloat_co
554
547
  Most negative percentage change.
555
548
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -564,7 +557,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
564
557
  """Most negative month.
565
558
 
566
559
  Returns:
567
- -------
560
+ --------
568
561
  SeriesOrFloat_co
569
562
  Most negative month.
570
563
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -610,7 +603,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
610
603
  """The share of percentage changes that are greater than zero.
611
604
 
612
605
  Returns:
613
- -------
606
+ --------
614
607
  SeriesOrFloat_co
615
608
  The share of percentage changes that are greater than zero.
616
609
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -624,7 +617,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
624
617
  """https://www.investopedia.com/terms/s/skewness.asp.
625
618
 
626
619
  Returns:
627
- -------
620
+ --------
628
621
  SeriesOrFloat_co
629
622
  Skew of the return distribution.
630
623
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -638,7 +631,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
638
631
  """https://www.investopedia.com/terms/k/kurtosis.asp.
639
632
 
640
633
  Returns:
641
- -------
634
+ --------
642
635
  SeriesOrFloat_co
643
636
  Kurtosis of the return distribution.
644
637
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -652,7 +645,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
652
645
  """https://www.investopedia.com/terms/c/conditional_value_at_risk.asp.
653
646
 
654
647
  Returns:
655
- -------
648
+ --------
656
649
  SeriesOrFloat_co
657
650
  Downside 95% Conditional Value At Risk "CVaR".
658
651
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -670,7 +663,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
670
663
  https://www.investopedia.com/terms/v/var.asp.
671
664
 
672
665
  Returns:
673
- -------
666
+ --------
674
667
  SeriesOrFloat_co
675
668
  Downside 95% Value At Risk (VaR).
676
669
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -688,10 +681,9 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
688
681
  Assumes that returns are normally distributed.
689
682
 
690
683
  Returns:
691
- -------
684
+ --------
692
685
  SeriesOrFloat_co
693
- Implied annualized volatility from the Downside 95% VaR using the.
694
- Returns float for OpenTimeSeries, Series[float] for OpenFrame.
686
+ Implied annualized volatility from the Downside 95% VaR using the
695
687
  assumption that returns are normally distributed.
696
688
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
697
689
 
@@ -719,7 +711,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
719
711
  Specific from date
720
712
 
721
713
  Returns:
722
- -------
714
+ --------
723
715
  tuple[datetime.date, datetime.date]
724
716
  Start and end date of the chosen date range
725
717
 
@@ -768,6 +760,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
768
760
 
769
761
  Parameters
770
762
  ----------
763
+
771
764
  countries: CountriesType, optional
772
765
  (List of) country code(s) according to ISO 3166-1 alpha-2
773
766
  markets: list[str] | str, optional
@@ -775,9 +768,10 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
775
768
  custom_holidays: list[str] | str, optional
776
769
  Argument where missing holidays can be added
777
770
  method: LiteralPandasReindexMethod, default: "nearest"
771
+ Method for reindexing when aligning to business days
778
772
 
779
773
  Returns:
780
- -------
774
+ --------
781
775
  OpenFrame
782
776
  An OpenFrame object
783
777
 
@@ -837,7 +831,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
837
831
  Equivalent to LN(value[t] / value[t=0]) in Excel.
838
832
 
839
833
  Returns:
840
- -------
834
+ --------
841
835
  self
842
836
  An object of the same class
843
837
 
@@ -858,7 +852,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
858
852
  Method used to handle NaN. Either fill with last known or drop
859
853
 
860
854
  Returns:
861
- -------
855
+ --------
862
856
  self
863
857
  An object of the same class
864
858
 
@@ -878,7 +872,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
878
872
  Method used to handle NaN. Either fill with zero or drop
879
873
 
880
874
  Returns:
881
- -------
875
+ --------
882
876
  self
883
877
  An object of the same class
884
878
 
@@ -893,7 +887,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
893
887
  """Convert timeseries into a drawdown series.
894
888
 
895
889
  Returns:
896
- -------
890
+ --------
897
891
  self
898
892
  An object of the same class
899
893
 
@@ -923,7 +917,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
923
917
  File folder location
924
918
 
925
919
  Returns:
926
- -------
920
+ --------
927
921
  list[dict[str, str | bool | ValueType | list[str] | list[float]]]
928
922
  A list of dictionaries with the data of the series
929
923
 
@@ -990,7 +984,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
990
984
  Flag whether to overwrite an existing file
991
985
 
992
986
  Returns:
993
- -------
987
+ --------
994
988
  str
995
989
  The Excel file path
996
990
 
@@ -1161,7 +1155,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1161
1155
  If True a Captor logo is added to the plot
1162
1156
 
1163
1157
  Returns:
1164
- -------
1158
+ --------
1165
1159
  tuple[plotly.go.Figure, str]
1166
1160
  Plotly Figure and a div section or a html filename with location
1167
1161
 
@@ -1258,7 +1252,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1258
1252
  If True the last self.tsdf point is highlighted as red dot with a label
1259
1253
 
1260
1254
  Returns:
1261
- -------
1255
+ --------
1262
1256
  tuple[plotly.go.Figure, str]
1263
1257
  Plotly Figure and a div section or a html filename with location
1264
1258
 
@@ -1395,7 +1389,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1395
1389
  If True a Captor logo is added to the plot
1396
1390
 
1397
1391
  Returns:
1398
- -------
1392
+ --------
1399
1393
  tuple[plotly.go.Figure, str]
1400
1394
  Plotly Figure and a div section or a html filename with location
1401
1395
 
@@ -1493,7 +1487,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1493
1487
  comparisons
1494
1488
 
1495
1489
  Returns:
1496
- -------
1490
+ --------
1497
1491
  SeriesOrFloat_co
1498
1492
  Annualized arithmetic mean of returns.
1499
1493
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -1537,7 +1531,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1537
1531
  Allows locking the periods-in-a-year to simplify test cases and comparisons
1538
1532
 
1539
1533
  Returns:
1540
- -------
1534
+ --------
1541
1535
  SeriesOrFloat_co
1542
1536
  Annualized volatility.
1543
1537
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -1591,11 +1585,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1591
1585
  An adjustment to remove the bias implied by the average return
1592
1586
 
1593
1587
  Returns:
1594
- -------
1588
+ --------
1595
1589
  SeriesOrFloat_co
1596
- Implied annualized volatility from the Downside VaR using the.
1597
- Returns float for OpenTimeSeries, Series[float] for OpenFrame.
1590
+ Implied annualized volatility from the Downside VaR using the
1598
1591
  assumption that returns are normally distributed.
1592
+ Returns float for OpenTimeSeries, Series[float] for OpenFrame.
1599
1593
 
1600
1594
  """
1601
1595
  return self._var_implied_vol_and_target_func(
@@ -1653,11 +1647,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1653
1647
  An adjustment to remove the bias implied by the average return
1654
1648
 
1655
1649
  Returns:
1656
- -------
1650
+ --------
1657
1651
  SeriesOrFloat_co
1658
- A position weight multiplier from the ratio between a VaR implied.
1652
+ A position weight multiplier from the ratio between a VaR implied
1653
+ volatility and a given target volatility. Multiplier = 1.0 -> target met.
1659
1654
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
1660
- volatility and a given target volatility. Multiplier = 1.0 -> target met
1661
1655
 
1662
1656
  """
1663
1657
  return self._var_implied_vol_and_target_func(
@@ -1720,11 +1714,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1720
1714
  An adjustment to remove the bias implied by the average return
1721
1715
 
1722
1716
  Returns:
1723
- -------
1717
+ --------
1724
1718
  SeriesOrFloat_co
1725
- Target volatility if target_vol is provided otherwise the VaR.
1726
- Returns float for OpenTimeSeries, Series[float] for OpenFrame.
1719
+ Target volatility if target_vol is provided otherwise the VaR
1727
1720
  implied volatility.
1721
+ Returns float for OpenTimeSeries, Series[float] for OpenFrame.
1728
1722
 
1729
1723
  """
1730
1724
  earlier, later = self.calc_range(
@@ -1808,7 +1802,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1808
1802
  Specific to date
1809
1803
 
1810
1804
  Returns:
1811
- -------
1805
+ --------
1812
1806
  SeriesOrFloat_co
1813
1807
  Downside Conditional Value At Risk "CVaR".
1814
1808
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -1868,7 +1862,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1868
1862
  comparisons
1869
1863
 
1870
1864
  Returns:
1871
- -------
1865
+ --------
1872
1866
  SeriesOrFloat_co
1873
1867
  Downside deviation if order set to 2.
1874
1868
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -1942,7 +1936,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1942
1936
  Specific to date
1943
1937
 
1944
1938
  Returns:
1945
- -------
1939
+ --------
1946
1940
  SeriesOrFloat_co
1947
1941
  Compounded Annual Growth Rate (CAGR).
1948
1942
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -1992,7 +1986,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
1992
1986
  Specific to date
1993
1987
 
1994
1988
  Returns:
1995
- -------
1989
+ --------
1996
1990
  SeriesOrFloat_co
1997
1991
  Skew of the return distribution.
1998
1992
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2036,7 +2030,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2036
2030
  Specific to date
2037
2031
 
2038
2032
  Returns:
2039
- -------
2033
+ --------
2040
2034
  SeriesOrFloat_co
2041
2035
  Kurtosis of the return distribution.
2042
2036
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2087,7 +2081,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2087
2081
  Smallest number of observations to use to find the maximum drawdown
2088
2082
 
2089
2083
  Returns:
2090
- -------
2084
+ --------
2091
2085
  SeriesOrFloat_co
2092
2086
  Maximum drawdown without any limit on date range.
2093
2087
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2126,7 +2120,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2126
2120
  Specific to date
2127
2121
 
2128
2122
  Returns:
2129
- -------
2123
+ --------
2130
2124
  SeriesOrFloat_co
2131
2125
  Calculate share of percentage changes that are greater than zero.
2132
2126
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2191,11 +2185,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2191
2185
  comparisons
2192
2186
 
2193
2187
  Returns:
2194
- -------
2188
+ --------
2195
2189
  SeriesOrFloat_co
2196
- Ratio of the annualized arithmetic mean of returns and annualized.
2190
+ Ratio of the annualized arithmetic mean of returns and annualized
2191
+ volatility or, if risk-free return provided, Sharpe ratio.
2197
2192
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
2198
- volatility or, if risk-free return provided, Sharpe ratio
2199
2193
 
2200
2194
  """
2201
2195
  result = Series(
@@ -2256,11 +2250,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2256
2250
  comparisons
2257
2251
 
2258
2252
  Returns:
2259
- -------
2253
+ --------
2260
2254
  SeriesOrFloat_co
2261
- Sortino ratio calculated as ( return - riskfree return ) /.
2255
+ Sortino ratio calculated as ( return - riskfree return ) /
2256
+ downside deviation (std dev of returns below MAR).
2262
2257
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
2263
- downside deviation (std dev of returns below MAR)
2264
2258
 
2265
2259
  """
2266
2260
  result = Series(
@@ -2312,7 +2306,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2312
2306
  Specific to date
2313
2307
 
2314
2308
  Returns:
2315
- -------
2309
+ --------
2316
2310
  SeriesOrFloat_co
2317
2311
  Omega ratio calculation.
2318
2312
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2353,7 +2347,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2353
2347
  Specific to date
2354
2348
 
2355
2349
  Returns:
2356
- -------
2350
+ --------
2357
2351
  SeriesOrFloat_co
2358
2352
  Calculate simple return.
2359
2353
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2394,7 +2388,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2394
2388
  Calendar month of the period to calculate.
2395
2389
 
2396
2390
  Returns:
2397
- -------
2391
+ --------
2398
2392
  SeriesOrFloat_co
2399
2393
  Calculate simple return for a specific calendar period.
2400
2394
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2440,7 +2434,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2440
2434
  Type of interpolation in Pandas.DataFrame.quantile() function.
2441
2435
 
2442
2436
  Returns:
2443
- -------
2437
+ --------
2444
2438
  SeriesOrFloat_co
2445
2439
  Downside Value At Risk.
2446
2440
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2482,11 +2476,11 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2482
2476
  Specific to date
2483
2477
 
2484
2478
  Returns:
2485
- -------
2479
+ --------
2486
2480
  SeriesOrFloat_co
2487
- Most negative percentage change over a rolling number of observations.
2481
+ Most negative percentage change over a rolling number of observations
2482
+ within a chosen date range.
2488
2483
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
2489
- within a chosen date range
2490
2484
 
2491
2485
  """
2492
2486
  earlier, later = self.calc_range(
@@ -2526,7 +2520,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2526
2520
  Specific to date
2527
2521
 
2528
2522
  Returns:
2529
- -------
2523
+ --------
2530
2524
  SeriesOrFloat_co
2531
2525
  Z-score as (last return - mean return) / standard deviation of returns.
2532
2526
  Returns float for OpenTimeSeries, Series[float] for OpenFrame.
@@ -2564,7 +2558,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2564
2558
  Number of observations in the overlapping window.
2565
2559
 
2566
2560
  Returns:
2567
- -------
2561
+ --------
2568
2562
  Pandas.DataFrame
2569
2563
  Calculate rolling annualized downside CVaR
2570
2564
 
@@ -2595,7 +2589,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2595
2589
  Number of observations in the overlapping window.
2596
2590
 
2597
2591
  Returns:
2598
- -------
2592
+ --------
2599
2593
  Pandas.DataFrame
2600
2594
  Calculate rolling returns
2601
2595
 
@@ -2634,7 +2628,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2634
2628
  Type of interpolation in Pandas.DataFrame.quantile() function.
2635
2629
 
2636
2630
  Returns:
2637
- -------
2631
+ --------
2638
2632
  Pandas.DataFrame
2639
2633
  Calculate rolling annualized downside Value At Risk "VaR"
2640
2634
 
@@ -2674,7 +2668,7 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2674
2668
  Variance bias factor taking the value 0 or 1.
2675
2669
 
2676
2670
  Returns:
2677
- -------
2671
+ --------
2678
2672
  Pandas.DataFrame
2679
2673
  Calculate rolling annualised volatilities
2680
2674
 
@@ -2701,3 +2695,70 @@ class _CommonModel(BaseModel, Generic[SeriesOrFloat_co]):
2701
2695
  )
2702
2696
 
2703
2697
  return DataFrame(voldf)
2698
+
2699
+ def outliers(
2700
+ self: Self,
2701
+ threshold: float = 3.0,
2702
+ months_from_last: int | None = None,
2703
+ from_date: dt.date | None = None,
2704
+ to_date: dt.date | None = None,
2705
+ ) -> Series | DataFrame:
2706
+ """Detect outliers using z-score analysis.
2707
+
2708
+ Identifies data points where the absolute z-score exceeds the threshold.
2709
+ For OpenTimeSeries, returns a pandas Series with dates and outlier values.
2710
+ For OpenFrame, returns a pandas DataFrame with dates and outlier values
2711
+ for each column.
2712
+
2713
+ Parameters
2714
+ ----------
2715
+ threshold: float, default: 3.0
2716
+ Z-score threshold for outlier detection. Values with absolute
2717
+ z-score > threshold are considered outliers.
2718
+ months_from_last : int, optional
2719
+ Number of months offset as positive integer. Overrides use of from_date
2720
+ and to_date
2721
+ from_date : datetime.date, optional
2722
+ Specific from date
2723
+ to_date : datetime.date, optional
2724
+ Specific to date
2725
+
2726
+ Returns:
2727
+ --------
2728
+ pandas.Series | pandas.DataFrame
2729
+ For OpenTimeSeries: Series with dates as index and outlier values.
2730
+ For OpenFrame: DataFrame with dates as index and outlier values for
2731
+ each column.
2732
+ Returns empty Series/DataFrame if no outliers found.
2733
+
2734
+ """
2735
+ earlier, later = self.calc_range(
2736
+ months_offset=months_from_last,
2737
+ from_dt=from_date,
2738
+ to_dt=to_date,
2739
+ )
2740
+
2741
+ # Get the data for the specified date range
2742
+ data = self.tsdf.loc[cast("Timestamp", earlier) : cast("Timestamp", later)]
2743
+
2744
+ # Calculate z-scores for each column
2745
+ z_scores = (data - data.mean()) / data.std()
2746
+
2747
+ # Find outliers where |z-score| > threshold
2748
+ outliers_mask = z_scores.abs() > threshold
2749
+
2750
+ if self.tsdf.shape[1] == 1:
2751
+ # OpenTimeSeries case - return Series
2752
+ outlier_values = data[outliers_mask].iloc[:, 0].dropna()
2753
+ return Series(
2754
+ data=outlier_values.values,
2755
+ index=outlier_values.index,
2756
+ name="Outliers",
2757
+ dtype="float64",
2758
+ )
2759
+ # OpenFrame case - return DataFrame
2760
+ outlier_df = data[outliers_mask].dropna(how="all")
2761
+ return DataFrame(
2762
+ data=outlier_df,
2763
+ dtype="float64",
2764
+ )