3i  dZddlmZddedededefdZ ddeded ededef d Zd edefd Z ddeeefdedefd Z ddededefdZ ddededefdZ dedefdZ d dedededefdZd!d edededefdZy)"z_ Formatting Utilities. Provides consistent formatting for currency, percentages, and numbers. )Unionamountsymboldecimalsreturnc |d|d}|d|S)u Format amount as currency with thousands separator. Args: amount: Amount to format symbol: Currency symbol (default: €) decimals: Number of decimal places (default: 2) Returns: Formatted string (e.g., "1,234.56 €") Examples: >>> format_currency(1234.56) '1,234.56 €' >>> format_currency(180000) '180,000.00 €' >>> format_currency(-523.45) '-523.45 €' ,.f )rrr formatteds B/mnt/ssd/data/python-lab/portfolio-manager/src/utils/formatters.pyformat_currencyr s'("XJa(I[& ""value show_signcN|r|dkDrd}n |r|dkrd}nd}|d|d}|||S)a6 Format value as percentage. Args: value: Percentage value decimals: Number of decimal places (default: 1) show_sign: Show + sign for positive values (default: True) symbol: Percentage symbol (default: %) Returns: Formatted string (e.g., "+12.5%", "-3.2%") Examples: >>> format_percentage(12.5) '+12.5%' >>> format_percentage(-3.2) '-3.2%' >>> format_percentage(7.9, decimals=2) '+7.90%' >>> format_percentage(5.0, show_sign=False) '5.0%' r+.r r )rrrrsignr s rformat_percentager"sJ8UQY uqy8*A &IVI;vh ''rtextc|jddjddjddj}t|S)uR Parse currency string to float. Args: text: Currency string (e.g., "1,234.56 €" or "1234.56") Returns: Float value Examples: >>> parse_currency("1,234.56 €") 1234.56 >>> parse_currency("1234.56") 1234.56 >>> parse_currency("-523.45 €") -523.45 ,r€$)replacestripfloat)rcleaneds rparse_currencyr"IsA&ll3#++E26>>sBGMMOG >rc|d|dS)a< Format number with thousands separator. Args: value: Number to format decimals: Number of decimal places (default: 2) Returns: Formatted string Examples: >>> format_number(1234.5678) '1,234.57' >>> format_number(1000000) '1,000,000.00' r r r )rrs r format_numberr$`s"Bxj> "#rquantitycR|dk(r|t|k(r t|dS|d|dS)a; Format share quantity. Args: quantity: Number of shares decimals: Number of decimal places (default: 0 for whole shares) Returns: Formatted string Examples: >>> format_shares(176) '176' >>> format_shares(1200.5, decimals=2) '1,200.50' rrr r )int)r%rs r format_sharesr(ts8"1}S]2h-"#2hZq.)*rct|}|dkrdnd}|dk\r ||dz dd|S|dk\r ||dz dd|S|d k\r ||d z dd |S||d d |S) u Format large amounts in compact form (K, M, B). Args: amount: Amount to format symbol: Currency symbol Returns: Compact formatted string Examples: >>> format_compact_currency(1500) '1.5K €' >>> format_compact_currency(180000) '180.0K €' >>> format_compact_currency(1500000) '1.5M €' r-riʚ;z.1fzB i@BzM izK z.2fr )abs)rr abs_amountrs rformat_compact_currencyr-s&VJ1*3"D]" ]237r&BB y  Y.s32fX>> u  U*3/r&:: 3'q11rpnlc|dkDry|dkryy)a[ Get color code for P&L value. Args: pnl: P&L amount or percentage Returns: Color hex code (green for positive, red for negative, gray for zero) Examples: >>> color_for_pnl(123.45) '#28a745' >>> color_for_pnl(-50.00) '#dc3545' >>> color_for_pnl(0.0) '#6c757d' rz#28a745z#dc3545z#6c757dr )r.s r color_for_pnlr0s$ Qw qrdate_str input_format output_formatcTddlm}|j||}|j|S)a Format date string. Args: date_str: Input date string input_format: Input date format (default: ISO format) output_format: Output date format (default: DD/MM/YYYY) Returns: Formatted date string Examples: >>> format_date("2025-12-15") '15/12/2025' >>> format_date("2025-12-15", output_format="%d %b %Y") '15 Dec 2025' r)datetime)r5strptimestrftime)r1r2r3r5date_objs r format_dater9s*$"  <8H   ] ++r max_lengthsuffixcJt||kr|S|d|t|z |zS)a\ Truncate text to max length. Args: text: Text to truncate max_length: Maximum length suffix: Suffix for truncated text Returns: Truncated text Examples: >>> truncate_text("This is a very long text", 15) 'This is a ve...' >>> truncate_text("Short", 15) 'Short' N)len)rr:r;s r truncate_textr>s1$ 4yJ )c&k) *V 33rN)r)T%)r?)r)r)z%Y-%m-%dz%d/%m/%Y)z...)__doc__typingrr strr'rboolrr"r$r(r-r0r9r>r rrrGs0 #E#3###c#4 $( $($($(  $(  $(N.$sEz*$c$#$(+E+S++.2E23232@u4,#,S,c,cf,.4443434r