Group 3: Ionut Bina, Robert Smith, Yutang Xing
This project implements a mock algorithmic trading application for silver (XAG/USD) that demonstrates:
- Backend trading logic using multiple technical indicators
- Real-time visualization of prices, indicators, and trading decisions
- Performance tracking with metrics like Sharpe ratio
-
SMA (Simple Moving Average) - Trend identification
- Short-term (20-day) vs Long-term (50-day)
- Golden cross (buy) and death cross (sell) detection
-
RSI (Relative Strength Index) - Momentum analysis
- Oversold (< 30): Buy signal
- Overbought (> 70): Sell signal
-
MACD (Moving Average Convergence Divergence) - Trend strength
- MACD line crossing signal line generates buy/sell signals
-
Each indicator votes: +1 (buy), -1 (sell), or 0 (neutral)
-
Combined score ≥ +1 → Buy
-
Combined score ≤ -1 → Sell
-
Otherwise → Hold
- Price Chart with SMA overlays and buy/sell markers
- RSI Chart with overbought/oversold zones
-
- MACD Chart with signal line
- Portfolio Value tracking over time
silver_trading_bot/
│
├── main.py # Main entry point
├── simulation_engine.py # Simulation orchestrator
├── data/ # Data directory
│ ├── input/ # Input data
│ │ └── silver_prices.csv # Historical price data
│ └── output/ # Output data (visualization)
├── trading_components/ # Trading components used by simulation_engine.py
│ ├── trading_algorithm.py # Technical indicators & signals
│ ├── portfolio_manager.py # Position & performance tracking
│ ├── data_loader.py # CSV data handling
│ └── visualizer.py # Plotting & visualization
└── README.md # This file
Edit the following parameters in main.py:
DATA_FILE = "data/input/silver_prices.csv" # Data file path
INITIAL_CAPITAL = 100000.0 # Starting capital
UPDATE_INTERVAL = 0.05 # Update delay in seconds
MAX_ITERATIONS = None # None = all data (In simulation_engine.py, line in main():
# Fast mode (recommended)
simulation.run_simulation(real_time=False)
# Real-time mode with delays
simulation.run_simulation(real_time=True)TradingAlgorithm(
sma_short=20, # Short-term SMA period
sma_long=50, # Long-term SMA period
rsi_period=14, # RSI calculation period
rsi_oversold=30.0, # RSI oversold threshold
rsi_overbought=70.0, # RSI overbought threshold
macd_fast=12, # MACD fast EMA
macd_slow=26, # MACD slow EMA
macd_signal=9 # MACD signal line
)The simulation calculates: 模拟计算:
- Total Return - Percentage gain/loss
- Sharpe Ratio - Risk-adjusted return
- Win Rate - Percentage of profitable trades
- Total Profit - Sum of all trade profits
The simulation generates:
-
Console output with trade logs and final summary
-
PNG visualization (
trading_simulation_results.png) showing:- Price chart with indicators
- Buy/sell markers at decision points
- RSI and MACD subplots
- Portfolio value progression
TradingAlgorithm: Encapsulates indicator calculationsPortfolioManager: Manages positions and performanceDataLoader: Handles data preprocessingTradingVisualizer: Manages all plottingTradingSimulation: Orchestrates the entire system