a
    i›xjâ(  ã                   @   s²   d Z ddlZddlZddlZddlZddlZddlZddlmZ ej	 
dd¡ ddlmZ edƒZedƒZedƒZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zedkr®e eƒ ¡ dS )aÆ  One-shot reminder: review xhigh, and re-check a Poly-US-only rule.

Scheduled for 2026-09-13 (about five weeks after the 2026-08-09 freeze). Emails
a live summary read straight out of the forward-test log, then the Windows task
that fires it is a one-off, so nothing recurs.

WHY A SCHEDULED TASK AND NOT A CHAT REMINDER: Claude's own cron jobs are
session-only and expire after 7 days, so they cannot carry five weeks. This runs
off Task Scheduler on the box, which survives reboots and closed sessions.

WHAT TO CHECK, AND THE TRAPS
  * xhigh was frozen 2026-08-09 (Kalshi-only, mid>=0.20, CLV in [0.05,0.12)).
    It needs ~480 bets. Anything below that is directional only.
  * Its discovery numbers (+15.1%, z+1.33) came from post-2026-07-05 data that
    was ALREADY the xlow forward-test window -- selection, not validation. Only
    fixtures after the freeze count. Expect the effect to shrink.
  * Poly-US-only was swept on 2026-08-09 and NOT frozen: the price-floor effect
    reproduced (+16.1% at minP>=0.20) but train and test disagreed in sign, and
    persistence hurt. Deliberately deferred to avoid a second frozen rule
    doubling the multiple-comparison exposure.
  * xhigh and xlow OVERLAP -- both fire on Kalshi CLV in the same band. If both
    look good, that is largely the same bets, not two pieces of evidence.
  * Better than freezing a Poly-US rule: split xhigh's OWN realised bets by
    venue. That answers "is the edge venue-dependent" for free.
é    N)ÚPathzE:\soccer\main)Ú
send_emailz3E:\soccer\research\forward_test_unique_book_log.csvz(E:\soccer\research\pin_fresh_capture.csvz*E:\soccer\research\pin_accuracy_cache.jsonc                  C   sJ   z.dd„ t  ttdd�¡D ƒ} | r*| d ni W S  tyD   i  Y S 0 d S )Nc                 S   s   g | ]}|‘qS © r   )Ú.0Úrr   r   ú'E:\soccer\main\reminder_xhigh_review.pyÚ
<listcomp>,   ó    zlatest.<locals>.<listcomp>úutf-8©Úencodingéÿÿÿÿ)ÚcsvÚ
DictReaderÚopenÚLOGÚ	Exception)Úrowsr   r   r   Úlatest*   s
    r   c              	   C   s(   z
t | ƒW S  ttfy"   Y d S 0 d S )N)ÚfloatÚ	TypeErrorÚ
ValueError)Úxr   r   r   Ú_f2   s    
r   c               	   C   sØ  i } t  ¡ s| S tt tt dd�¡ƒ}t|ƒ| d< t dd„ ¡}|D ]`}|d |d |d |d	 f}| 	d
¡r„|| d  
|d
 ¡ | 	d¡rD|| d  
|d ¡ qDdd„ | ¡ D ƒ}t|ƒpÂd}t|ƒ| d< tdd„ | ¡ D ƒƒ| d< tdd„ | ¡ D ƒƒ| d< tdd„ | ¡ D ƒƒ| d< tdd„ | ¡ D ƒƒ| d< d| d  | | d< t t¡}|D ]†}dD ]z}t| 	d|› �¡ƒt| 	d|› �¡ƒ }	}
|	d u �sb|
d u �r¨�qb|	d!k�r¶d"n|	d#k�rÄd$nd%}||  |
|	 ¡ �qb�qZd&D ],}|| �rædt || ¡ | d'|› �< �qæzt tjdd�¡}W n t�yB   i }Y n0 i }|D ]X}|d › d(|d › d(|d › d(|d	 › �}||v�sš|d) || d) k�rL|||< �qLg }| ¡ D ]¸\}}| 	|¡}|�sÎ�q²t|d* ƒt|d+ ƒ }}t|d, ƒt|d- ƒ }}d ||||fv �r�q²d.|d/k d.|d0k  }}| || d1 || d1  || d1 || d1   ¡ �q²t|ƒd2k�rÔt |¡}t |¡�p’d3}|t t|ƒ¡ }| jt|ƒ|||| |d4|  |d4|  d5� | S )6a®  Live read of the pinnapi-vs-API-Football comparison.

    Three separate questions, deliberately reported apart because they answered
    differently as of 2026-08-09 and conflating them caused real confusion:

      ACCURACY  paired Brier per fixture. The only clean test -- paired, uses
                every fixture, no entry reconstruction. Needed ~580 fixtures.
                It FLIPPED SIGN (+0.0096 -> -0.0078) when n went 26 -> 77, which
                is why nothing below target should be believed.
      DIVERGENCE how often the two feeds produce a different bet. This is NOT
                evidence either is better -- only that the choice matters.
      BIAS      API-Football rounds odds to 2dp (1.50 where pinnapi says
                1.5917). Measured as a monotonic gradient: it underprices
                favourites and overprices long shots. This is a MECHANISM and
                was stable across sample sizes.
    r
   r   Z	snapshotsc                   S   s   t ƒ t ƒ dœS )N©ÚsÚf)Úsetr   r   r   r   Ú<lambda>R   r	   z!pinnapi_summary.<locals>.<lambda>ZlcÚhomeZawayZ	game_dateZ
xlow_staler   Z
xlow_freshr   c                 S   s&   i | ]\}}|d  s|d r||“qS r   r   )r   ÚkÚvr   r   r   Ú
<dictcomp>Y   r	   z#pinnapi_summary.<locals>.<dictcomp>é   Úsig_fixturesc                 s   s*   | ]"}|d  r|d  |d krdV  qdS ©r   r   r#   Nr   ©r   r!   r   r   r   Ú	<genexpr>\   r	   z"pinnapi_summary.<locals>.<genexpr>Úsamec                 s   s"   | ]}|d  r|d sdV  qdS r%   r   r&   r   r   r   r'   ]   r	   Úaf_onlyc                 s   s"   | ]}|d  r|d sdV  qdS )r   r   r#   Nr   r&   r   r   r   r'   ^   r	   Úpin_onlyc                 s   s2   | ]*}|d  r|d r|d  |d krdV  qdS r%   r   r&   r   r   r   r'   _   s    ÿÚdifferg      Y@Ú	agree_pct)ÚhÚaZfair_fresh_Zfair_stale_Ng      à?Úfavg      Ð?ÚmidÚdog©r/   r0   r1   Úbias_ú|ZtsZfair_fresh_hZfair_fresh_aZfair_stale_hZfair_stale_ag      ð?ÚHÚAé   é
   g•Ö&è.>g\�Âõ(\ÿ?)Úacc_nÚacc_meanÚacc_seÚacc_zÚacc_loÚacc_hi)ÚCAPTUREÚexistsÚlistr   r   r   ÚlenÚcollectionsÚdefaultdictÚgetÚaddÚitemsÚsumÚvaluesr   ÚappendÚ
statisticsZmeanÚjsonÚloadsÚ	ACC_CACHEÚ	read_textr   ZpstdevÚmathZsqrtÚupdate)Úoutr   Zfxr   r    ZsigÚnZsgÚtÚfrÚstÚbÚcacheZlastZdiffsZftrZfhZfaZshZsaZyhZyaÚmZsdZser   r   r   Úpinnapi_summary9   sz    


* 
 
* 
ÿ

ÿrZ   c                    s4  ˆ sdS dˆ v r°ˆ d dkr dnˆ d dk r0dnd}ˆ d d	krDd
ndd	ˆ d  › d�}dˆ d › dˆ d d›dˆ d d›dˆ d d›dˆ d d›dˆ d d›d|› |› d�}nd}d  ‡ fdd„dD ƒ¡}d |› d!ˆ  d"d¡› d#ˆ  d$d¡› d%ˆ  d&d¡d'›d(ˆ  d)d¡› d*ˆ  d+d¡› d,ˆ  d-d¡› d.|› d/�S )0Nz=<h3>pinnapi vs API-Football</h3><p>No capture data found.</p>r9   r=   r   z<b>pinnapi more accurate</b>r>   z!<b>API-Football more accurate</b>z<b>no measurable difference</b>iD  Ú z &mdash; still z1 short of the 580 target, so treat as directionalz!<li><b>Accuracy (paired Brier, n=z):</b> r:   z+.5fz (SE r;   z.5fz, z r<   ú+.2fz), 95% CI [z, z	] &rarr; z</li>z=<li><b>Accuracy:</b> too few settled fixtures to report.</li>z / c                 3   s@   | ]8}d |› �ˆ v r|› dˆ   d |› �tdƒ¡d›d�V  qdS )r3   ú Únanr\   ÚcN)rE   r   )r   rW   ©Úpr   r   r'   Ÿ   s   ÿz!build_pin_html.<locals>.<genexpr>r2   z)
<h3>pinnapi vs API-Football</h3>
<ul>
  z
  <li><b>Signal divergence (r$   z7 fixtures that produced a
      signal):</b> identical r(   z
      (r,   z.0fz%), API-Football only r)   z,
      pinnapi only r*   z%, both fired but DIFFERENT bet
      r+   zœ. Divergence shows the feed choice <i>matters</i>;
      it is not evidence either is better.</li>
  <li><b>Rounding bias (API-Football minus pinnapi):</b> a  . A monotonic
      gradient = API-Football's 2dp rounding underpricing favourites and
      overpricing long shots. This was stable across sample sizes &mdash; the
      one solid finding of the exercise.</li>
</ul>
<p><b>Traps.</b> The accuracy figure <b>flipped sign</b> (+0.0096 &rarr;
&minus;0.0078) when n went 26&rarr;77, so anything below target is noise. And a
positive result justifies <b>recalibrating the xlow band against the fresh
line and re-testing</b> &mdash; NOT switching the live feed, which stays on
API-Football so the frozen forward tests keep running. Given the rounding
gradient, a band tuned to a biased anchor will not transfer to an unbiased one.</p>
<p>Re-run: <code>python research\pin_accuracy_test.py</code> and
<code>python research\pin_fresh_vs_stale.py</code></p>
)ÚjoinrE   )ra   ZverdictÚtargetZaccZbiasr   r`   r   Úbuild_pin_html�   s\    þÿÿÿÿþþýý
ÿý
ü
û
ú
ú
ù
ø
örd   c                  C   s¸   t ƒ } |  d¡pd}ttƒ ƒ}d|  dd¡› d|› d|  dd	¡› d
|  dd	¡› d|  dd	¡› d|  dd	¡› d|  dd	¡› d|  dd	¡› d|› d�}td|ƒ}t|r¦dndƒ |r´dS dS )NZxhigh_nÚ0z©
<h2>Reminder: review xhigh (and revisit Poly-US)</h2>

<p>Frozen 2026-08-09. Set as a five-week checkpoint.</p>

<h3>Where xhigh stands (from the forward-test log, run Zrun_dateú?z)</h3>
<ul>
  <li><b>n = z<</b> of the ~480 needed to resolve the effect</li>
  <li>WR Zxhigh_wrú-z% &nbsp; ROI Z	xhigh_roiz% &nbsp;
      z Zxhigh_zz#</li>
  <li>xlow for comparison: n=Zxlow_nz ROI Zxlow_roiz
%
      z Zxlow_zaw  </li>
</ul>

<h3>Read it with these in mind</h3>
<ul>
  <li>xhigh's discovery numbers (+15.1%) came from data that was already the
      xlow forward-test window. That was <b>selection, not validation</b> &mdash;
      expect the real effect to be smaller.</li>
  <li>The reason it was frozen was <b>measurability</b>, not ROI: a price floor
      cut the required sample from ~201,000 bets to ~480. 17 candidates were
      swept and none reached z&gt;1.96.</li>
  <li><b>xhigh overlaps xlow.</b> Both fire on Kalshi CLV in the same band. Two
      green numbers here are largely the same bets.</li>
  <li>If n is still well short of 480, say so and wait. Do not read a partial
      sample as a verdict.</li>
</ul>

<h3>The Poly-US question that was deferred</h3>
<p>Swept 2026-08-09, not frozen: the price floor reproduced (+16.1% at
minP&ge;0.20, needing only ~370 bets) but <b>train and test disagreed in sign</b>
and persistence hurt every variant. The cheaper next step is to split xhigh's own
realised bets by venue rather than freeze a second rule.</p>

<p>Poly-US also pays a <b>maker rebate</b> where Kalshi charges a taker fee. If
the floor effect survives, that is an execution reason to prefer it &mdash; a
separate question from whether the signal is better.</p>

<p>Re-run: <code>python research\rule_sweep.py</code> and
<code>python research\forward_test_unique_book.py</code></p>

Ú
z.[REMINDER] Review xhigh + revisit Poly-US ruleZsentzsend failedr   r#   )r   rE   rd   rZ   r   Úprint)r   rS   Zpin_htmlÚbodyZokr   r   r   Úmain»   s2    

ûù
ø
ø	
÷

ö

ö
õ)×+
rk   Ú__main__)Ú__doc__rC   r   rL   rP   rK   ÚsysÚpathlibr   ÚpathÚinsertZdaily_signalsr   r   r?   rN   r   r   rZ   rd   rk   Ú__name__Úexitr   r   r   r   Ú<module>   s&   V,4