From 55596ecdecb15de54368445292b20ca6a8246fa2 Mon Sep 17 00:00:00 2001 From: Carlo Lepelaars Date: Fri, 23 Dec 2022 23:15:59 +0100 Subject: [PATCH] Fix mixup in iron condor --- blackscholes/iron_condor.py | 4 ++-- blackscholes/tests/test_iron_condor.py | 18 +++++++++--------- docs/6.option_structures.md | 18 +++++++++--------- docs/index.md | 4 ++-- pyproject.toml | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blackscholes/iron_condor.py b/blackscholes/iron_condor.py index f6260bf..981c4b4 100644 --- a/blackscholes/iron_condor.py +++ b/blackscholes/iron_condor.py @@ -53,7 +53,7 @@ def _calc_attr(self, attribute_name: str) -> float: put_attr2 = getattr(self.put2, attribute_name) call_attr1 = getattr(self.call1, attribute_name) call_attr2 = getattr(self.call2, attribute_name) - return put_attr1() - put_attr2() - call_attr1() + call_attr2() + return -put_attr1() + put_attr2() + call_attr1() - call_attr2() class BlackScholesIronCondorShort(BlackScholesStructureBase): @@ -107,4 +107,4 @@ def _calc_attr(self, attribute_name: str) -> float: put_attr2 = getattr(self.put2, attribute_name) call_attr1 = getattr(self.call1, attribute_name) call_attr2 = getattr(self.call2, attribute_name) - return -put_attr1() + put_attr2() + call_attr1() - call_attr2() + return put_attr1() - put_attr2() - call_attr1() + call_attr2() diff --git a/blackscholes/tests/test_iron_condor.py b/blackscholes/tests/test_iron_condor.py index 59a5ff4..582de85 100644 --- a/blackscholes/tests/test_iron_condor.py +++ b/blackscholes/tests/test_iron_condor.py @@ -72,10 +72,10 @@ def test_individual_methods(self): for attr in test_methods: assert ( getattr(iron_condor, attr)() - == getattr(iron_condor.put1, attr)() - - getattr(iron_condor.put2, attr)() - - getattr(iron_condor.call1, attr)() - + getattr(iron_condor.call2, attr)() + == -getattr(iron_condor.put1, attr)() + + getattr(iron_condor.put2, attr)() + + getattr(iron_condor.call1, attr)() + - getattr(iron_condor.call2, attr)() ) @@ -136,10 +136,10 @@ def test_individual_methods(self): ] # Short iron condor = -Put1 + Put2 + Call1 - Call2 for attr in test_methods: - assert ( + ( getattr(iron_condor, attr)() - == -getattr(iron_condor.put1, attr)() - + getattr(iron_condor.put2, attr)() - + getattr(iron_condor.call1, attr)() - - getattr(iron_condor.call2, attr)() + == getattr(iron_condor.put1, attr)() + - getattr(iron_condor.put2, attr)() + - getattr(iron_condor.call1, attr)() + + getattr(iron_condor.call2, attr)() ) diff --git a/docs/6.option_structures.md b/docs/6.option_structures.md index 6a03103..0b589d3 100644 --- a/docs/6.option_structures.md +++ b/docs/6.option_structures.md @@ -169,26 +169,26 @@ Two conditions must hold when choosing strike prices: ### Long iron condor (`BlackScholesIronCondorLong`): -$$P(K_1) - P(K_2) - C(K_3) + C(K_4)$$ +$$-P(K_1) + P(K_2) + C(K_3) - C(K_4)$$ ```python3 from blackscholes import BlackScholesIronCondorLong -butterfly = BlackScholesIronCondorLong(S=55, K1=20, K2=25, K3=45, K4=50, - T=1.0, r=0.0025, sigma=0.15) -butterfly.price() ## -4.0742 -butterfly.delta() ## -0.1572 +iron_condor = BlackScholesIronCondorLong(S=55, K1=20, K2=25, K3=45, K4=50, + T=1.0, r=0.0025, sigma=0.15) +iron_condor.price() ## 4.0742 +iron_condor.delta() ## 0.1572 ``` ### Short iron condor (`BlackScholesIronCondorShort`): -$$-P(K_1) + P(K_2) + C(K_3) - C(K_4)$$ +$$P(K_1) - P(K_2) - C(K_3) + C(K_4)$$ ```python3 from blackscholes import BlackScholesIronCondorShort -butterfly = BlackScholesIronCondorShort(S=55, K1=20, K2=25, K3=45, K4=50, +iron_condor = BlackScholesIronCondorShort(S=55, K1=20, K2=25, K3=45, K4=50, T=1.0, r=0.0025, sigma=0.15) -butterfly.price() ## 4.0742 -butterfly.delta() ## 0.1572 +iron_condor.price() ## -4.0742 +iron_condor.delta() ## -0.1572 ``` diff --git a/docs/index.md b/docs/index.md index e557476..7bdf195 100644 --- a/docs/index.md +++ b/docs/index.md @@ -134,6 +134,6 @@ from blackscholes import BlackScholesIronCondorLong iron_condor = BlackScholesIronCondorLong(S=55, K1=20, K2=25, K3=45, K4=50, T=1.0, r=0.0025, sigma=0.15) -iron_condor.price() ## -4.0742 -iron_condor.delta() ## -0.1572 +iron_condor.price() ## 4.0742 +iron_condor.delta() ## 0.1572 ``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 48c8168..fbbcb33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "blackscholes" -version = "0.1.0" +version = "0.1.1" description = "Black Scholes calculator for Python including all Greeks" authors = ["CarloLepelaars "] license = "MIT"