Trading Simulator Report
Trading Simulator Report
1. Introduction
This project is a Trading Simulator developed using Java Swing. It provides a graphical user
interface (GUI) to simulate stock trading activities, allowing users to buy and sell stocks,
track their portfolio, and view real-time simulated stock prices. The system enables adding,
editing, and removing stock holdings, displaying current portfolio value, and viewing
historical transactions.
2. Project Components
a) Stock.java
This file defines the Stock class, which stores details about each stock.
Attributes:
- symbol → Stock symbol (e.g., AAPL)
- companyName → Company name
- price → Current stock price
- quantity → Number of shares owned
- purchasePrice → Price at which the stock was bought
- category → Stock category (e.g., Tech, Finance)
Methods:
- Getters and setters for each attribute
- toString() → formats stock as "SYMBOL - Company Name"
b) TradingPanel.java
This file creates the GUI for simulating trades.
Main Features:
- Table (JTable) showing current stock prices.
- Input fields for symbol, quantity, price.
- Buy, Sell, Clear buttons.
- Refresh Prices button (simulates price changes).
- Sample stocks loaded for testing.
Important Methods:
- buyStock() → Validates input and adds stock to portfolio.
- sellStock() → Validates and removes stock from portfolio.
- refreshPrices() → Simulates new prices for stocks.
- clearFields() → Resets the input form.
- loadSampleStocks() → Loads predefined stock data.
The design uses GridBagLayout for alignment and styled Swing components for a
professional UI.
c) PortfolioPanel.java
This file creates the GUI for managing the user’s portfolio.
Main Features:
- Table showing owned stocks: symbol, quantity, purchase price, current price, profit/loss.
- Summary of portfolio value and gains.
- View Transaction History button.
Important Methods:
- updatePortfolio() → Updates table and recalculates values.
- viewHistory() → Displays historical buy/sell transactions.
- calculateProfitLoss() → Computes gain/loss per stock.
3. Technologies Used
- Java SE 8 or above
- Java Swing (JPanel, JTable, JTextField, JButton)
- Layouts: BorderLayout, GridBagLayout, FlowLayout
- Collections: ArrayList, List
- Table Models: DefaultTableModel
Limitations:
⚠ No integration with real stock market APIs
⚠ Prices are randomly simulated, not real-time
⚠ Data is lost when the program closes
5. Learning Points
While working on this project, you learn:
- How to design a trading GUI in Java.
- How to handle buy/sell transactions and validations.
- How to use JTable for displaying portfolio data.
- How to simulate and update stock prices dynamically.
6. Conclusion
This Trading Simulator is a practical example of a basic trading application using Java
Swing. It demonstrates core functionalities like buying/selling stocks, updating portfolio,
and simulating price changes. The application can be extended with features like real API
integration, persistent storage, graph plotting, and performance reports.