@@ -42,6 +42,9 @@ def build_reconciliation_record(
4242 signal_metadata = dict (signal_metadata or {})
4343 execution_summary = dict (execution_summary or {})
4444 target_weights = dict (target_weights or {})
45+ allocation = dict (signal_metadata .get ("allocation" ) or {})
46+ allocation_safe_haven_symbols = tuple (allocation .get ("safe_haven_symbols" ) or ())
47+ allocation_safe_haven_symbol = allocation_safe_haven_symbols [0 ] if allocation_safe_haven_symbols else None
4548 record = {
4649 "strategy_profile" : strategy_profile ,
4750 "mode" : mode ,
@@ -55,7 +58,11 @@ def build_reconciliation_record(
5558 "realized_stock_weight" : signal_metadata .get ("realized_stock_weight" ),
5659 "target_safe_haven_weight" : signal_metadata .get ("safe_haven_weight" ),
5760 "realized_safe_haven_weight" : execution_summary .get ("realized_safe_haven_weight" ),
58- "safe_haven_symbol" : execution_summary .get ("safe_haven_symbol" ) or signal_metadata .get ("safe_haven_symbol" ),
61+ "safe_haven_symbol" : (
62+ execution_summary .get ("safe_haven_symbol" )
63+ or signal_metadata .get ("safe_haven_symbol" )
64+ or allocation_safe_haven_symbol
65+ ),
5966 "target_holdings" : [
6067 {"symbol" : symbol , "target_weight" : float (weight )}
6168 for symbol , weight in sorted (target_weights .items (), key = lambda item : (- item [1 ], item [0 ]))
@@ -85,6 +92,9 @@ def build_reconciliation_record(
8592
8693def write_reconciliation_record (record : dict [str , Any ], * , output_path : str | Path | None = None ) -> Path :
8794 path = Path (output_path ) if output_path else default_reconciliation_output_path (record .get ("strategy_profile" ))
95+ if output_path and path .suffix .lower () != ".json" :
96+ trade_date = str (record .get ("trade_date" ) or "latest" ).strip () or "latest"
97+ path = path / trade_date / "reconciliation.json"
8898 path .parent .mkdir (parents = True , exist_ok = True )
8999 path .write_text (json .dumps (_json_safe (record ), ensure_ascii = False , indent = 2 , sort_keys = True ), encoding = "utf-8" )
90100 return path
0 commit comments