Skip to content

Commit 6d40e76

Browse files
committed
docs: update docstrings for CashFlow strategies
1 parent dc7437f commit 6d40e76

File tree

1 file changed

+78
-85
lines changed

1 file changed

+78
-85
lines changed

okama/portfolios/cashflow_strategies.py

Lines changed: 78 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ def __init__(
240240
self._amount = amount
241241
self.indexation = indexation
242242

243-
# TODO: check why default value for `initial_investments` changes in pf.dcf.cashflow_parameters (examples/10 forecasting.ipyng)
244-
245243
def __repr__(self):
246244
dic = {
247245
"Strategy name": self.NAME,
@@ -310,7 +308,17 @@ class PercentageStrategy(CashFlow):
310308
Parameters
311309
----------
312310
parent : Portfolio
313-
Parent Portfolio instance.
311+
The parent Portfolio instance.
312+
frequency : str, optional
313+
Frequency of cash flows. Default is "none".
314+
initial_investment : float, optional
315+
Initial investment amount. Default is 1000.0.
316+
time_series_dic : dict, optional
317+
Dictionary with dates and cash flow values. Default is empty dict.
318+
time_series_discounted_values : bool, optional
319+
If True, values in time_series_dic are considered as discounted (PV). Default is False.
320+
percentage : float, optional
321+
Percentage of portfolio balance to be withdrawn or contributed. Negative for withdrawals. Default is 0.0.
314322
315323
Examples
316324
--------
@@ -339,24 +347,6 @@ def __init__(
339347
time_series_discounted_values: bool = False,
340348
percentage: float = 0.0,
341349
):
342-
"""
343-
Initialize the PercentageStrategy.
344-
345-
Parameters
346-
----------
347-
parent : Portfolio
348-
The parent Portfolio instance.
349-
frequency : str, optional
350-
Frequency of cash flows. Default is "none".
351-
initial_investment : float, optional
352-
Initial investment amount. Default is 1000.0.
353-
time_series_dic : dict, optional
354-
Dictionary with dates and cash flow values. Default is empty dict.
355-
time_series_discounted_values : bool, optional
356-
If True, values in time_series_dic are considered as discounted (PV). Default is False.
357-
percentage : float, optional
358-
Percentage of portfolio balance to be withdrawn or contributed. Negative for withdrawals. Default is 0.0.
359-
"""
360350
super().__init__(
361351
parent,
362352
frequency=frequency,
@@ -410,7 +400,13 @@ class TimeSeriesStrategy(CashFlow):
410400
Parameters
411401
----------
412402
parent : Portfolio
413-
Parent Portfolio instance.
403+
The parent Portfolio instance.
404+
initial_investment : float, optional
405+
Initial investment amount. Default is 0.
406+
time_series_dic : dict, optional
407+
Dictionary with dates and cash flow values. Default is empty dict.
408+
time_series_discounted_values : bool, optional
409+
If True, values in time_series_dic are considered as discounted (PV). Default is False.
414410
415411
Examples
416412
--------
@@ -437,20 +433,6 @@ def __init__(
437433
time_series_dic: dict = {},
438434
time_series_discounted_values: bool = False
439435
):
440-
"""
441-
Initialize the TimeSeriesStrategy.
442-
443-
Parameters
444-
----------
445-
parent : Portfolio
446-
The parent Portfolio instance.
447-
initial_investment : float, optional
448-
Initial investment amount. Default is 0.
449-
time_series_dic : dict, optional
450-
Dictionary with dates and cash flow values. Default is empty dict.
451-
time_series_discounted_values : bool, optional
452-
If True, values in time_series_dic are considered as discounted (PV). Default is False.
453-
"""
454436
super().__init__(
455437
parent,
456438
frequency="none",
@@ -477,6 +459,30 @@ class VanguardDynamicSpending(PercentageStrategy):
477459
The withdrawal amount is calculated as a percentage of the portfolio balance,
478460
but it is limited by a ceiling and a floor.
479461
The ceiling and floor are calculated based on the previous year's withdrawal amount.
462+
463+
Parameters
464+
----------
465+
parent : Portfolio
466+
The parent Portfolio instance.
467+
initial_investment : float, optional
468+
Initial investment amount. Default is 1000.0.
469+
time_series_dic : dict, optional
470+
Dictionary with dates and cash flow values. Default is empty dict.
471+
time_series_discounted_values : bool, optional
472+
If True, values in time_series_dic are considered as discounted (PV). Default is False.
473+
percentage : float, optional
474+
Percentage of portfolio balance to be withdrawn. Negative value. Default is 0.0.
475+
min_max_annual_withdrawal : tuple[float, float], optional
476+
Minimum and maximum annual withdrawal limits (positive values). Default is None.
477+
adjust_min_max : bool, optional
478+
If True, min and max limits are adjusted by indexation. Default is True.
479+
floor_ceiling : tuple[float, float], optional
480+
Floor and ceiling percentages relative to the previous year's withdrawal.
481+
Example: (-0.025, 0.05) means floor is -2.5% and ceiling is +5%. Default is None.
482+
adjust_floor_ceiling : bool, optional
483+
If True, floor and ceiling are adjusted by indexation. Default is False.
484+
indexation : str or float, optional
485+
Indexation rate. Default is None.
480486
"""
481487
NAME = "VDS"
482488
def __init__(
@@ -495,29 +501,7 @@ def __init__(
495501
"""
496502
Initialize the VanguardDynamicSpending strategy.
497503
498-
Parameters
499-
----------
500-
parent : Portfolio
501-
The parent Portfolio instance.
502-
initial_investment : float, optional
503-
Initial investment amount. Default is 1000.0.
504-
time_series_dic : dict, optional
505-
Dictionary with dates and cash flow values. Default is empty dict.
506-
time_series_discounted_values : bool, optional
507-
If True, values in time_series_dic are considered as discounted (PV). Default is False.
508-
percentage : float, optional
509-
Percentage of portfolio balance to be withdrawn. Negative value. Default is 0.0.
510-
min_max_annual_withdrawal : tuple[float, float], optional
511-
Minimum and maximum annual withdrawal limits (positive values). Default is None.
512-
adjust_min_max : bool, optional
513-
If True, min and max limits are adjusted by indexation. Default is True.
514-
floor_ceiling : tuple[float, float], optional
515-
Floor and ceiling percentages relative to the previous year's withdrawal.
516-
Example: (-0.025, 0.05) means floor is -2.5% and ceiling is +5%. Default is None.
517-
adjust_floor_ceiling : bool, optional
518-
If True, floor and ceiling are adjusted by indexation. Default is False.
519-
indexation : str or float, optional
520-
Indexation rate. Default is None.
504+
521505
"""
522506
super().__init__(
523507
parent=parent,
@@ -743,6 +727,28 @@ class CutWithdrawalsIfDrawdown(IndexationStrategy):
743727
Withdrawal strategy that reduces the withdrawal amount if the portfolio drawdown exceeds a certain threshold.
744728
745729
The reduction coefficients are defined in `crash_threshold_reduction` list of tuples.
730+
731+
Parameters
732+
----------
733+
parent : Portfolio
734+
The parent Portfolio instance.
735+
frequency : str, optional
736+
Frequency of cash flows. Default is "year".
737+
initial_investment : float, optional
738+
Initial investment amount. Default is 1000.0.
739+
time_series_dic : dict, optional
740+
Dictionary with dates and cash flow values. Default is empty dict.
741+
time_series_discounted_values : bool, optional
742+
If True, values in time_series_dic are considered as discounted (PV). Default is False.
743+
amount : float, optional
744+
Regular withdrawal amount (negative value) before reduction. Default is 0.0.
745+
The frequency of withdrawals is determined by the `frequency` parameter.
746+
indexation : str or float, optional
747+
Indexation rate for the withdrawal amount. Default is None.
748+
crash_threshold_reduction : list[tuple[float, float]], optional
749+
List of tuples (threshold, reduction_coefficient).
750+
Example: [(0.20, 0.40)] means if drawdown > 20%, reduce withdrawal by 40%.
751+
Default is [(.20, .40), (.50, 1)].
746752
"""
747753
NAME = "CWID"
748754
def __init__(
@@ -756,31 +762,6 @@ def __init__(
756762
indexation: Optional[Union[str, float]] = None,
757763
crash_threshold_reduction: list[tuple[float, float]] = [(.20, .40), (.50, 1)],
758764
):
759-
"""
760-
Initialize the CutWithdrawalsIfDrawdown strategy.
761-
762-
Parameters
763-
----------
764-
parent : Portfolio
765-
The parent Portfolio instance.
766-
frequency : str, optional
767-
Frequency of cash flows. Default is "year".
768-
initial_investment : float, optional
769-
Initial investment amount. Default is 1000.0.
770-
time_series_dic : dict, optional
771-
Dictionary with dates and cash flow values. Default is empty dict.
772-
time_series_discounted_values : bool, optional
773-
If True, values in time_series_dic are considered as discounted (PV). Default is False.
774-
amount : float, optional
775-
Regular withdrawal amount (negative value) before reduction. Default is 0.0.
776-
The frequency of withdrawals is determined by the `frequency` parameter.
777-
indexation : str or float, optional
778-
Indexation rate for the withdrawal amount. Default is None.
779-
crash_threshold_reduction : list[tuple[float, float]], optional
780-
List of tuples (threshold, reduction_coefficient).
781-
Example: [(0.20, 0.40)] means if drawdown > 20%, reduce withdrawal by 40%.
782-
Default is [(.20, .40), (.50, 1)].
783-
"""
784765
super().__init__(
785766
parent=parent,
786767
frequency=frequency,
@@ -811,7 +792,19 @@ def __repr__(self):
811792
@property
812793
def crash_threshold_reduction(self):
813794
"""
814-
List of tuples (threshold, reduction_coefficient).
795+
List of tuples (threshold, reduction_coefficient) that define how much withdrawals are reduced
796+
based on the portfolio drawdown depth.
797+
798+
Example
799+
-------
800+
crash_threshold_reduction = [
801+
(.05, .20),
802+
(.10, .40),
803+
(.20, .50),
804+
(.30, 1)
805+
]
806+
If drawdown is 5%, reduce withdrawal by 20%; if 10%, reduce by 40%; if 20%, reduce by 50%.
807+
If drawdown is 30% or more, withdrawals stop entirely (100% reduction).
815808
"""
816809
return self._crash_threshold_reduction
817810

0 commit comments

Comments
 (0)