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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nshare-calc-0.1.2.tar.gz | 6.6 kB | Without provenance | Details for nshare-calc-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nshare_calc-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for nshare_calc-0.1.2-py3-none-any.whl |
Total release size: 13.3 kB
Security for nshare-calc 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.