# HG changeset patch # User Dennis Concepcion Martin # Date 1637014481 -3600 # Node ID b853194dc28b4fa9919299cc38bcc6f608ed796a # Parent e5f3f855e6f9e5457c6c23a3bf0f28ba202a4238 add methods for eu call option diff -r e5f3f855e6f9 -r b853194dc28b .idea/.gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/.gitignore Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff -r e5f3f855e6f9 -r b853194dc28b .idea/fucking-black-scholes.iml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/fucking-black-scholes.iml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/inspectionProfiles/Project_Default.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/inspectionProfiles/Project_Default.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,38 @@ + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/inspectionProfiles/profiles_settings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/inspectionProfiles/profiles_settings.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/misc.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/misc.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/modules.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/modules.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/other.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/other.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b .idea/vcs.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/vcs.xml Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b README_ES.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README_ES.md Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,1 @@ +# fucking-black-scholes model \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b fbs/__init__.py diff -r e5f3f855e6f9 -r b853194dc28b fbs/helpers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fbs/helpers.py Mon Nov 15 23:14:41 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 diff -r e5f3f855e6f9 -r b853194dc28b fbs/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fbs/main.py Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,6 @@ +def main(): + pass + + +if __name__ == '__main__': + main() diff -r e5f3f855e6f9 -r b853194dc28b requirements.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/requirements.txt Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,2 @@ +numpy~=1.21.4 +scipy~=1.7.2 \ No newline at end of file diff -r e5f3f855e6f9 -r b853194dc28b tests/__init__.py diff -r e5f3f855e6f9 -r b853194dc28b tests/test_helpers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_helpers.py Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,30 @@ +from unittest import TestCase +from fbs.helpers import Option + + +class TestOption(TestCase): + option = Option( + spot_price=20.00, + exercise_price=21.00, + risk_free_rate=0.05, + std=0.25, + expiration=0.5 # 6 month (half year) + ) + + def test_compute_eu_call_price(self): + price = self.option.compute_eu_call_price() + price = round(price, 2) + + self.assertEqual(price, 1.20, 'EU call price is not equal to 1.20') + + def test_compute_d1(self): + d1 = self.option.compute_d1() + d1 = round(d1, 2) + + self.assertEqual(d1, -0.05, 'D1 coefficient is not equal to -0.05') + + def test_compute_d2(self): + d2 = self.option.compute_d2() + d2 = round(d2, 2) + + self.assertEqual(d2, -0.22, 'D2 coefficient is now equal to -0.22') diff -r e5f3f855e6f9 -r b853194dc28b tests/test_main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_main.py Mon Nov 15 23:14:41 2021 +0100 @@ -0,0 +1,6 @@ +from unittest import TestCase + + +class Test(TestCase): + def test_main(self): + self.fail()