Mercurial > public > python-black-scholes
changeset 8:f213aa4891fc 0.0.2
add setup.cfg
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 20 Nov 2021 18:04:06 +0100 |
parents | 5063639df439 |
children | 6f9a6fc6d4d9 |
files | fbs/__init__.py fbs/helpers.py fbs/main.py pyproject.toml setup.cfg setup.py src/__init__.py src/fbs/__init__.py src/fbs/helpers.py src/fbs/main.py tests/test_helpers.py |
diffstat | 8 files changed, 126 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/fbs/helpers.py Sat Nov 20 12:24:01 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -""" -Helper methods -""" - -import math -import numpy as np -from scipy.stats import norm - - -class Option: - def __init__(self, spot_price, exercise_price, risk_free_rate, std, expiration): - """ - :param spot_price: spot price of the underlying asset at t0, float, required - :param exercise_price: exercise price of the option, float, required - :param risk_free_rate: float, required - :param std: standard deviation of the return rate of P, float, required - :param expiration: time to expiration, float, required - :return: None - """ - - self.s = spot_price - self.k = exercise_price - self.r = risk_free_rate - self.std = std - self.t = expiration - - def compute_eu_call_price(self): - """ - Determine the value of an European call option - :return: - """ - - d1 = self.compute_d1() - d2 = self.compute_d2() - - price = self.s * norm.cdf(d1) - self.k * math.exp(- self.r * self.t) * norm.cdf(d2) - - return price - - def compute_d1(self): - """ - Determine d1 coefficient - :return: float - """ - - numerator = (np.log(self.s / self.k) + (self.r + (self.std**2 / 2)) * self.t) - denominator = self.std * np.sqrt(self.t) - - d1 = numerator / denominator - - return d1 - - def compute_d2(self): - """ - Determine d2 coefficient - :return: float - """ - - d1 = self.compute_d1() - d2 = d1 - self.std * np.sqrt(self.t) - - return d2
--- a/fbs/main.py Sat Nov 20 12:24:01 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -import click -from fbs.helpers import Option - - -@click.command() -@click.option('--spot-price', type=float, required=True, help='Spot price of the underlying asset.') -@click.option('--exercise-price', type=float, required=True, help='Exercise price of the option.') -@click.option('--risk-free-rate', type=float, required=True, help='Risk free rate.') -@click.option('--std', type=float, required=True, help='Standard deviation.') -@click.option('--expiration', type=float, required=True, help='Time to expiration.') -def cli(spot_price, exercise_price, risk_free_rate, std, expiration): - option = Option(spot_price, exercise_price, risk_free_rate, std, expiration) - - # Format output - output = 'European call option price: {}'.format(option.compute_eu_call_price()) - output_length = len(output) - line = ''.join('-' for _ in range(output_length)) - - # Output - click.echo(line) - click.echo(output) - click.echo(line) - - -if __name__ == '__main__': - cli()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyproject.toml Sat Nov 20 18:04:06 2021 +0100 @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.cfg Sat Nov 20 18:04:06 2021 +0100 @@ -0,0 +1,29 @@ +[metadata] +name = fucking-black-scholes +version = 0.0.2 +author = Dennis Concepcion Martin +author_email = dennisconcepcionmartin@gmail.com +description = A simple command line tool for pricing options using the Black-Scholes model +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/denniscm190/fucking-black-scholes +project_urls = Bug Tracker = https://github.com/denniscm190/fucking-black-scholes/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +package_dir = = src +packages = find: +python_requires = >=3.8 +install_requires = + numpy~=1.21.4 + scipy~=1.7.2 + click~=8.0.3 + +[options.packages.find] +where = src + +[options.entry_points] +console_scripts = fbs = fbs.main:cli \ No newline at end of file
--- a/setup.py Sat Nov 20 12:24:01 2021 +0100 +++ b/setup.py Sat Nov 20 18:04:06 2021 +0100 @@ -1,24 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import setup -setup( - name='fucking-black-scholes', - description='A simple command line tool for pricing options using the Black-Scholes model', - version='0.0.1', - packages=find_packages(), - install_requires=['numpy~=1.21.4', 'scipy~=1.7.2', 'click~=8.0.3'], - python_requires='>=3.8', - entry_points=''' - [console_scripts] - fbs=fbs.main:cli - ''', - author="Dennis Concepción Martín", - keyword="finance, black-scholes, option, pricing, derivative", - license='MIT', - url='https://github.com/denniscm190/fucking-black-scholes', - author_email='dennisconcepcionmartin@gmail.com', - classifiers=[ - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.8", - ] -) +setup()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fbs/helpers.py Sat Nov 20 18:04:06 2021 +0100 @@ -0,0 +1,62 @@ +""" +Helper methods +""" + +import math +import numpy as np +from scipy.stats import norm + + +class Option: + def __init__(self, spot_price, exercise_price, risk_free_rate, std, expiration): + """ + :param spot_price: spot price of the underlying asset at t0, float, required + :param exercise_price: exercise price of the option, float, required + :param risk_free_rate: float, required + :param std: standard deviation of the return rate of P, float, required + :param expiration: time to expiration, float, required + :return: None + """ + + self.s = spot_price + self.k = exercise_price + self.r = risk_free_rate + self.std = std + self.t = expiration + + def compute_eu_call_price(self): + """ + Determine the value of an European call option + :return: + """ + + d1 = self.compute_d1() + d2 = self.compute_d2() + + price = self.s * norm.cdf(d1) - self.k * math.exp(- self.r * self.t) * norm.cdf(d2) + + return price + + def compute_d1(self): + """ + Determine d1 coefficient + :return: float + """ + + numerator = (np.log(self.s / self.k) + (self.r + (self.std**2 / 2)) * self.t) + denominator = self.std * np.sqrt(self.t) + + d1 = numerator / denominator + + return d1 + + def compute_d2(self): + """ + Determine d2 coefficient + :return: float + """ + + d1 = self.compute_d1() + d2 = d1 - self.std * np.sqrt(self.t) + + return d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fbs/main.py Sat Nov 20 18:04:06 2021 +0100 @@ -0,0 +1,26 @@ +import click +from fbs.helpers import Option + + +@click.command() +@click.option('--spot-price', type=float, required=True, help='Spot price of the underlying asset.') +@click.option('--exercise-price', type=float, required=True, help='Exercise price of the option.') +@click.option('--risk-free-rate', type=float, required=True, help='Risk free rate.') +@click.option('--std', type=float, required=True, help='Standard deviation.') +@click.option('--expiration', type=float, required=True, help='Time to expiration.') +def cli(spot_price, exercise_price, risk_free_rate, std, expiration): + option = Option(spot_price, exercise_price, risk_free_rate, std, expiration) + + # Format output + output = 'European call option price: {}'.format(option.compute_eu_call_price()) + output_length = len(output) + line = ''.join('-' for _ in range(output_length)) + + # Output + click.echo(line) + click.echo(output) + click.echo(line) + + +if __name__ == '__main__': + cli()