A Python-based portfolio management system that automatically syncs stock transactions to Google Sheets, tracks real-time prices, dividends, and performance metrics.
- Python 3.8 or higher
- Google Cloud account (free)
- Google Sheets
- Clone the repository
- Install dependencies (install -r requirements.txt)
- Set up Google Sheets API a. Go to Google Cloud Console b. Create a new project c. Enable Google Sheets API and Google Drive API d. Create Service Account credentials e. Download JSON key and save as credentials.json in project root f. Copy the service account email (looks like xxx@xxx.iam.gserviceaccount.com)
- Create your Google Sheet a. Create a new Google Sheet b. Share it with your service account email (make sure it has editor access!) c. Create two tabs: MyPortfolio and MyTransactions
- Configure the app a. Open config.py b. Update SHEET_NAME with your Google Sheet name
- Set up your google sheets (Use this template by making a copy here:
https://docs.google.com/spreadsheets/d/1ZXmKKT_JIAyPMi7DegvO5yrag0Obj9WlmDRrvsNbMoo/edit?usp=sharing) - Run the main
Add your stock transactions to the MyTransactions tab
When you run python main.py, the app will:
- Read all transactions from MyTransactions
- Calculate consolidated positions (average cost, realized gains)
- Sync holdings to MyPortfolio tab
- Fetch current prices and dividend data
- Update all performance metrics
- Display summary in terminal and Google Sheets
Python 3.8+ - Core language yfinance - Real-time stock data gspread - Google Sheets API wrapper google-auth - Authentication pandas - Data processing (via yfinance)
Edit config.py to customize:
SHEET_NAME = 'Your Portfolio Sheet Name'
PORTFOLIO_TAB = 'MyPortfolio'
TRANSACTIONS_TAB = 'MyTransactions'
VERBOSE = True # Detailed console output
UPDATE_SHEET = True # Auto-update Google Sheets
SHOW_SUMMARY = True # Display portfolio summary
TRACK_DIVIDENDS = True # Include dividend tracking
MAX_RETRIES = 3 # Retry failed API calls
- Supports BUY and SELL transactions
- Automatically calculates average cost basis across multiple purchases
- Tracks realized gains/losses when positions are sold
- Handles partial sells correctly
- Unrealized Gains - Current profit/loss on open positions
- Realized Gains - Locked-in profit/loss from closed positions
- Day Change - Today's performance
- Portfolio Allocation - Percentage weight of each position
- Annual dividend per share
- Dividend yield percentage
- Projected annual income
- Portfolio-wide dividend yield
- Automatic sector classification
- Sector allocation percentages
- Sector-level performance
This tool is for educational and personal portfolio tracking purposes only. It is not financial advice. Always do your own research before making investment decisions. Stock prices are fetched from Yahoo Finance and may be delayed. For real-time trading decisions, use official broker platforms.
- yfinance - Stock data API
- gspread - Google Sheets Python API
Project Link: https://github.com/ellenvlimnauaw/ReStock
Email: ellenvlimanauw@gmail.com