Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Options Cost_Basis is not being used consistently. #455

Open
2 tasks done
SkyShadex opened this issue May 19, 2024 · 0 comments
Open
2 tasks done

[Bug]: Options Cost_Basis is not being used consistently. #455

SkyShadex opened this issue May 19, 2024 · 0 comments

Comments

@SkyShadex
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Options positions have an issue with cost_basis or avg_entry_price. All values based these values report wildly incorrectly. Seems like this is only in the paper environment. Might be related to what happened earlier in the week with misreported numbers?

image

print(f'[{row.symbol}] {row.current_price} {row.current_price/row.qty}')
print(f'[{row.symbol}] {row.cost_basis} {row.avg_entry_price}')
print(f'[{row.symbol}] {row.unrealized_plpc:.2%}')

image

Because avg_entry_price is 1/100th of what it should be, the percentage gain reported is misleading (as well as the cash value). It's possible to report a gain of 90$ on a 100$ cost basis, when actual loss is -10$.

Expected Behavior

avg_entry_price should be contract value. Cost Basis should either be Contract Value or Contract Value x 100. But there's currently a discrepancy.

SDK Version I encountered this issue in

alpaca-py == 0.21.0
But the issue seems to extend to alpaca's back end.

Steps To Reproduce

In the paper environment

api = TradingClient()
positions = api.get_all_positions()
options = pos.loc[(pos['asset_class'].str.contains("us_option",case=False))].copy()
print(f'[{options.symbol}] {options.current_price} {options.current_price/options.qty} {options.cost_per_unit} {options.avg_entry_price}')

print(options.symbol,options.current_price,options.avg_entry_price,options.cost_basis,options.unrealized_pl,options.unrealized_plpc)

all options contract's older than a day report incorrect values when it comes to cost_basis and everything based on it.

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

From what I can tell, there’s a state management issue or a wrong variable used, maybe both? In the paper environment it's present. In the live environment.

Screenshot 2024-05-17 190751
(there’s also a text overflow problem in the Asset Column)

  • On contracts bought same day, the values seem correct.
  • On contracts held overnight. The avg entry seems to go down by 1/100. Which then makes to Total P/L report a wildy wrong number the next day.
  • Today’s P/L seems to be accurately stating the actual % gain.
  • Market Value seems to be (price * 100 * Qty), price being reported in contract value. But Cost Basis (for options) is doesn’t get that same *100. Somewhere between avg entry and cost basis it’s being misused?
  • Any user logic built on top of those values would see position A, pnl = +90$ (when it cost 100$ & pnl = -10$). And the percentages based on that would be wrong as well.
  • The logic behind the daily values seems to be intact though. If I had built on the daily values this wouldn’t be an issue.
    In live, all the values seem to be correct.

image
Then what happens every day is this huge jump in p/l...

  • Daily change is some sum of Total P/L (which is calculated wrong)? Which also happens to be the cash value of all current options + actual PnL
  • Start of each day, equity is pulled from the last value of the previous day. Equity ends up oscillating around what should be the actual equity (offset being the value of all contracts).

Screenshot 2024-05-17 201947

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant