Skip to content

Commit 17d39a4

Browse files
committed
fix: errors related with floor_ceiling & min_max_annual_withdrawals in VDS
1 parent c65416a commit 17d39a4

File tree

2 files changed

+355
-247
lines changed

2 files changed

+355
-247
lines changed

main_notebook.ipynb

Lines changed: 345 additions & 237 deletions
Large diffs are not rendered by default.

okama/portfolios/cashflow_strategies.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ def __repr__(self):
420420
"Cash flow frequency": self.frequency,
421421
"Cash flow strategy": self.NAME,
422422
"Cash flow percentage": self.percentage, # negative
423-
"Minimum annual withdrawal": self.min_max_annual_withdrawals, # negative
424-
"Maximum annual withdrawal": self.maximum_annual_withdrawal, # negative
425-
"Ceiling": self.ceiling, # positive
426-
"Floor": self.floor, # negative
423+
"Minimum annual withdrawal": self.min_max_annual_withdrawals[0] if self.min_max_annual_withdrawals is not None else None, # positive
424+
"Maximum annual withdrawal": self.min_max_annual_withdrawals[1] if self.min_max_annual_withdrawals is not None else None, # positive
425+
"Floor": self.floor_ceiling[0] if self.floor_ceiling is not None else None, # negative
426+
"Ceiling": self.floor_ceiling[1] if self.floor_ceiling is not None else None, # positive
427427
"Indexation": self.indexation,
428428
}
429429
return repr(pd.Series(dic))
@@ -472,10 +472,10 @@ def floor_ceiling(self, value: Optional[tuple[float, float]]):
472472
ceiling = value[1]
473473
validators.validate_real("floor", floor)
474474
validators.validate_real("ceiling", ceiling)
475-
if floor > 0:
476-
raise ValueError("Floor cannot be positive.")
477-
if ceiling < 0:
478-
raise ValueError("Ceiling cannot be negative.")
475+
if floor >= 0:
476+
raise ValueError("Floor must be negative.")
477+
if ceiling <= 0:
478+
raise ValueError("Ceiling must be positive.")
479479
self._clear_cf_cache()
480480
self._floor_ceiling = value
481481

@@ -518,7 +518,7 @@ def calculate_withdrawal_size(self, last_withdrawal: float, balance: float, numb
518518
if self.min_max_annual_withdrawals is not None:
519519
min_withdrawal = self.min_max_annual_withdrawals[0]
520520
min_indexed = abs(min_withdrawal) * (1 + self.indexation) ** number_of_periods
521-
max_withdrawal = self.maximum_annual_withdrawal[1]
521+
max_withdrawal = self.min_max_annual_withdrawals[1]
522522
max_indexed = abs(max_withdrawal) * (1 + self.indexation) ** number_of_periods
523523
# Chek what limitation is actual
524524
if self.floor_ceiling is not None and self.min_max_annual_withdrawals is not None:
@@ -536,7 +536,7 @@ def calculate_withdrawal_size(self, last_withdrawal: float, balance: float, numb
536536
elif 0 < floor_indexed <= min_indexed:
537537
min_final = min_indexed
538538
else:
539-
# floor = 0
539+
# floor_indexed & ceiling_indexed = 0 for the first withdrawal (last_withdrawal = 0)
540540
min_final = min_indexed
541541
elif self.floor_ceiling is None and self.min_max_annual_withdrawals is not None:
542542
min_final = min_indexed

0 commit comments

Comments
 (0)