From c865f1c402655e5c3a12533ccf66e846a9ae7578 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 24 Jan 2026 13:09:01 +0000 Subject: [PATCH] feat: enhance CLI output with colors and emojis - Add ANSI color codes and emojis to trading simulation output for better readability. - Colorize Buy (Green) and Sell (Red) signals. - Improve formatting of the final portfolio performance summary. - Add `requirements.txt` and correct `README.md` for proper developer onboarding. - Create .Jules/palette.md for UX learnings. --- .Jules/palette.md | 3 +++ README.md | 37 +++++++++++++++++++++++++++++++++-- bitcoin_trading_simulation.py | 28 +++++++++++++++++++------- requirements.txt | 2 ++ 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 .Jules/palette.md create mode 100644 requirements.txt diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 0000000..d2bea2d --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2026-01-24 - [CLI Visual Hierarchy] +**Learning:** UX principles like visual hierarchy and semantic coloring apply equally to CLI tools. Using ANSI codes and emojis transforms a wall of text into a scannable dashboard. +**Action:** For future CLI tools, prioritize a `Colors` class or library early to establish a visual language (Green=Success/Buy, Red=Failure/Sell). diff --git a/README.md b/README.md index a1d5a77..be561ef 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ -# code -Programming with C++ code +# Bitcoin Trading Simulation + +A Python-based CLI tool that simulates Bitcoin trading using a 'Golden Cross' moving average strategy. It generates synthetic price data using Geometric Brownian Motion, executes trades based on technical indicators, and provides a daily ledger with a final performance summary. + +## Features + +- **Price Simulation:** Uses Geometric Brownian Motion to simulate 60 days of Bitcoin prices. +- **Trading Strategy:** Implements a Golden Cross strategy (Short MA > Long MA = Buy, Short MA < Long MA = Sell). +- **Rich CLI Output:** features color-coded logs (Green for Buy/Profit, Red for Sell/Loss) and emojis for better readability. +- **Performance metrics:** Compares the strategy's performance against a "Buy and Hold" approach. + +## Installation + +1. Clone the repository. +2. Install the required dependencies: + +```bash +pip install -r requirements.txt +``` + +## Usage + +Run the simulation script: + +```bash +python bitcoin_trading_simulation.py +``` + +## Tests + +Run the test suite: + +```bash +python test.py +``` diff --git a/bitcoin_trading_simulation.py b/bitcoin_trading_simulation.py index e619723..adfc288 100644 --- a/bitcoin_trading_simulation.py +++ b/bitcoin_trading_simulation.py @@ -1,6 +1,14 @@ import numpy as np import pandas as pd +# ANSI color codes for visual enhancement +class Colors: + GREEN = '\033[92m' + RED = '\033[91m' + PURPLE = '\033[95m' + BOLD = '\033[1m' + RESET = '\033[0m' + 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'] - print("------ Daily Trading Ledger ------") + print(f"\n{Colors.PURPLE}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.RESET}") 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"Day {i}: {Colors.GREEN}📈 [BUY]{Colors.RESET} {btc_to_buy:.4f} BTC at ${row['price']:.2f}") # 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"Day {i}: {Colors.RED}📉 [SELL]{Colors.RESET} {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}") portfolio.loc[i, 'btc'] = 0 portfolio.loc[i, 'total_value'] = portfolio.loc[i, 'cash'] + portfolio.loc[i, 'btc'] * row['price'] @@ -99,9 +107,15 @@ 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.PURPLE}{Colors.BOLD}------ Final Portfolio Performance ------{Colors.RESET}") print(f"Initial Cash: ${initial_cash:.2f}") print(f"Final Portfolio Value: ${final_value:.2f}") - print(f"Profit/Loss: ${profit:.2f}") + + if profit >= 0: + profit_str = f"{Colors.GREEN}💰 +${profit:.2f}{Colors.RESET}" + else: + profit_str = f"{Colors.RED}📉 -${abs(profit):.2f}{Colors.RESET}" + + print(f"Profit/Loss: {profit_str}") print(f"Buy and Hold Strategy Value: ${buy_and_hold_value:.2f}") - print("-----------------------------------------") + print(f"{Colors.PURPLE}-----------------------------------------{Colors.RESET}") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5da331c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +pandas