a
    >E�j  ã                   @   sö  d Z ddlZddlZddlZej dd¡ ddlZdZdd„ Z	ddd	d
œddddœddddœdœZ
e	ƒ Zedƒ edd›ddd›ddd›ddd›�ƒ d ZZee ¡ ƒD �]\ZZeeƒdkrÂqªdd„ e ¡ D ƒZee ¡ ƒZd d„ e ¡ D ƒZe ei ¡Zed! dk�rd"nd#Zd$d„ e ¡ D ƒZed! dk�r<ed%7 Ze�rJed%7 Ze d&d'¡ d(d)¡dd… Zeed›ded*›d+ed›de�r¢d,d- d.d/„ e ¡ D ƒ¡ nd0d›�ƒ qªed1e› d2ed3d4„ e ¡ D ƒƒ› d5�ƒ ed6e› d7�ƒ ed8ƒ edd9›dd:d;›dd<d›dd=d>›dd<d›�	ƒ e
 ¡ D ]²\ZZ e !e¡�p<i Ze�rVd?d„ e ¡ D ƒni Zee  ¡ ƒZ"e�r~ed@d/„ e D ƒƒne"Z#e d&d'¡ d(d)¡ddA… Zeed9›de"d›d+e"dB dC›d+e#dD›d+e#dB dC›dE�
ƒ �q&edFƒ edGƒ edHƒ dS )Ia7  Replay today's real maker session against the new rules.

Three rules were added after the live session lost money:
  ENTRY GATE  -- refuse a book whose three touches do not clear 1.00 + fees
  RATCHET     -- never re-quote a leg below where it was first offered
  BUDGET      -- once a leg fills, price the rest to clear the target

The question this answers is not "would we have made money" -- at n=3 that is
unanswerable -- but the more useful one: WHICH of today's fills would each rule
have prevented, and what would the completed books have collected instead.
é    NzE:\soccer\mainz%E:\soccer\research\mm_live_orders.csvc                  C   sÌ   t  dd„ ¡} ttddd��œ}t |¡D ]€}| d¡p8d}d|vrDq(zt| d	¡ƒ}W n tt	fyp   Y q(Y n0 | 
dd
¡\}}| | | }|rž|d |kr(| |¡ q(W d  ƒ n1 s¾0    Y  | S )z0{event: {leg: [prices in cents, in time order]}}c                   S   s
   t  t¡S )N)ÚcollectionsÚdefaultdictÚlist© r   r   ú%E:\soccer\research\mm_rules_replay.pyÚ<lambda>   ó    zload_quotes.<locals>.<lambda>zutf-8Úreplace)ÚencodingÚerrorsZtickerÚ ú-Zprice_centsé   éÿÿÿÿN)r   r   ÚopenÚORDERSÚcsvZ
DictReaderÚgetÚintÚ	TypeErrorÚ
ValueErrorÚrsplitÚappend)ÚbooksZfhÚrÚtÚpÚevZlegÚseqr   r   r   Úload_quotes   s    
*r   é(   é"   é   )ZALAÚTIEZGETé!   é    )ZUNIr#   ZSLAé   éD   é   )ZEXCZPSVr#   )zKXLALIGAGAME-26AUG15ALAGETzKXARGPREMDIVGAME-26AUG15SLAUNIzKXEREDIVISIEGAME-26AUG15EXCPSVz"=== every book we quoted today ===ZbookZ34ú z	entry sumz>9Zgatez>6Úchasedz>7é   c                 C   s   i | ]\}}||d  “qS ©r   r   ©Ú.0Úlr   r   r   r   Ú
<dictcomp>4   r   r0   c                 C   s   i | ]\}}||d  “qS )g      Y@r   )r.   r/   Úvr   r   r   r0   6   r   ZdecisionZREFUSEZtakec                 C   s2   i | ]*\}}t |ƒ|d  k r||d  t |ƒf“qS r,   )Úminr-   r   r   r   r0   9   r   r   ZKXARGPREMDIVGAMEZARGZKXr   z>8zc zyes ú,c                 c   s*   | ]"\}\}}|› d |› d|› �V  qdS )r)   z->Nr   )r.   r/   ÚaZb_r   r   r   Ú	<genexpr>@   r   r5   Znoz
  z of c                 C   s   g | ]}t |ƒd kr|‘qS )r+   )Úlen)r.   Úbr   r   r   Ú
<listcomp>B   r   r8   z  books refused by the entry gatez  z< books had at least one leg walked DOWN from its first quotez'
=== the three books that completed ===Z30Z	collectedz>10zvs 1.00zwith ratchetz>13c                 C   s   i | ]\}}||d  “qS r,   r   r-   r   r   r   r0   J   r   c                 c   s(   | ] }t t |d ¡t |d ¡ƒV  qdS )r   N)ÚmaxÚfillsr   Úentry)r.   r/   r   r   r   r5   N   r   é   éd   z>+8z>12ÚczC
  The ratchet alone recovers only what the chase gave away. Two ofzE  these books never had an edge to protect -- which is what the entryzB  gate is for, and it refuses them before a single leg is offered.)$Ú__doc__r   r   ÚsysÚpathÚinsertZmm_maker_liveZMLr   r   ZFILLSr   ÚprintZgatedr*   ÚsortedÚitemsr   Zlegsr6   r;   ÚsumÚvaluesZesumZasksZbook_budgetr7   ÚgZdroppedr	   ÚnameÚjoinr:   r   ZactualZratchr   r   r   r   Ú<module>   sX   


ý&&ÿ
(.<