|
1 | 1 | import argparse |
2 | 2 | import numpy as np |
3 | 3 | import pandas as pd |
4 | | -import argparse |
5 | 4 |
|
6 | 5 |
|
7 | 6 | class Colors: |
8 | 7 | HEADER = '\033[95m' |
9 | 8 | BLUE = '\033[94m' |
| 9 | + CYAN = '\033[96m' |
10 | 10 | GREEN = '\033[92m' |
11 | | - RED = '\033[91m' |
| 11 | + WARNING = '\033[93m' |
| 12 | + FAIL = '\033[91m' |
12 | 13 | ENDC = '\033[0m' |
13 | 14 | BOLD = '\033[1m' |
| 15 | + UNDERLINE = '\033[4m' |
14 | 16 |
|
15 | 17 | @classmethod |
16 | 18 | def disable(cls): |
17 | 19 | cls.HEADER = '' |
18 | 20 | cls.BLUE = '' |
| 21 | + cls.CYAN = '' |
19 | 22 | cls.GREEN = '' |
20 | | - cls.RED = '' |
| 23 | + cls.WARNING = '' |
| 24 | + cls.FAIL = '' |
21 | 25 | cls.ENDC = '' |
22 | 26 | cls.BOLD = '' |
| 27 | + cls.UNDERLINE = '' |
23 | 28 |
|
24 | 29 |
|
25 | | -class Colors: |
26 | | - HEADER = '\033[95m' |
27 | | - BLUE = '\033[94m' |
28 | | - CYAN = '\033[96m' |
29 | | - GREEN = '\033[92m' |
30 | | - WARNING = '\033[93m' |
31 | | - FAIL = '\033[91m' |
32 | | - ENDC = '\033[0m' |
33 | | - BOLD = '\033[1m' |
34 | | - UNDERLINE = '\033[4m' |
35 | | - |
36 | 30 | def simulate_bitcoin_prices(days=60, initial_price=50000, volatility=0.02): |
37 | 31 | """ |
38 | 32 | Simulates Bitcoin prices for a given number of days using Geometric Brownian Motion. |
@@ -87,9 +81,7 @@ def simulate_trading(signals, initial_cash=10000, quiet=False): |
87 | 81 | portfolio['total_value'] = float(initial_cash) |
88 | 82 |
|
89 | 83 | if not quiet: |
90 | | - print(f"{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}") |
91 | | - |
92 | | - print(f"\n{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}") |
| 84 | + print(f"\n{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}") |
93 | 85 | for i, row in signals.iterrows(): |
94 | 86 | if i > 0: |
95 | 87 | portfolio.loc[i, 'cash'] = portfolio.loc[i-1, 'cash'] |
@@ -153,13 +145,51 @@ def simulate_trading(signals, initial_cash=10000, quiet=False): |
153 | 145 | # Compare with buy and hold strategy |
154 | 146 | buy_and_hold_btc = args.initial_cash / prices.iloc[0] |
155 | 147 | buy_and_hold_value = buy_and_hold_btc * prices.iloc[-1] |
156 | | - |
157 | | - print(f"\n{Colors.HEADER}{Colors.BOLD}------ Final Portfolio Performance ------{Colors.ENDC}") |
158 | | - print(f"Initial Cash: ${initial_cash:.2f}") |
159 | | - print(f"Final Portfolio Value: ${final_value:.2f}") |
160 | | - if profit >= 0: |
161 | | - print(f"{Colors.GREEN}💰 Profit/Loss: ${profit:.2f}{Colors.ENDC}") |
162 | | - else: |
163 | | - print(f"{Colors.FAIL}📉 Profit/Loss: ${profit:.2f}{Colors.ENDC}") |
164 | | - print(f"Buy and Hold Strategy Value: ${buy_and_hold_value:.2f}") |
165 | | - print(f"{Colors.HEADER}-----------------------------------------{Colors.ENDC}") |
| 148 | + |
| 149 | + # Calculate additional statistics |
| 150 | + roi = (profit / initial_cash) * 100 |
| 151 | + trade_count_buys = int(portfolio['btc'].diff().fillna(0).gt(0).sum()) |
| 152 | + trade_count_sells = int(portfolio['btc'].diff().fillna(0).lt(0).sum()) |
| 153 | + total_trades = trade_count_buys + trade_count_sells |
| 154 | + vs_buy_hold = final_value - buy_and_hold_value |
| 155 | + |
| 156 | + # Format the final report |
| 157 | + width = 44 |
| 158 | + border = "═" * width |
| 159 | + |
| 160 | + print(f"\n{Colors.HEADER}{Colors.BOLD}╔{border}╗{Colors.ENDC}") |
| 161 | + title = "Final Portfolio Performance" |
| 162 | + print(f"{Colors.HEADER}{Colors.BOLD}║{title:^{width}}║{Colors.ENDC}") |
| 163 | + print(f"{Colors.HEADER}{Colors.BOLD}╠{border}╣{Colors.ENDC}") |
| 164 | + |
| 165 | + def print_line(label, value_str, color=Colors.ENDC): |
| 166 | + left_border = f"{Colors.HEADER}{Colors.BOLD}║{Colors.ENDC}" |
| 167 | + right_border = f"{Colors.HEADER}{Colors.BOLD}║{Colors.ENDC}" |
| 168 | + print(f"{left_border} {label:<24}{color}{value_str:>18}{Colors.ENDC} {right_border}") |
| 169 | + |
| 170 | + print_line("Initial Cash:", f"${initial_cash:,.2f}") |
| 171 | + print_line("Final Portfolio Value:", f"${final_value:,.2f}") |
| 172 | + |
| 173 | + profit_color = Colors.GREEN if profit >= 0 else Colors.FAIL |
| 174 | + profit_sign = "+" if profit >= 0 else "-" |
| 175 | + print_line("Profit/Loss:", f"{profit_sign}${abs(profit):,.2f}", profit_color) |
| 176 | + |
| 177 | + roi_color = Colors.GREEN if roi >= 0 else Colors.FAIL |
| 178 | + roi_sign = "+" if roi >= 0 else "-" |
| 179 | + print_line("ROI:", f"{roi_sign}{abs(roi):.2f}%", roi_color) |
| 180 | + |
| 181 | + print(f"{Colors.HEADER}{Colors.BOLD}╠{border}╣{Colors.ENDC}") |
| 182 | + |
| 183 | + print_line("Total Trades:", f"{total_trades}") |
| 184 | + print_line(" - Buys:", f"{trade_count_buys}") |
| 185 | + print_line(" - Sells:", f"{trade_count_sells}") |
| 186 | + |
| 187 | + print(f"{Colors.HEADER}{Colors.BOLD}╠{border}╣{Colors.ENDC}") |
| 188 | + |
| 189 | + print_line("Buy & Hold Value:", f"${buy_and_hold_value:,.2f}") |
| 190 | + |
| 191 | + vs_color = Colors.GREEN if vs_buy_hold >= 0 else Colors.FAIL |
| 192 | + vs_sign = "+" if vs_buy_hold >= 0 else "-" |
| 193 | + print_line("vs Buy & Hold:", f"{vs_sign}${abs(vs_buy_hold):,.2f}", vs_color) |
| 194 | + |
| 195 | + print(f"{Colors.HEADER}{Colors.BOLD}╚{border}╝{Colors.ENDC}") |
0 commit comments