@@ -36,7 +36,8 @@ class InMemoryPortfolioService(BasePortfolioService):
3636
3737 def __init__ (
3838 self ,
39- initial_capital : float ,
39+ free_cash : float ,
40+ total_cash : float ,
4041 initial_positions : Dict [str , PositionSnapshot ],
4142 trading_mode : TradingMode ,
4243 market_type : MarketType ,
@@ -46,11 +47,16 @@ def __init__(
4647 # Store owning strategy id on the view so downstream components
4748 # always see which strategy this portfolio belongs to.
4849 self ._strategy_id = strategy_id
49- position_value = sum (
50+ net_exposure = sum (
5051 value .notional
5152 for value in initial_positions .values ()
5253 if value .notional is not None
5354 )
55+ gross_exposure = sum (
56+ abs (value .notional )
57+ for value in initial_positions .values ()
58+ if value .notional is not None
59+ )
5460 total_unrealized_pnl = sum (
5561 value .unrealized_pnl
5662 for value in initial_positions .values ()
@@ -59,16 +65,16 @@ def __init__(
5965 self ._view = PortfolioView (
6066 strategy_id = strategy_id ,
6167 ts = int (datetime .now (timezone .utc ).timestamp () * 1000 ),
62- account_balance = initial_capital + position_value ,
68+ account_balance = free_cash ,
6369 positions = initial_positions ,
64- gross_exposure = position_value ,
65- net_exposure = position_value ,
70+ gross_exposure = gross_exposure ,
71+ net_exposure = net_exposure ,
6672 constraints = constraints or None ,
67- total_value = initial_capital + position_value ,
73+ total_value = total_cash + total_unrealized_pnl ,
6874 total_unrealized_pnl = total_unrealized_pnl ,
6975 total_realized_pnl = 0.0 ,
70- buying_power = initial_capital ,
71- free_cash = initial_capital ,
76+ buying_power = free_cash ,
77+ free_cash = free_cash ,
7278 )
7379 self ._trading_mode = trading_mode
7480 self ._market_type = market_type
0 commit comments