Skip to content

Commit

Permalink
Fix mixup in iron condor
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLepelaars committed Dec 23, 2022
1 parent bd85182 commit 55596ec
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions blackscholes/iron_condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
18 changes: 9 additions & 9 deletions blackscholes/tests/test_iron_condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
)


Expand Down Expand Up @@ -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)()
)
18 changes: 9 additions & 9 deletions docs/6.option_structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 55596ec

Please sign in to comment.