@@ -193,8 +193,9 @@ def pandl_for_instrument_across_contracts(
193
193
) -> pd .DataFrame :
194
194
## can return missing contract
195
195
pandl_store = self .instrument_pandl_store
196
- pandl_for_instrument = pandl_store .get (instrument_code , missing_data )
197
- if pandl_for_instrument is missing_data :
196
+ try :
197
+ pandl_for_instrument = pandl_store [instrument_code ]
198
+ except KeyError :
198
199
pandl_for_instrument = self ._get_pandl_for_instrument_across_contracts (
199
200
instrument_code
200
201
)
@@ -204,9 +205,11 @@ def pandl_for_instrument_across_contracts(
204
205
205
206
@property
206
207
def instrument_pandl_store (self ):
207
- store = getattr (self , "_instrument_pandl_store" , missing_data )
208
- if store is missing_data :
209
- store = self ._instrument_pandl_store = {}
208
+ try :
209
+ store = getattr (self , "_instrument_pandl_store" )
210
+ except AttributeError :
211
+ store = {}
212
+ setattr (self , "_instrument_pandl_store" , store )
210
213
return store
211
214
212
215
def _get_pandl_for_instrument_across_contracts (
@@ -274,8 +277,9 @@ def perc_pandl_series_for_strategy_instrument_vs_total_capital(
274
277
strategy_pandl_store = self .strategy_pandl_store
275
278
store_key = instrument_strategy .key
276
279
277
- pandl_series = strategy_pandl_store .get (store_key , missing_data )
278
- if pandl_series is missing_data :
280
+ try :
281
+ pandl_series = strategy_pandl_store [store_key ]
282
+ except KeyError :
279
283
pandl_series = (
280
284
self ._get_perc_pandl_series_for_strategy_instrument_vs_total_capital (
281
285
instrument_strategy
@@ -297,9 +301,11 @@ def _get_perc_pandl_series_for_strategy_instrument_vs_total_capital(
297
301
298
302
@property
299
303
def strategy_pandl_store (self ):
300
- store = getattr (self , "_strategy_pandl_store" , missing_data )
301
- if store is missing_data :
302
- store = self ._strategy_pandl_store = {}
304
+ try :
305
+ store = getattr (self , "_strategy_pandl_store" )
306
+ except AttributeError :
307
+ store = {}
308
+ setattr (self , "_strategy_pandl_store" , store )
303
309
return store
304
310
305
311
0 commit comments