Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 1.5.0 (2025-12-14)

- Changed `get_pop` to compute the expected profit and expected loss of a strategy with the Black-Scholes model by calling a new function, `_compute_expected_returns_bs`.
- Updated docstrings.
- Removed price_array.py (a better Monte Carlo implementation is coming soon).
- The `expected_return_above_target` and `expected_return_below_target` fields in `PoPOutputs`, in models.py, are no longer optional but floats with default value of 0.0.
- The same for the `expected_profit` and `expected_loss` fields in `EngineData` and `Outputs`, both also in models.py.
- Removed test_misc.py.

## 1.4.3 (2025-04-14)

- Updated docstrings.
Expand Down
181 changes: 33 additions & 148 deletions docs/optionlab.html

Large diffs are not rendered by default.

224 changes: 112 additions & 112 deletions docs/optionlab/black_scholes.html

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions docs/optionlab/engine.html

Large diffs are not rendered by default.

2,412 changes: 1,208 additions & 1,204 deletions docs/optionlab/models.html

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions docs/optionlab/plot.html

Large diffs are not rendered by default.

584 changes: 322 additions & 262 deletions docs/optionlab/support.html

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions docs/optionlab/utils.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/search.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions examples/black_scholes_calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"source": [
"from __future__ import print_function\n",
"from __future__ import division\n",
"from optionlab import VERSION, get_bs_info\n",
"from optionlab import __version__\n",
"from optionlab.black_scholes import get_bs_info\n",
"import sys"
]
},
Expand All @@ -43,13 +44,13 @@
"output_type": "stream",
"text": [
"Python version: 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]\n",
"OptionLab version: 1.4.3\n"
"OptionLab version: 1.5.0\n"
]
}
],
"source": [
"print(f\"Python version: {sys.version}\")\n",
"print(f\"OptionLab version: {VERSION}\")"
"print(f\"OptionLab version: {__version__}\")"
]
},
{
Expand Down Expand Up @@ -105,8 +106,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 0 ns\n",
"Wall time: 4 ms\n"
"CPU times: total: 15.6 ms\n",
"Wall time: 7.02 ms\n"
]
}
],
Expand Down
12 changes: 7 additions & 5 deletions examples/calendar_spread.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"import datetime as dt\n",
"import sys\n",
"\n",
"from optionlab import VERSION, run_strategy, plot_pl\n",
"from optionlab import __version__, run_strategy, plot_pl\n",
"\n",
"%matplotlib inline"
]
Expand All @@ -47,13 +47,13 @@
"output_type": "stream",
"text": [
"Python version: 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]\n",
"OptionLab version: 1.4.3\n"
"OptionLab version: 1.5.0\n"
]
}
],
"source": [
"print(f\"Python version: {sys.version}\")\n",
"print(f\"OptionLab version: {VERSION}\")"
"print(f\"OptionLab version: {__version__}\")"
]
},
{
Expand Down Expand Up @@ -119,8 +119,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 375 ms\n",
"Wall time: 485 ms\n"
"CPU times: total: 297 ms\n",
"Wall time: 367 ms\n"
]
}
],
Expand Down Expand Up @@ -179,6 +179,8 @@
"text": [
"Probability of profit: 0.599111819020198\n",
"Profit ranges: [(118.87, 136.15)]\n",
"Expected profit: 1383.2\n",
"Expected loss: -691.09\n",
"Per leg cost: [4600.0, -5900.0]\n",
"Strategy cost: -1300.0\n",
"Minimum return in the domain: -1300.0000000000146\n",
Expand Down
30 changes: 19 additions & 11 deletions examples/call_spread.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,20 @@
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\rgave\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\optionlab-M7OP2qJc-py3.11\\Lib\\site-packages\\numpy\\lib\\_scimath_impl.py:289: RuntimeWarning: divide by zero encountered in log\n",
" return nx.log(x)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 39.8 s\n",
"Wall time: 42.4 s\n"
"CPU times: total: 1min 25s\n",
"Wall time: 1min 29s\n"
]
}
],
Expand Down Expand Up @@ -258,7 +266,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2024-03-13T02:15:17.818384Z",
Expand All @@ -269,10 +277,10 @@
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x1d7a0247250>]"
"[<matplotlib.lines.Line2D at 0x21b4b9b8250>]"
]
},
"execution_count": 9,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -306,7 +314,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2024-03-13T02:17:03.700786Z",
Expand Down Expand Up @@ -371,7 +379,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2024-03-13T02:17:10.924712Z",
Expand All @@ -383,8 +391,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 39.5 s\n",
"Wall time: 42.3 s\n"
"CPU times: total: 1min 26s\n",
"Wall time: 1min 31s\n"
]
}
],
Expand All @@ -395,7 +403,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2024-03-13T02:17:10.925263Z",
Expand Down Expand Up @@ -488,7 +496,7 @@
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x1d7a2447bd0>]"
"[<matplotlib.lines.Line2D at 0x21b4b9b1590>]"
]
},
"execution_count": 15,
Expand Down
14 changes: 8 additions & 6 deletions examples/covered_call.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"import matplotlib.pyplot as plt\n",
"from numpy import zeros\n",
"\n",
"from optionlab import VERSION, run_strategy\n",
"from optionlab import __version__, run_strategy\n",
"\n",
"%matplotlib inline"
]
Expand All @@ -54,13 +54,13 @@
"output_type": "stream",
"text": [
"Python version: 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]\n",
"OptionLab version: 1.4.3\n"
"OptionLab version: 1.5.0\n"
]
}
],
"source": [
"print(\"Python version: %s\" % sys.version)\n",
"print(\"OptionLab version: %s\" % VERSION)"
"print(\"OptionLab version: %s\" % __version__)"
]
},
{
Expand Down Expand Up @@ -119,8 +119,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 281 ms\n",
"Wall time: 258 ms\n"
"CPU times: total: 234 ms\n",
"Wall time: 293 ms\n"
]
}
],
Expand All @@ -142,7 +142,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x1e0346f7f90>"
"<matplotlib.legend.Legend at 0x1909fae4910>"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -195,6 +195,8 @@
"text": [
"Probability of profit: 0.522421406650333\n",
"Profit ranges: [(162.9, inf)]\n",
"Expected profit: 787.24\n",
"Expected loss: -904.12\n",
"Per leg cost: [-16404.0, 114.99999999999999]\n",
"Strategy cost: -16289.0\n",
"Minimum return in the domain: -8087.0\n",
Expand Down
52 changes: 26 additions & 26 deletions examples/naked_call.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"import datetime as dt\n",
"import sys\n",
"\n",
"from optionlab import VERSION, run_strategy, Inputs, plot_pl\n",
"from optionlab import __version__, run_strategy, Inputs, plot_pl\n",
"\n",
"%matplotlib inline"
]
Expand All @@ -46,13 +46,13 @@
"output_type": "stream",
"text": [
"Python version: 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]\n",
"OptionLab version: 1.4.3\n"
"OptionLab version: 1.5.0\n"
]
}
],
"source": [
"print(\"Python version: %s\" % sys.version)\n",
"print(\"OptionLab version: %s\" % VERSION)"
"print(\"OptionLab version: %s\" % __version__)"
]
},
{
Expand Down Expand Up @@ -116,8 +116,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 328 ms\n",
"Wall time: 338 ms\n"
"CPU times: total: 141 ms\n",
"Wall time: 262 ms\n"
]
}
],
Expand Down Expand Up @@ -174,31 +174,31 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Maximum loss: 6992.00\n",
"Maximum profit: 115.00\n",
"Profitable stock price range:\n",
" 0.00 ---> 176.14\n",
"Probability of Profit (PoP): 83.9%\n",
"Probability of reaching 100.00 or more: 82.0%\n",
"Probability of losing 100.00 or more: 14.3%\n"
"Probability of profit: 0.8389215512144531\n",
"Profit ranges: [(0.0, 176.14)]\n",
"Expected profit: 113.49\n",
"Expected loss: -717.5\n",
"Per leg cost: [114.99999999999999]\n",
"Strategy cost: 114.99999999999999\n",
"Minimum return in the domain: -6991.999999999999\n",
"Maximum return in the domain: 114.99999999999999\n",
"Implied volatility: [0.256]\n",
"In the money probability: [0.1832371984432129]\n",
"Delta: [-0.20371918274704337]\n",
"Gamma: [0.023104402361599465]\n",
"Theta: [0.091289876347897]\n",
"Vega: [0.12750177318341913]\n",
"Rho: [-0.02417676577711979]\n",
"Probability of profit target: 0.8197909190785164\n",
"Profit target ranges: [(0.0, 175.15)]\n",
"Probability of loss limit: 0.14307836806156238\n",
"Loss limit ranges: [(177.15, inf)]\n",
"\n"
]
}
],
"source": [
"print(f\"Maximum loss: {abs(out.minimum_return_in_the_domain):.2f}\")\n",
"print(f\"Maximum profit: {out.maximum_return_in_the_domain:.2f}\")\n",
"print(\"Profitable stock price range:\")\n",
"\n",
"for low, high in out.profit_ranges:\n",
" print(f\" {low:.2f} ---> {high:.2f}\")\n",
"\n",
"print(f\"Probability of Profit (PoP): {out.probability_of_profit * 100.0:.1f}%\")\n",
"print(\n",
" f\"Probability of reaching {profit_target:.2f} or more: {out.probability_of_profit_target * 100.0:.1f}%\"\n",
")\n",
"print(\n",
" f\"Probability of losing {abs(loss_limit):.2f} or more: {out.probability_of_loss_limit * 100.0:.1f}%\"\n",
")"
"print(out)"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions optionlab/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
*.old
old
Loading