
    EPj              	           S r SSKJrJrJrJr  SSKJr  SSKJ	r	J
r
  SSKJr  SSKJrJr  \" 5       r\R#                  S\S9\R$                  " S	5      \" \	5      4S
\S\S\4S jj5       5       rg)uF   Credit Peer Curve router — OAS term structure across peer universes.    )	APIRouterDependsHTTPExceptionRequest)limiter)get_registryrun_sync)ServiceRegistry)PeerCurveResponsePeerCurveUniverseOASz/peer-curve)response_modelz	10/minuterequestissuerregistryc                   #     [        UR                  R                  U5      I Sh  vN nUS   R                  5        VVs0 s H  u  pVU[        S0 UD6_M     nnn[        US   UR                  S5      UR                  S5      UR                  S5      UR                  S	/ 5      UR                  S
5      UUS   US   UR                  SS5      S9
$  N! [         a  n[	        S[        U5      S9eSnAff = fs  snnf 7f)u9  
Build the Credit Peer Curve for a given issuer.

Returns average OAS (or Z-spread fallback) per maturity bucket across
7 peer universes: issuer, rating peers, sector, sub-sector, and
their intersections.

First call per issuer takes 60–120 s (fetching ~350 bonds from LSEG).
Results are cached for 30 minutes.
Ni  )status_codedetailtabler   sector
sub_sectorrating_bucketrating_peer_bucketslower_rating_bucketbond_counts
chart_dataspread_sourcez_spread)
r   r   r   r   r   r   r   r   r   r    )
r	   peer_curve_servicebuild
ValueErrorr   stritemsr   r   get)r   r   r   resultexcbucketrowr   s           3/root/lseg-credit/backend/app/routers/peer_curve.py
peer_curver*      s    "> ; ; A A6JJ "'?0022KF 	$+s++2 
 
 hzz(#::l+jj1"JJ'<bA"JJ'<==),'jj*=  K >CH==>sD   D#C CC DC;A:DC 
C8 C33C88	DN)__doc__fastapir   r   r   r   app.mainr   app.dependenciesr   r	   app.services.registryr
   app.models.schemasr   r   routerr$   limitr"   r*   r       r)   <module>r4      sx    L > >  3 1 F	 M*;<{ !( 5$$$ $  =$r3   