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 5472ec1 commit f6b424e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions examples/options-trading-mleg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
"metadata": {},
"cell_type": "code",
"source": [
"# This is a function that will return a contract which minimizes an error from a target price\n",
"def get_least_error_contract(contracts, target_price):\n",
"# 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_contract = None\n",
" for contract in contracts:\n",
Expand Down Expand Up @@ -233,7 +233,7 @@
" )\n",
" cts = trade_client.get_option_contracts(req)\n",
"\n",
" c = get_least_error_contract(cts.option_contracts, optimal_price)\n",
" c = find_nearest_strike_contract(cts.option_contracts, optimal_price)\n",
" order_legs.append(OptionLegRequest(\n",
" symbol=c.symbol,\n",
" side=OrderSide.BUY,\n",
Expand Down Expand Up @@ -308,8 +308,8 @@
"metadata": {},
"cell_type": "code",
"source": [
"# At the time of writing, TSLA has a standard deviation of 5.02 and a price of 413.82\n",
"# Let's create a moat around the current price such that B and C are a standard deviation away from each other\n",
"# At the time of writing, TSLA has a standard deviation (a common measure of variation for the price) of 5.02 and a price of 413.82\n",
"# Let's create a interval around the current price such that B and C are a standard deviation away from each other\n",
"\n",
"stddev = 5.02\n",
"B = optimal_price - (stddev / 2)\n",
Expand Down Expand Up @@ -382,7 +382,7 @@
"metadata": {},
"cell_type": "code",
"source": [
"# This is a function that will return a contract which minimizes an error from a target price\n",
"# This finds contracts which minimizes the difference from a set of target prices\n",
"class ContractBuffer:\n",
" def __init__(self, optimal, is_call, is_buy):\n",
" self.optimal = optimal\n",
Expand All @@ -403,9 +403,9 @@
" is_call = contract.type == ContractType.CALL\n",
" if buff.is_call != is_call:\n",
" continue\n",
" error = abs(float(contract.strike_price) - buff.optimal)\n",
" if error < buff.err or buff.contract is None:\n",
" buff.err = error\n",
" diff = abs(float(contract.strike_price) - buff.optimal)\n",
" if diff < buff.err or buff.contract is None:\n",
" buff.err = diff\n",
" buff.contract = contract\n",
"\n",
"order_legs_m = []\n",
Expand Down

0 comments on commit f6b424e

Please sign in to comment.