Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -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).
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
28 changes: 21 additions & 7 deletions bitcoin_trading_simulation.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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']
Expand All @@ -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']
Expand Down Expand Up @@ -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}")
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
pandas
Loading