https://github.com/yfiua/nshare-calc
Calculating the optimal number of shares given a portfolio using integer programming.
https://github.com/yfiua/nshare-calc
integer-programming python python-package quant
Last synced: 10 days ago
JSON representation
Calculating the optimal number of shares given a portfolio using integer programming.
- Host: GitHub
- URL: https://github.com/yfiua/nshare-calc
- Owner: yfiua
- License: apache-2.0
- Created: 2023-04-02T01:19:42.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-23T10:49:18.000Z (about 3 years ago)
- Last Synced: 2026-02-22T00:38:30.560Z (3 months ago)
- Topics: integer-programming, python, python-package, quant
- Language: Python
- Homepage: https://pypi.org/project/nshare-calc/
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```sh
pip install nshare-calc
```
## Usage
```python
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.]
```