Skip to content

Commit

Permalink
Merge pull request #1 from vicaws/release
Browse files Browse the repository at this point in the history
Release to pypi
  • Loading branch information
vicaws authored Jan 7, 2024
2 parents 0ab0912 + cc72425 commit 6825eb4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
><img src="https://render.githubusercontent.com/render/math?math=(T,k) \mapsto c(T,k)">
>should satisfy some shape constraints. Assuming smooth surface function
><img src="https://render.githubusercontent.com/render/math?math=c(T,k) \in C^{1,2} (\mathbb{R}_{ %3E 0} \times \mathbb{R}_{\geq 0})">,
>then these shape constraints are
>- Positivity: <img src="https://render.githubusercontent.com/render/math?math=0 \leq c \leq 1">
>- Monotonicity: <img src="https://render.githubusercontent.com/render/math?math=-1\leq\partial c / \partial k \leq 0">, <img src="https://render.githubusercontent.com/render/math?math=\partial c / \partial T \geq 0">
>- Convexity: <img src="https://render.githubusercontent.com/render/math?math=\partial^2 c / \partial^2 k \geq 0">
An arbitrage-free normalised call price surface
<img src="https://render.githubusercontent.com/render/math?math=(T,k) \mapsto c(T,k)">
should satisfy some shape constraints. Assuming smooth surface function
<img src="https://render.githubusercontent.com/render/math?math=c(T,k) \in C^{1,2} (\mathbb{R}_{ %3E 0} \times \mathbb{R}_{\geq 0})">,
then these shape constraints are
- Positivity: <img src="https://render.githubusercontent.com/render/math?math=0 \leq c \leq 1">
- Monotonicity: <img src="https://render.githubusercontent.com/render/math?math=-1\leq\partial c / \partial k \leq 0">, <img src="https://render.githubusercontent.com/render/math?math=\partial c / \partial T \geq 0">
- Convexity: <img src="https://render.githubusercontent.com/render/math?math=\partial^2 c / \partial^2 k \geq 0">

## 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),
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions arbitragerepair/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .constraints import *
from .repair import *
8 changes: 4 additions & 4 deletions arbitragerepair/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cvxopt==1.3.0
matplotlib==3.2.2
numpy==1.19.0
pandas==1.0.5
cvxopt>=1.3.0
numpy>=1.19.0
pandas>=1.0.5
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description_file = README.md
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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'
]
)

0 comments on commit 6825eb4

Please sign in to comment.