@@ -1149,8 +1149,8 @@ def percentile_inverse_cagr(
11491149 Parameters
11501150 ----------
11511151 distr: {'norm', 'lognorm', 'hist'}, default 'norm'
1152- Distribution type (normal or lognormal) .
1153- If 'hist' historical distribution properties are used .
1152+ The rate of teturn distribution type .
1153+ For 'hist' type percentile is taken from the historical data .
11541154
11551155 years: int, default 1
11561156 Period length (time frame) in years when CAGR is calculated.
@@ -1160,7 +1160,9 @@ def percentile_inverse_cagr(
11601160
11611161 n: int, optional
11621162 Number of random time series with the defined distributions (for 'norm' or 'lognorm' only).
1163- Is not required for historical distribution.
1163+ Larger argument values can be used to increase the precision of the calculation. But this will lead
1164+ to slower performance.
1165+ Is not required for historical distribution (dist='hist').
11641166 For 'norm' or 'lognorm' distribution default value n=1000 is used.
11651167
11661168 Returns
@@ -1180,7 +1182,7 @@ def percentile_inverse_cagr(
11801182 elif distr in ["norm" , "lognorm" ]:
11811183 if not n :
11821184 n = 1000
1183- cagr_distr = self ._get_monte_carlo_cagr_distribution (
1185+ cagr_distr = self ._get_cagr_distribution (
11841186 distr = distr , years = years , n = n
11851187 )
11861188 else :
@@ -1403,13 +1405,13 @@ def _monte_carlo_wealth(
14031405 first_value = self .wealth_index [self .symbol ].values [- 1 ]
14041406 return Frame .get_wealth_indexes (return_ts , first_value )
14051407
1406- def _get_monte_carlo_cagr_distribution (
1408+ def _get_cagr_distribution (
14071409 self , distr : str = "norm" , years : int = 1 , n : int = 100 ,
14081410 ) -> pd .Series :
14091411 """
1410- Generate random CAGR distribution.
1411- CAGR is calculated for each of N future random returns time series.
1412- Random distribution could be normal or lognormal .
1412+ Generate CAGR distribution for the rate of return distribution of a given type .
1413+
1414+ CAGR is calculated for each of n random returns time series .
14131415 """
14141416 if distr not in ["norm" , "lognorm" ]:
14151417 raise ValueError ('distr should be "norm" (default) or "lognorm".' )
@@ -1445,6 +1447,8 @@ def percentile_distribution_cagr(
14451447
14461448 n : int, default 10000
14471449 Number of random time series to generate with Monte Carlo simulation.
1450+ Larger argument values can be used to increase the precision of the calculation. But this will lead
1451+ to slower performance.
14481452
14491453 Returns
14501454 -------
@@ -1463,7 +1467,7 @@ def percentile_distribution_cagr(
14631467 """
14641468 if distr not in ["norm" , "lognorm" ]:
14651469 raise ValueError ('distr should be "norm" (default) or "lognorm".' )
1466- cagr_distr = self ._get_monte_carlo_cagr_distribution (
1470+ cagr_distr = self ._get_cagr_distribution (
14671471 distr = distr , years = years , n = n
14681472 )
14691473 results = {}
@@ -1483,13 +1487,43 @@ def percentile_wealth(
14831487 """
14841488 Calculate percentiles for portfolio wealth indexes distribution.
14851489
1486- Portfolio wealth indexes are derived from CAGR time series with given distribution type.
1487- CAGR - Compound Annual Growth Rate.
1490+ Portfolio wealth indexes are derived from the rate of return time series of a given distribution type.
1491+
1492+ Parameters
1493+ ----------
1494+ distr : {'hist', 'norm', 'lognorm'}, default 'norm'
1495+ Distribution type for the rate of return of portfolio.
1496+ For 'hist' type percentiles are taken from the historical data.
1497+
1498+ years : int, default 1
1499+ Investment period length to calculate wealth index.
1500+ It should not exceed 1/2 of the portfolio history period length 'period_length'.
1501+
1502+ percentiles : list of int, default [10, 50, 90]
1503+ List of percentiles to be calculated.
1504+
1505+ today_value : int, optional
1506+ Initial value of the wealth index.
1507+ If today_value is None the last value of the historical wealth indexes is taken. It can be useful to plot
1508+ the forecast of wealth index togeather with the hitorical data.
1509+
1510+ n : int, default 1000
1511+ Number of random time series to generate with Monte Carlo simulation (for 'norm' or 'lognorm' only).
1512+ Larger argument values can be used to increase the precision of the calculation. But this will lead
1513+ to slower performance.
1514+ Is not required for historical distribution (dist='hist').
14881515
1489- today_value - the value of portfolio today (before forecast period). If today_value is None
1490- the last value of the historical wealth indexes is taken.
1516+ Returns
1517+ -------
1518+ dict
1519+ Dictionary {Percentile: value}
14911520
1492- TODO: finish docstrings
1521+ Examples
1522+ --------
1523+ >>> pf = ok.Portfolio(['SPY.US', 'AGG.US', 'GLD.US'], weights=[.60, .35, .05], rebalancing_period='year')
1524+ >>> pf.percentile_wealth(distr='hist', years=5, today_value=1000, n=5000)
1525+ {10: 1228.3741255659957, 50: 1491.7857161011104, 90: 1745.1130920663286}
1526+ Percentiles values for the wealth index 5 years forecast if the initial value is 1000.
14931527 """
14941528 if distr == "hist" :
14951529 results = (
0 commit comments