@@ -259,7 +259,7 @@ def from_weights_market_initial_capital(
259259 return results
260260
261261 @cached_property
262- def holdings (self ) -> PastView [float , IndexT ]:
262+ def quantities_held (self ) -> PastView [float , IndexT ]:
263263 weights = self .weights .by_security .to_dataframe (lazy = True )
264264 prices = self .market .prices .close .by_security .to_dataframe (lazy = True )
265265
@@ -273,10 +273,35 @@ def holdings(self) -> PastView[float, IndexT]:
273273 )
274274 if dtype .is_numeric ()
275275 ]
276+ nav_series = pl .Series (self .nav )
276277
277- result = joined .select (
278+ qtys = joined .select (
278279 "date" ,
279- * [(pl .col (c ) * pl .col (f"{ c } _p" )).alias (c ) for c in numeric_cols ],
280+ * [
281+ (pl .col (c ) * nav_series / pl .col (f"{ c } _p" )).alias (c )
282+ for c in numeric_cols
283+ ],
280284 )
281285
282- return self ._backend .from_dataframe (result .collect ())
286+ return self ._backend .from_dataframe (qtys .collect ())
287+
288+ @cached_property
289+ def values_held (self ) -> PastView [float , IndexT ]:
290+ weights = self .weights .by_security .to_dataframe (lazy = True )
291+
292+ weights_schema = weights .collect_schema ()
293+ numeric_cols = [
294+ name
295+ for name , dtype in zip (
296+ weights_schema .names (), weights_schema .dtypes (), strict = True
297+ )
298+ if dtype .is_numeric ()
299+ ]
300+ nav_series = pl .Series (self .nav )
301+
302+ values = weights .select (
303+ "date" ,
304+ * [(pl .col (c ) * nav_series ).alias (c ) for c in numeric_cols ],
305+ )
306+
307+ return self ._backend .from_dataframe (values .collect ())
0 commit comments