Skip to main content

Python library for calculating the optimal number of shares given a portfolio using integer programming.

Project description

nshare-calc

Python package for calculating the optimal number of shares given a portfolio using integer programming.

Problem statement

Given a portfolio with total asset $S$, price vector $\mathbf p$ and weight vector $\mathbf w$, find integer vector $\mathbf n$ such that

  • The total value of all stocks must not exceed the total asset, i.e., $\mathbf p \cdot \mathbf n \leq S$;
  • Minimize the total absolute difference between the desired values and the actual values for all stocks, i.e., $\Sigma_i |S w_i - p_i n_i|$.

Installation

pip install nshare-calc

Usage

from nshare_calc import calc_n

# params
S = 100
p = [6, 5.5]
w = [0.6, 0.4]         # w will be automatically normalized

n = calc_n(S, p, w)    # Result: n = [10.  7.]

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

nshare-calc-0.1.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

nshare_calc-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file nshare-calc-0.1.2.tar.gz.

File metadata

  • Download URL: nshare-calc-0.1.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for nshare-calc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1ae1c333a81ff23e467fd5c61047b4b8df237d8799b6f4d1bc5abba04f9a664d
MD5 6e3891d41b53694a282e4a2cf942e6fa
BLAKE2b-256 437f824e03b34876f9eeab1a60276631ea7d19ca512d273180372f978792811d

See more details on using hashes here.

File details

Details for the file nshare_calc-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nshare_calc-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for nshare_calc-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7afddd7e935a7e0f9cce805dc2d86d78642c38328d35a66c080b22ddd98a4b65
MD5 0f22caf364edd7f5ab1a30be4a922d1f
BLAKE2b-256 cf0773e1b68647ac8e45e10dfe6508b6ad0c8bf5b70c9a16a053d68c83815eb9

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