Skip to content

Commit 051f185

Browse files
committed
docs: update docstrings
1 parent 0733850 commit 051f185

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

main_notebook.ipynb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"is_executing": true
88
},
99
"ExecuteTime": {
10-
"end_time": "2025-06-24T10:47:59.358922Z",
11-
"start_time": "2025-06-24T10:47:56.923050Z"
10+
"end_time": "2025-06-24T13:40:48.620923Z",
11+
"start_time": "2025-06-24T13:40:46.884104Z"
1212
}
1313
},
1414
"source": [
@@ -35,7 +35,7 @@
3535
"%autoreload 2"
3636
],
3737
"outputs": [],
38-
"execution_count": 3
38+
"execution_count": 1
3939
},
4040
{
4141
"cell_type": "code",
@@ -45,8 +45,8 @@
4545
"outputs_hidden": false
4646
},
4747
"ExecuteTime": {
48-
"end_time": "2025-06-20T05:36:19.175809Z",
49-
"start_time": "2025-06-20T05:36:19.105040Z"
48+
"end_time": "2025-06-24T13:40:51.143568Z",
49+
"start_time": "2025-06-24T13:40:50.317414Z"
5050
}
5151
},
5252
"source": [
@@ -59,12 +59,12 @@
5959
"'1.4.4'"
6060
]
6161
},
62-
"execution_count": 3,
62+
"execution_count": 2,
6363
"metadata": {},
6464
"output_type": "execute_result"
6565
}
6666
],
67-
"execution_count": 3
67+
"execution_count": 2
6868
},
6969
{
7070
"metadata": {},
@@ -1776,8 +1776,8 @@
17761776
{
17771777
"metadata": {
17781778
"ExecuteTime": {
1779-
"end_time": "2025-06-19T04:37:29.958Z",
1780-
"start_time": "2025-06-19T04:37:29.892941Z"
1779+
"end_time": "2025-06-24T13:40:59.950652Z",
1780+
"start_time": "2025-06-24T13:40:59.904179Z"
17811781
}
17821782
},
17831783
"cell_type": "code",
@@ -1787,13 +1787,13 @@
17871787
"assets2 = ['SPY.US', 'AGG.US', 'GC.COMM']"
17881788
],
17891789
"outputs": [],
1790-
"execution_count": 6
1790+
"execution_count": 3
17911791
},
17921792
{
17931793
"metadata": {
17941794
"ExecuteTime": {
1795-
"end_time": "2025-06-19T04:37:30.844845Z",
1796-
"start_time": "2025-06-19T04:37:30.773261Z"
1795+
"end_time": "2025-06-24T13:41:02.307322Z",
1796+
"start_time": "2025-06-24T13:41:02.265496Z"
17971797
}
17981798
},
17991799
"cell_type": "code",
@@ -1805,12 +1805,12 @@
18051805
"['SPY.US', 'AGG.US', 'GC.COMM']"
18061806
]
18071807
},
1808-
"execution_count": 7,
1808+
"execution_count": 4,
18091809
"metadata": {},
18101810
"output_type": "execute_result"
18111811
}
18121812
],
1813-
"execution_count": 7
1813+
"execution_count": 4
18141814
},
18151815
{
18161816
"cell_type": "code",
@@ -1820,8 +1820,8 @@
18201820
"outputs_hidden": false
18211821
},
18221822
"ExecuteTime": {
1823-
"end_time": "2025-06-19T04:38:08.998330Z",
1824-
"start_time": "2025-06-19T04:38:06.774005Z"
1823+
"end_time": "2025-06-24T13:41:16.286421Z",
1824+
"start_time": "2025-06-24T13:41:14.199455Z"
18251825
}
18261826
},
18271827
"source": [
@@ -1832,7 +1832,7 @@
18321832
" ccy=\"USD\",\n",
18331833
" weights=weights,\n",
18341834
" inflation=True,\n",
1835-
" symbol=\"retirement_pf.PF\",\n",
1835+
" # symbol=\"retirement_pf.PF\",\n",
18361836
" rebalancing_strategy=ok.Rebalance(period=\"year\"),\n",
18371837
")\n",
18381838
"print(pf)"
@@ -1842,7 +1842,7 @@
18421842
"name": "stdout",
18431843
"output_type": "stream",
18441844
"text": [
1845-
"symbol retirement_pf.PF\n",
1845+
"symbol portfolio_7354.PF\n",
18461846
"assets [SPY.US, AGG.US, GC.COMM]\n",
18471847
"weights [0.3, 0.55, 0.15]\n",
18481848
"rebalancing_period year\n",
@@ -1857,7 +1857,7 @@
18571857
]
18581858
}
18591859
],
1860-
"execution_count": 9
1860+
"execution_count": 6
18611861
},
18621862
{
18631863
"metadata": {

okama/common/helpers/rebalancing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ class Rebalance:
3939
Attributes
4040
----------
4141
period : {'none', 'month', 'quarter', 'half-year', 'year'}
42-
The rebalancing period for the investment portfolio.
42+
rebalancing period (rebalancing frequency) is predetermined time intervals when
43+
the investor rebalances the portfolio.
44+
If 'none' assets weights are not rebalanced.
4345
4446
abs_deviation : float, optional
4547
The absolute deviation allowed for the assets weights in the portfolio.
4648
It is defined for an asset weight as an absolut value of: actual_weight - target_weight.
4749
It must be more than 0 (0%).
4850
Max value is 1 (100%).
51+
if None the parameter is ignored.
4952
5053
rel_deviation : float, optional
5154
The relative deviation allowed for the assets weights in the portfolio.
5255
It is defined for an asset weight as an absolut value of: actual_weight / target_weight - 1.
5356
it must be positive.
57+
if None the parameter is ignored.
5458
"""
5559

5660
def __init__(

okama/frontier/multi_period.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ class EfficientFrontierReb(asset_list.AssetList):
5656
Including inflation could limit available data (last_date, first_date)
5757
as the inflation data is usually published with a one-month delay.
5858
59-
rebalancing_period : {'year', 'none'}, default 'year'
60-
Rebalancing period of the portfolios in the multi-period Efficient Frontier.
61-
Portfolio is rebalanced every year if rebalancing_period='year'.
62-
Portfolio is not rebalanced if rebalancing_period='none'
59+
rebalancing_strategy : Rebalance, default Rebalance(period='year', abs_deviation=None, rel_deviation=None)
60+
Rebalancing strategy for an investment portfolio. The rebalancing strategy si defined by:
61+
-period (rebalancing frequency): predetermined time intervals when the investor rebalances the portfolio.
62+
If 'none' assets weights are not rebalanced.
63+
-abs_deviation: the absolute deviation allowed for the assets weights in the portfolio.
64+
-rel_deviation: the relative deviation allowed for the assets weights in the portfolio.
6365
6466
n_points : int, default 20
6567
Number of points in the Efficient Frontier.
@@ -977,9 +979,14 @@ def get_monte_carlo(self, n: int = 100) -> pd.DataFrame:
977979
"""
978980
weights_df = helpers.Float.get_random_weights(n, self.assets_ror.shape[1], self.bounds)
979981

982+
args = dict(
983+
period=self.rebalancing_strategy.period,
984+
abs_deviation=self.rebalancing_strategy.abs_deviation,
985+
rel_deviation=self.rebalancing_strategy.rel_deviation
986+
)
980987
# Portfolio risk and cagr for each set of weights
981988
portfolios_ror = weights_df.aggregate(
982-
Rebalance(period=self.rebalancing_period).return_ror_ts,
989+
Rebalance(**args).return_ror_ts,
983990
ror=self.assets_ror,
984991
)
985992
random_portfolios = pd.DataFrame()

okama/portfolio.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ class Portfolio(make_asset_list.ListMaker):
6060
The weight of an asset is the percent of an investment portfolio that corresponds to the asset.
6161
If weights = None an equally weighted portfolio is created (all weights are equal).
6262
63-
rebalancing_strategy : {'none', 'month', 'quarter', 'half-year', 'year'}, default 'month'
64-
Rebalancing period (rebalancing frequency) is predetermined time intervals when
65-
the investor rebalances the portfolio. If 'none' assets weights are not rebalanced.
66-
67-
symbol : str, default None
63+
rebalancing_strategy : Rebalance, default Rebalance(period='year', abs_deviation=None, rel_deviation=None)
64+
Rebalancing strategy for an investment portfolio. The rebalancing strategy si defined by:
65+
-period (rebalancing frequency): predetermined time intervals when the investor rebalances the portfolio.
66+
If 'none' assets weights are not rebalanced.
67+
-abs_deviation: the absolute deviation allowed for the assets weights in the portfolio.
68+
-rel_deviation: the relative deviation allowed for the assets weights in the portfolio.
69+
70+
symbol : str
6871
Text symbol of portfolio. It is similar to tickers but have a namespace information.
6972
Portfolio symbol must end with .PF (all_weather_portfolio.PF).
70-
If None a random symbol is generated (portfolio_7802.PF).
73+
If not defined a random symbol is generated (portfolio_7802.PF).
7174
"""
7275

7376
def __init__(
@@ -80,7 +83,7 @@ def __init__(
8083
inflation: bool = True,
8184
weights: Optional[List[float]] = None,
8285
rebalancing_strategy: Rebalance = Rebalance(period="month"),
83-
symbol: str = None,
86+
symbol: str,
8487
):
8588
super().__init__(
8689
assets,
@@ -3088,7 +3091,6 @@ def find_the_largest_withdrawals_size(
30883091
... target_survival_period=25
30893092
...)
30903093
>>> res
3091-
# TODO: update example results
30923094
success True
30933095
withdrawal_abs -917.96875
30943096
withdrawal_rel 0.091797

0 commit comments

Comments
 (0)