Skip to content

Commit

Permalink
fix: implement fixes suggested by @matebudai
Browse files Browse the repository at this point in the history
  • Loading branch information
aarjaneiro committed Jan 20, 2025
1 parent f6b424e commit 8e80102
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/options-trading-mleg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@
"source": [
"# This is a function that will return a contract which minimizes the difference from a target price\n",
"def find_nearest_strike_contract(contracts, target_price):\n",
" min_error = 0\n",
" min_diff = 0\n",
" min_contract = None\n",
" for contract in contracts:\n",
" error = abs(float(contract.strike_price) - target_price)\n",
" if min_contract is None or error < min_error:\n",
" min_error = error\n",
" diff = abs(float(contract.strike_price) - target_price)\n",
" if min_contract is None or diff < min_diff:\n",
" min_diff = diff\n",
" min_contract = contract\n",
" return min_contract"
],
Expand Down Expand Up @@ -389,10 +389,10 @@
" self.is_call = is_call\n",
" self.is_buy = is_buy\n",
" self.contract = None\n",
" self.err = 0\n",
" self.diff = 0\n",
"\n",
" def __repr__(self):\n",
" return f\"Contract: {self.contract}, Optimal: {self.optimal}, Error: {self.err}, Is Call: {self.is_call}\"\n",
" return f\"Contract: {self.contract}, Optimal: {self.optimal}, Diff: {self.diff}, Is Call: {self.is_call}\"\n",
"\n",
"\n",
"buffers = [ContractBuffer(A, False, True), ContractBuffer(B, False, False), ContractBuffer(C, True, False),\n",
Expand All @@ -404,8 +404,8 @@
" if buff.is_call != is_call:\n",
" continue\n",
" diff = abs(float(contract.strike_price) - buff.optimal)\n",
" if diff < buff.err or buff.contract is None:\n",
" buff.err = diff\n",
" if diff < buff.diff or buff.contract is None:\n",
" buff.diff = diff\n",
" buff.contract = contract\n",
"\n",
"order_legs_m = []\n",
Expand Down

0 comments on commit 8e80102

Please sign in to comment.