Python library for calculating the optimal number of shares given a portfolio using integer programming.
Project description
nshare-calc
Python library 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
Release history Release notifications | RSS feed
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.1.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for nshare_calc-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00b4054da4ae741ef8264de48d7bff0ffbae6b90b0b43750b04b0486f34355a5 |
|
MD5 | d9de319ff015e5a36b815ba47feef81c |
|
BLAKE2b-256 | d5a9247a4122d9e090faf50483aad7153e03d3f5699ac983f2dd91bdb44719cd |