From 24f4bca3512ce1286d52ad2ee7aa1e1bc62987f6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 11 Jan 2026 13:04:55 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Add=20colorful=20CLI?= =?UTF-8?q?=20output=20and=20fix=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: - Added ANSI color codes and emojis to the simulation output. - Fixed a Pandas FutureWarning by explicitly casting initial cash values to float. - Added a `Colors` class for consistent styling. 🎯 Why: - The color-coded output (Green for Buy/Profit, Red for Sell/Loss) reduces cognitive load and makes it easier to scan the trading ledger. - The emojis add a small touch of delight and visual hierarchy. - Fixing the warning improves the developer experience and cleans up the output. 📸 Before/After: Before: Plain text output. After: Colored output with emojis (💰, 📉, 📈) and bold headers. ♿ Accessibility: - Visual indicators (colors and icons) help users quickly identify positive and negative events. --- .Jules/palette.md | 3 +++ bitcoin_trading_simulation.py | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 .Jules/palette.md diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 0000000..5de3a38 --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2024-05-22 - Visual Hierarchy in CLI Output +**Learning:** Adding color-coded indicators (Green/Red) and emojis (💰, 📉) in CLI tools significantly reduces cognitive load when parsing financial data streams. It transforms a wall of text into a scannable narrative. +**Action:** For data-heavy CLI applications, always implement a semantic color system and visual anchors (icons/emojis) for key events. diff --git a/bitcoin_trading_simulation.py b/bitcoin_trading_simulation.py index e619723..82df43f 100644 --- a/bitcoin_trading_simulation.py +++ b/bitcoin_trading_simulation.py @@ -1,6 +1,14 @@ import numpy as np import pandas as pd +class Colors: + HEADER = '\033[95m' + BLUE = '\033[94m' + GREEN = '\033[92m' + RED = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + def simulate_bitcoin_prices(days=60, initial_price=50000, volatility=0.02): """ Simulates Bitcoin prices for a given number of days using Geometric Brownian Motion. @@ -47,11 +55,11 @@ def simulate_trading(signals, initial_cash=10000): """ portfolio = pd.DataFrame(index=signals.index).fillna(0.0) portfolio['price'] = signals['price'] - portfolio['cash'] = initial_cash + portfolio['cash'] = float(initial_cash) portfolio['btc'] = 0.0 - portfolio['total_value'] = portfolio['cash'] + portfolio['total_value'] = float(initial_cash) - print("------ Daily Trading Ledger ------") + print(f"{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}") for i, row in signals.iterrows(): if i > 0: portfolio.loc[i, 'cash'] = portfolio.loc[i-1, 'cash'] @@ -62,14 +70,14 @@ def simulate_trading(signals, initial_cash=10000): btc_to_buy = portfolio.loc[i, 'cash'] / row['price'] portfolio.loc[i, 'btc'] += btc_to_buy portfolio.loc[i, 'cash'] -= btc_to_buy * row['price'] - print(f"Day {i}: Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}") + print(f"{Colors.GREEN}Day {i}: 💰 Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") # Sell signal elif row['positions'] == -2.0: if portfolio.loc[i, 'btc'] > 0: cash_received = portfolio.loc[i, 'btc'] * row['price'] portfolio.loc[i, 'cash'] += cash_received - print(f"Day {i}: Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}") + print(f"{Colors.RED}Day {i}: 📉 Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") portfolio.loc[i, 'btc'] = 0 portfolio.loc[i, 'total_value'] = portfolio.loc[i, 'cash'] + portfolio.loc[i, 'btc'] * row['price'] @@ -99,9 +107,14 @@ def simulate_trading(signals, initial_cash=10000): buy_and_hold_btc = initial_cash / prices.iloc[0] buy_and_hold_value = buy_and_hold_btc * prices.iloc[-1] - print("\n------ Final Portfolio Performance ------") + print(f"\n{Colors.HEADER}{Colors.BOLD}------ Final Portfolio Performance ------{Colors.ENDC}") print(f"Initial Cash: ${initial_cash:.2f}") print(f"Final Portfolio Value: ${final_value:.2f}") - print(f"Profit/Loss: ${profit:.2f}") + + if profit >= 0: + print(f"Profit/Loss: {Colors.GREEN}📈 ${profit:.2f}{Colors.ENDC}") + else: + print(f"Profit/Loss: {Colors.RED}📉 ${profit:.2f}{Colors.ENDC}") + print(f"Buy and Hold Strategy Value: ${buy_and_hold_value:.2f}") - print("-----------------------------------------") + print(f"{Colors.HEADER}-----------------------------------------{Colors.ENDC}")