From 2b51caf3a7709a2557df6743b297495c96c41399 Mon Sep 17 00:00:00 2001 From: Victor Wang Date: Sun, 7 Jan 2024 15:07:18 +0800 Subject: [PATCH 1/2] add setup.py and others for uploading to pypi --- .gitignore | 1 + arbitragerepair/__init__.py | 2 ++ arbitragerepair/repair.py | 8 ++++---- requirements.txt | 7 +++---- setup.cfg | 2 ++ setup.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 77bee78..e0f61e6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.idea/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/arbitragerepair/__init__.py b/arbitragerepair/__init__.py index e69de29..dbe2fa8 100644 --- a/arbitragerepair/__init__.py +++ b/arbitragerepair/__init__.py @@ -0,0 +1,2 @@ +from .constraints import * +from .repair import * diff --git a/arbitragerepair/repair.py b/arbitragerepair/repair.py index 2f65175..0aaf47c 100644 --- a/arbitragerepair/repair.py +++ b/arbitragerepair/repair.py @@ -141,10 +141,10 @@ def l1ba(mat_A, vec_b, C, spread=None, solver='glpk'): delta0 = 1./len(delta_ask) if delta0 > 1./len(delta_ask) else delta0 delta0 = 1e-8 if delta0 < 1e-8 else delta0 except ValueError: - raise ValueError('Please ensure that the spread input has legal ' - 'format! It should contain two arrays/lists, one ' - 'for bid-reference spread, one for ask-reference ' - 'spread.') + raise ValueError('Please ensure that the spread input has legal ' + 'format! It should contain two arrays/lists, one ' + 'for bid-reference spread, one for ask-reference ' + 'spread.') # Construct required quantities for the LP I = _np.eye(n_quote) diff --git a/requirements.txt b/requirements.txt index c0d0e41..feba0ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -cvxopt==1.3.0 -matplotlib==3.2.2 -numpy==1.19.0 -pandas==1.0.5 \ No newline at end of file +cvxopt>=1.3.0 +numpy>=1.19.0 +pandas>=1.0.5 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0f94f37 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description_file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4223cc5 --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import os +from setuptools import setup + +here = os.path.realpath(os.path.dirname(__file__)) +with open(os.path.join(here, 'README.md')) as f: + readme = f.read() + +setup( + name='arbitragerepair', + packages=['arbitragerepair'], + description='Model-free algorithms of detecting and repairing spread, butterfly and calendar arbitrages in European option prices.', + long_description=readme, + long_description_content_type="text/markdown", + install_requires=[ + 'cvxopt>=1.3.0', + 'numpy>=1.19.0', + 'pandas>=1.0.5' + ], + python_requies='>=3.8', + url='https://github.com/vicaws/arbitragerepair', + version='1.0.2', + license='MIT', + author='Victor Wang', + author_email='wangsheng.victor@gmail.com', + keywords=['option', 'arbitrage', 'quantitative finance', 'data cleansing', 'asset pricing'], + classifiers=[ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License' + ] +) From cc72425b7b2e8baa698bf18b130cab58b105e567 Mon Sep 17 00:00:00 2001 From: Victor Wang Date: Sun, 7 Jan 2024 15:19:53 +0800 Subject: [PATCH 2/2] update readme --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ba339b7..788ca7f 100644 --- a/README.md +++ b/README.md @@ -14,26 +14,27 @@ Some examples of arbitrage repair are shown as below: ![image](https://user-images.githubusercontent.com/32545513/83334755-9666ad80-a2a0-11ea-9910-34137539517b.png) ->An arbitrage-free normalised call price surface -> ->should satisfy some shape constraints. Assuming smooth surface function ->, ->then these shape constraints are ->- Positivity: ->- Monotonicity: , ->- Convexity: +An arbitrage-free normalised call price surface + +should satisfy some shape constraints. Assuming smooth surface function +, +then these shape constraints are +- Positivity: +- Monotonicity: , +- Convexity: ## Code -### Installation of pre-requisites +### Installation -It is recommended to create a new environment and install pre-requisite -packages. All packages in requirement.txt are compatible with Python 3.8.x. +It is recommended to create a new virtual environment and install from pypi. >``` ->pip install -r requirements.txt +>pip install arbitragerepair >``` +**Requirements:** ```Python >= 3.8``` and ```CVXOPT >= 1.3.0```. + ### Usage While an example can be found in [this jupyter notebook](notebook/example.ipynb), @@ -46,6 +47,10 @@ the usage of this code consists of the following steps. >``` **1.** Normalise strikes and call prices + +The inputs are four 1D ```numpy.array``` objects ```T, K, C, F```, which should be of the same length, representing +time-to-expiries, strike prices, option prices and forward prices. + >``` >normaliser = constraints.Normalise() >normaliser.fit(T, K, C, F)