This project is a stock trading visualization and simulation tool that allows users to interact with historical stock data, visualize it using candlestick charts, and simulate buy/sell operations based on the displayed data.
Visualize historical stock data in candlestick charts Display original and derived data side by side Simulate stock trading with buy and sell operations Record trading transactions to a CSV file for further analysis
The project consists of the following main components:
PrepareData
: Reads and preprocesses historical stock data from a CSV file, calculates derived data, and computes scores and growth rates for each row.CandlestickChart
: Displays candlestick charts for original and derived data, allowing users to navigate and perform buy/sell operations using keyboard inputs.TradeManager
: Manages trading transactions (buy and sell operations), calculates profits and losses, and saves the transaction records to a CSV file.
To set up the project, follow these steps:
- Install the required packages:
pip install pandas mplfinance matplotlib
- Download the historical stock data for your desired stock in CSV format. Example sources include Yahoo Finance or Alpha Vantage.
- Place the downloaded CSV file in an appropriate directory and update the file_path variable in the main script to point to the file.
python auto_trade.py --file_path stock_data/apple.csv
- implement your strategy in
auto_trade.py
(the default one is MA 10/30)
python trade_simulation.py --file_path stock_data/apple.csv
This will launch the visualization window with the candlestick charts. You can navigate through the data and perform buy/sell operations using the following keyboard inputs:
l
: Move forward in timej
: Move backward in timeb
: Buy stockc
: Sell stockq
: Quit and save transactions to a CSV file, and will also display in terminal simultaneously
This project is licensed under the MIT License.