Skip to main content

A portfolio tracker library, that allows to track a portfolio of stocks and their performance.

Project description

Stock Portfolio Tracker

This library provides a set of Python modules for managing and tracking a stock portfolio.

Description

The project includes the following modules:

  • price_repo.py: Manages the stock prices repository, which is a csv file containing the prices of the stocks. This is used to avoid downloading the prices every time the program is executed.

  • manager.py: Contains the portfolio class and the functions to manage it. It allows for portfolio rebalancing, rolling forward, and other operations.

  • utils.py: Includes utility functions used in the project, such as functions for computing returns and rolling dates to business days.

For a more detailed documentation check the docs folder on GitHub: https://github.com/LucaPoli59/PortfolioTrackerLib/tree/master/docs

Installation

To install the library, run the following command:

pip install portfolio_tracker

Usage

To use this library, import the necessary modules and use the provided classes and functions.

For example, the following code shows how to use the Portfolio class to manage a stock portfolio:

import os

from portfolio_tracker.price_repo import PriceRepo

from portfolio_tracker.manager import Portfolio



#Define the path to the stock prices repository and the portfolios

STOCK_PRICES_REPO = os.path.join(os.path.dirname(os.getcwd()), 'data', 'stock_repo.csv') # Example of a price repository path

STOCK_PRICES_REPO_OPEN = os.path.join(os.path.dirname(os.getcwd()), 'data', 'stock_repo_open.csv') # Example of a price repository path

PORTFOLIOS_PATH = os.path.join(os.path.dirname(os.getcwd()), 'data', 'portfolios') # Example of a portfolio path



# Initialize the PriceRepo objects

price_repo = PriceRepo(STOCK_PRICES_REPO, 'Adj Close')

price_repo_open = PriceRepo(STOCK_PRICES_REPO_OPEN, 'Open')



# Initialize the Portfolio object

portfolio_path1 = os.path.join(PORTFOLIOS_PATH, "portfolio_10_2023.xlsx")

portfolio = Portfolio(portfolio_path1, price_repo, price_repo_open)



# Roll the portfolio forward to the next month

portfolio.roll_forward("1M")

print(portfolio.get_weights())



# Rebalance the portfolio

portfolio_path2 = os.path.join(PORTFOLIOS_PATH, "portfolio_01_2024.xlsx")

portfolio.rebalancing_from_file(portfolio_path2)



# We can roll again the portfolio forward

portfolio.roll_forward(20)



# Print the weights, assets values and returns

print(portfolio.get_weights())

print(portfolio.get_assets_values())

print(portfolio.get_returns(weighted=True))

For more examples, check the example.ipynb notebook.

Development

This library is meant to be a simple tool for tracking a stock portfolio, it has been developed by Luca Poli from the quant team of the MIURA group, for the group itself.

For any bug or suggestion, please contact me through discord at https://discordapp.com/users/326499540540588032

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

portfolio_tracker-0.2.0.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

portfolio_tracker-0.2.0.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file portfolio_tracker-0.2.0.2.tar.gz.

File metadata

  • Download URL: portfolio_tracker-0.2.0.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for portfolio_tracker-0.2.0.2.tar.gz
Algorithm Hash digest
SHA256 2f4b59e75e65a373b219e50b9f769acabd542a7be6d4f02e1d262927255b13f5
MD5 08548c439252dc774c6405ccc9674dc5
BLAKE2b-256 b19d86aeb45cf2f55bb9ba68f74338549ac716d7b26c9fd56269f08adaa2fe7d

See more details on using hashes here.

File details

Details for the file portfolio_tracker-0.2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for portfolio_tracker-0.2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23fea5d767d20629a83af17b2b79dac903363ffeeb86046263a8319b2b0c0d0d
MD5 6aee2b4cd9a3b546cb0d8a649f9f409f
BLAKE2b-256 31fa2122acc0162391864cb260308845ebd12e32b30bb8ef3f25ef7ae5b305de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page