Skip to main content

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.]

Metadata

Release files for nshare-calc 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nshare-calc 0.1.2
File Size Uploaded
nshare-calc-0.1.2.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nshare-calc 0.1.2
File Interpreter ABI Platform
nshare_calc-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / nshare-calc-0.1.2.tar.gz

Download URL nshare-calc-0.1.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1ae1c333a81ff23e467fd5c61047b4b8df237d8799b6f4d1bc5abba04f9a664d
BLAKE2b-256 checksum
How to use checksums
437f824e03b34876f9eeab1a60276631ea7d19ca512d273180372f978792811d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / nshare_calc-0.1.2-py3-none-any.whl

Download URL nshare_calc-0.1.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7afddd7e935a7e0f9cce805dc2d86d78642c38328d35a66c080b22ddd98a4b65
BLAKE2b-256 checksum
How to use checksums
cf0773e1b68647ac8e45e10dfe6508b6ad0c8bf5b70c9a16a053d68c83815eb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page