A Python package for tracking a dynamic portfolio of stocks with daily price monitoring, cash management, and dividend handling
Project description
FinTrack
A Python package for tracking a dynamic portfolio of stocks with daily price monitoring, cash management, and dividend handling. This tool helps you maintain a record of your stock holdings, monitor their values over time, and automatically track cash flows from transactions and dividends.
Features
- Portfolio Management: Track multiple stock holdings with buy/sell transactions
- Dynamic Price Tracking: Automatically fetch and store historical stock prices using yfinance
- Multi-Currency Support: Handle stocks traded in different currencies with automatic conversion
- Cash Management: Maintain accurate cash balances accounting for buy/sell transactions and dividend payments
- Dividend Tracking: Automatically capture and account for dividend payments
- Historical Analysis: Query portfolio composition and value at any point in time
- Index Comparison: Compare your portfolio returns against benchmark indices
Installation
Install the package using pip:
pip install FinTrack
Quick Start
1. Create a Transaction CSV File
First, create a CSV file with your transactions (transactions.csv):
Date;Ticker;Type;Amount;Price
2023-01-15;AAPL;Buy;10;150.00
2023-02-20;MSFT;Buy;5;250.00
2023-03-10;AAPL;Sell;5;165.00
CSV Columns:
Date: Transaction date (YYYY-MM-DD format)Ticker: Stock ticker symbolType: Either "Buy" or "Sell"Amount: Number of sharesPrice: Price per share (in the stock's native currency)
2. Initialize the Portfolio Tracker
from portfolio_tracker import Portfolio_tracker
import datetime
# Initialize with starting cash and currency
portfolio = Portfolio_tracker(
initial_cash=150000,
currency="SEK", # Your portfolio's base currency
csv_file="transactions.csv"
)
# Update portfolio (fetches latest prices and processes new transactions)
portfolio.update_portfolio()
3. Query Your Portfolio
# Get current holdings
current_holdings = portfolio.get_current_holdings()
print(f"Current holdings: {current_holdings}")
# Get all holdings ever owned
all_holdings = portfolio.get_past_holdings()
print(f"All past holdings: {all_holdings}")
# Get portfolio value for a date range
portfolio_values = portfolio.get_portfolio_value(
from_date=datetime.date(2023, 1, 1),
to_date=datetime.date(2023, 12, 31)
)
# Get cash balance at a specific date
cash_balance = portfolio.get_portfolio_cash(datetime.date(2023, 6, 15))
print(f"Cash balance: {cash_balance}")
# Compare against index returns
index_returns = portfolio.get_index_returns(
ticker="^GSPC", # S&P 500
start_date=datetime.date(2023, 1, 1),
end_date=datetime.date(2023, 12, 31)
)
How It Works
Data Storage
The package uses SQLite to store three main tables:
- Portfolio Table: Tracks holdings for each date based on transactions
- Cash Table: Maintains cash balance accounting for transactions and dividends
- Prices Table: Stores historical prices for all stocks in the portfolio
Price Management
- Prices are automatically fetched from Yahoo Finance using yfinance
- Multi-currency portfolios are supported with automatic conversion to your base currency
- Prices are forward-filled for missing trading days
- You can specify custom prices for specific dates by adding a "Prices" sheet to your CSV
Cash Flow Tracking
Cash balance is updated for:
- Stock purchases (cash out)
- Stock sales (cash in)
- Dividend payments (cash in)
Advanced Features
Custom Price Specifications
You can specify custom prices for certain dates by including them in your transaction CSV. The package will use these instead of fetching from Yahoo Finance when available.
Portfolio Reset
Reset your portfolio to start fresh:
portfolio.reset_portfolio()
Requirements
- Python >= 3.7
- pandas
- yfinance
Supported Currencies
The package supports any currency pair available on Yahoo Finance, including:
- Major currencies: USD, EUR, GBP, JPY, CHF, AUD, CAD, SEK, NOK, DKK
- Cryptocurrencies through crypto tickers
- Emerging market currencies
Limitations
- Prices are fetched from Yahoo Finance; ensure data quality
- Intra-day trading is not supported (daily resolution only)
- Corporate actions (stock splits, mergers) should be manually adjusted in transactions
- Past dividend data depends on Yahoo Finance's historical dividend records
Contributing
Contributions are welcome! Please feel free to submit a Pull Request on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
Always verify your portfolio calculations independently. The author is not responsible for any financial losses resulting from the use of this software.
Support
For issues, questions, or suggestions, please open an issue on the GitHub repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fintrack-1.0.0.tar.gz.
File metadata
- Download URL: fintrack-1.0.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2547b2c518477f7eeb93d0753f33bf867fd631a1486fc8948ea5dbcf60974a85
|
|
| MD5 |
625424cb11d9fa210200263962e90efd
|
|
| BLAKE2b-256 |
c7854eb34ffd1e268b3d4632d1db4650d072888a532d1cce74adb63e7bea7ea2
|
File details
Details for the file fintrack-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fintrack-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fff8f3e53979565ec0c4498cb0cfb6106aedd3498fc03af53df4b32caf177351
|
|
| MD5 |
c744f0c14cfa7447f3f42adf3aaf7931
|
|
| BLAKE2b-256 |
63b8f4ce2d5daf870b282cc46ec6348ccdf5f7bb3344bb5d01a78c349282f9aa
|