From 2e78c9f760126e779d1c763a4a834bc1e4c53e03 Mon Sep 17 00:00:00 2001 From: "entelligence-ai-pr-reviews[bot]" <174136889+entelligence-ai-pr-reviews[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 20:23:45 +0000 Subject: [PATCH] Update README.md The code introduces a new trading system with classes for Stock, Portfolio, and TradingSystem, along with methods for buying, selling, simulating market movements, and saving portfolio state. The README.md should be updated to include information about these new classes and their functionalities, as well as any usage instructions or examples for the new features. --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd1d66c..d64504b 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,67 @@ NeuralInk/ └── .env # Environment variables ``` +## Trading System + +The code introduces a new trading system with the following components: + +### Classes + +- **Stock**: Represents a stock with a symbol and price. It includes methods to update the stock price and maintain a price history. + +- **Portfolio**: Manages the user's financial assets, including balance, holdings, and transaction history. It provides methods to buy and sell stocks. + +- **TradingSystem**: Manages the overall trading environment, including available stocks and the user's portfolio. It supports adding stocks, starting trading sessions, simulating market movements, executing trades, and saving the portfolio state. + +### Methods + +- **Stock.update_price(new_price: float)**: Updates the stock's price and records the price history. + +- **Portfolio.buy(stock: Stock, quantity: int) -> bool**: Buys a specified quantity of a stock if sufficient balance is available. + +- **Portfolio.sell(stock: Stock, quantity: int) -> bool**: Sells a specified quantity of a stock if sufficient holdings are available. + +- **TradingSystem.add_stock(symbol: str, initial_price: float)**: Adds a new stock to the trading system. + +- **TradingSystem.start_trading(initial_balance: float)**: Initializes the portfolio with a starting balance and opens the market for trading. + +- **TradingSystem.simulate_market_movement()**: Simulates random market movements affecting stock prices. + +- **TradingSystem.execute_trade(symbol: str, quantity: int, is_buy: bool) -> bool**: Executes a buy or sell trade for a specified stock. + +- **TradingSystem.get_portfolio_value() -> float**: Calculates the total value of the portfolio, including cash balance and current stock holdings. + +- **TradingSystem.save_portfolio_state(filename: str)**: Saves the current state of the portfolio to a JSON file. + +### Example Usage + +```python +def main(): + # Create and initialize trading system + system = TradingSystem() + system.add_stock("AAPL", 150.0) + system.add_stock("GOOGL", 2800.0) + system.add_stock("MSFT", 300.0) + + # Start trading with initial balance + system.start_trading(10000.0) + + # Simulate some trading + for _ in range(5): + system.simulate_market_movement() + system.execute_trade("AAPL", 2, True) + system.execute_trade("GOOGL", 1, True) + system.execute_trade("MSFT", 3, True) + + # Save portfolio state + system.save_portfolio_state("portfolio_state.json") + + print(f"Final portfolio value: ${system.get_portfolio_value():.2f}") + +if __name__ == "__main__": + main() +``` + ## Contributing We welcome contributions to NeuralInk! Here's how you can help: @@ -103,4 +164,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## Support -If you encounter any issues or have suggestions, please open an issue in the GitHub repository. \ No newline at end of file +If you encounter any issues or have suggestions, please open an issue in the GitHub repository. \ No newline at end of file