
    6Lj                    T   d dl mZ d dlmZ d dlmZmZ d dlmZ dZ	ed         Z
ed         Z ed	           G d
 d                      Z ed	           G d d                      Z ed	           G d d                      Zd&d'dZd(dZd)dZd ed          dd*d$Zd%S )+    )annotations)	dataclass)DecimalROUND_HALF_UP)Literal#candidate_portfolio_holding_advisor)advisor_accumulate_watchadvisor_hold_watch)advisor_watchlistcash_or_waitT)frozenc                  n    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded	<   ded
<   dZded<   dS )HoldingCandidatestrcoinr   pricesma_fastsma_slowmomentum_30d_pctvolume_24h_usdvolatility_30d_pctcorrelation_to_btcTbooldata_quality_allowedN)__name__
__module____qualname____annotations__r        ^/home/agent/projects/CryptoTradingBot/Crypto_Agent/src/strategies/portfolio_holding_advisor.pyr   r      s~         IIINNN!%%%%%%%r    r   c                  L    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<   d
S )HoldingAllocationr   r   r   target_weight_pcttarget_notional_usdcscoreAdvisorActionactionreasonN)r   r   r   r   r   r    r!   r#   r#      sO         III!!!!NNNKKKKKr    r#   c                  ^    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   dZded<   dZded<   dS )PortfolioHoldingAdvicer   strategy_idAdvisorStatusstatuszlist[HoldingAllocation]allocationszdict[str, list[str]]rejectedr   cash_weight_pctFr   live_order_allowedmainnet_signed_actionN)r   r   r   r   r2   r3   r   r    r!   r+   r+   $   sr         ((((""""$$$$$"'''''''r    r+   0.01valuer   placesr   returnc                T    |                      t          |          t                    S )N)rounding)quantizer   r   )r5   r6   s     r!   _qr;   /   s    >>'&//M>BBBr    	candidate	list[str]c                   g }| j         s|                    d           | j        t          d          k     r|                    d           | j        | j        cxk    r| j        k    sn |                    d           | j        t          d          k     r|                    d           | j        t          d          k    r|                    d           | j	        t          d          k    r|                    d	           |S )
Ndata_quality50000000weak_liquiditytrend_not_confirmedz3.0momentum_too_weakvolatility_too_highz0.85too_correlated_to_btc)
r   appendr   r   r   r   r   r   r   r   )r<   blockerss     r!   portfolio_holding_blockersrH   3   s   H) (''''*"5"555()))Oi0EEEE93EEEEE-...!GENN22+,,,#genn44-...#gfoo55/000Or    c                8   t          | j        t          d                    }t          | j        t          d          z  t          d                    }| j        t          d          z  }| j        t          d          z  }t          ||z   |z
  |z
  d          S )N25	1000000002z1.2z2.0z0.0001)minr   r   r   r   r   r;   )r<   momentumliquidity_bonusvolatility_penaltycorrelation_penaltys        r!   _scorerR   D   s    9-wt}}==H)2W[5I5II7SV<<XXO"5F#6Gh(+==@SSU]^^^r       z20.00)
max_assetsmax_weight_pct
candidateslist[HoldingCandidate]equity_usdcrT   intrU   c               *   i }g }| D ]V}t          |          }|j                                        }|r|||<   2|                    t	          |          |f           W|                    d d           g }	|dt          d|                   D ]\  }
}|}t          ||z  t          d          z            }|j	        t          d          k    rdnd	}|	                    t          |j                                        |||
|d
                     t          d |	D             t          d                    }t          t          d          t          d          |z
            }t          t          |	rdnd|	|t          |          dd          S )a  Build advisor-only medium/long holding recommendations.

    This is deliberately side-effect-free: it never authorizes orders. It creates
    a measurable sleeve for weekly/monthly allocation research and later manual
    review against buy-and-hold benchmarks.
    c                P    | d         | d         j                                         fS )Nr      )r   upper)items    r!   <lambda>z0build_portfolio_holding_advice.<locals>.<lambda>c   s!    DGT!W\-?-?-A-A#B r    T)keyreverseNr   100z6.0r	   r
   &weekly_trend_momentum_liquidity_screen)r   r$   r%   r&   r(   r)   c              3  $   K   | ]}|j         V  d S )N)r$   ).0r^   s     r!   	<genexpr>z1build_portfolio_holding_advice.<locals>.<genexpr>t   s%      JJd41JJJJJJr    0z100.00r   r   F)r,   r.   r/   r0   r1   r2   r3   )rH   r   r]   rF   rR   sortmaxr;   r   r   r#   sumr+   PORTFOLIO_HOLDING_ID)rV   rX   rT   rU   r0   eligibler<   rG   r   r/   r&   weightnotionalr(   invested_weightcash_weights                   r!   build_portfolio_holding_advicerq   L   s    &(H79H 8 8	-i88~##%% 	%HTN	**I67777MMBBDMQQQ+-K$%9s1j'9'9%9: 
 
ykF*WU^^;<<>G>X\cdi\j\j>j>j : :  qE^))++"(%-?  		
 		
 		
 		
 JJkJJJGTWLLYYOgcllGH$5$5$GHHK!(&1E""~; #   r    N)r4   )r5   r   r6   r   r7   r   )r<   r   r7   r=   )r<   r   r7   r   )
rV   rW   rX   r   rT   rY   rU   r   r7   r+   )
__future__r   dataclassesr   decimalr   r   typingr   rk   r'   r-   r   r#   r+   r;   rH   rR   rq   r   r    r!   <module>rv      s   " " " " " " ! ! ! ! ! ! * * * * * * * *      < HI;< $	& 	& 	& 	& 	& 	& 	& 	& $        $( ( ( ( ( ( ( (C C C C C   "_ _ _ _ %gg..2 2 2 2 2 2 2 2r    