Skip to content

Commit 3411efa

Browse files
committed
feat: add __getitem__ to ListMaker
1 parent 184fcf1 commit 3411efa

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
al = ok.AssetList(['SPY.US', ok.Portfolio()])
44

5+
print(al[0].symbol)
6+
57
for a in al:
68
print(a.symbol)

okama/common/make_asset_list.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def __repr__(self):
101101
def __len__(self):
102102
return len(self.symbols)
103103

104+
def __getitem__(self, item):
105+
return list(self.asset_obj_dict.values())[item]
106+
104107
def _make_list(self, ls: list, first_date, last_date) -> dict:
105108
"""
106109
Make an asset list from a list of symbols.
@@ -264,7 +267,7 @@ def _get_single_asset_dividends(self, tick: str, remove_forecast: bool = True) -
264267
if asset.currency != self.currency:
265268
s = self._adjust_price_to_currency_monthly(s, asset.currency)
266269
if remove_forecast:
267-
s = s[: pd.Period.now(freq="M")]
270+
s = s[: pd.Period.now(freq="M")] # Period.now() must be without arguments to be compatible with pandas 2.0
268271
# Create time series with zeros to pad the empty spaces in dividends time series
269272
index = pd.date_range(start=self.first_date, end=self.last_date, freq="MS") # 'MS' to include the last period
270273
period = index.to_period("M")

0 commit comments

Comments
 (0)