Skip to content
Open
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
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
If you encounter any issues or have suggestions, please open an issue in the GitHub repository.