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

New Feature: support selling short #1736

Conversation

jamespan
Copy link

@jamespan jamespan commented Sep 7, 2020

Selling short and covering short support for PP.

Screen Shot 2020-09-07 at 9 41 11 AM

image

image

image

image

@jamespan jamespan marked this pull request as ready for review September 7, 2020 01:56
@jamespan
Copy link
Author

jamespan commented Sep 7, 2020

#1466

#353

@jamespan jamespan changed the title Feature/support selling short WIP:Feature/support selling short Sep 7, 2020
@jamespan jamespan marked this pull request as draft September 7, 2020 04:13
@jamespan jamespan changed the title WIP:Feature/support selling short Feature/support selling short Sep 7, 2020
@jamespan jamespan marked this pull request as ready for review September 8, 2020 01:03
@jamespan jamespan changed the title Feature/support selling short New Feature: support selling short Sep 8, 2020
@bbatsov
Copy link
Contributor

bbatsov commented Sep 13, 2020

Do you really need a "Short" action, though? It seems to me it's more natural to implement this in terms of "Sell" and maybe add some checkbox that you're shorting there. After all, that's also how shorting works in brokers.

@buchen
Copy link
Member

buchen commented Sep 13, 2020

I like the change. I appreciate contributing this change. The support for selling short has been asked for quite some time. I glanced over the code and I think it is a good idea to add new types. Due to the size of the change, I did not find the time yet to look at the code in detail. I will plan to review and merge the code for the next week(s) - as my job permits me to spend time on PP.

@chirlu
Copy link
Member

chirlu commented Sep 19, 2020

I agree with @bbatsov – this change needlessly complicates things by duplicating functionality, while not creating any advantage. It’s based on flawed or lacking analysis of the problem at hand (“enable short selling”).

It already works perfectly fine in PP to sell securities that you don’t own, and later buy them (back) to get to zero. The backend (model) can handle that, and the user interface, too. It’s just some of the reports and widgets and diagrams that get confused when they see negative amounts. Adding transaction types won’t fix them.

Duplicate transaction types for selling and buying not only make the code more complex, they also create user-visible issues. Assume, e.g., that someone short-sells 5 shares of some company, then some time later buys 20 shares. How would you represent that when there is an artificial distinction between “buy” and “buy to cover”? Does the actual buy of 20 need to be split into a 5-shares cover buy and a 15-shares regular buy?

Or let’s assume you short-sell 3 shares in one account, then buy 3 shares in another. Would that buy be a cover? How is that to be interpreted when viewing just that second account? You could then transfer the shares from the second account to the first, bringing each account to zero. For that, wouldn’t we need another split transaction type, “inbound transfer to cover”?

@jamespan
Copy link
Author

jamespan commented Nov 6, 2020

@chirlu
Copy link
Member

chirlu commented Nov 8, 2020

Would you mind to elaborate?

@MichaelSp MichaelSp mentioned this pull request Nov 24, 2020
@MichaelSp
Copy link

MichaelSp commented Nov 24, 2020

I think the idea is

  • 5 long + 10 short = 5 short?
  • 5 long + 10 short = 5 long + 10 short

Without the direction you will always end up in one case. And especially performance wise it's not the same.

@jamespan
Copy link
Author

My broker is futubull.

If I am holding a short position, I have to cover it before I can open a new long position.

I don't know whether other brokers have the same limit about the long/short position or not.

Also, PP dose not support opening a position with a SELL, so I decide to add SHORT/COVER operations to PP.

SHORT is a selling that open a position, and COVER closes a SHORT position, just like BUY opens a long position and SELL close it.

Base on the SHORT/COVER, I fix some calculation issues comes with fees and taxes.

@MichaelSp
Copy link

I think there are 3 different aspects to cover: UI, Storage/Export-Formats and Performance calculation

Just checked with my broker (Interactive Brokers, with Lynx as reseller).

  1. In the UI you see a negative quantity if you have a short position.
  2. In the export it is marked if a trade (sell/buy) opens a new position or closes an exist.
  3. For the performance: I don't know. That would be interesting, but I guess it's just treated as long.

Not sure if that works everywhere but treating short as negative quantity seems to be reasonable.

@aeneasr
Copy link

aeneasr commented Dec 5, 2021

Sorry for digging this one up, I think there are even more complications with these types of transactions. Usually, you have two ways of put / call options. As already stated you can buy a put, sell a put, buy an option, sell an option - and all of those you can do to either open or close a position.

This also plays into risk calculations. So let's say you sell a put on AMD for 15$. Price falls to 10$ and you have to buy 1000 stock at 10$. I would argue that the 10.000$, which you should have in your bank account do not fall under "risk free" as you need the money to cover the put in case things go south.

Right now, puts and calls are not reported correctly and cause the consistency check to fail. They also do not report in your performance correctly due to the negative prefix and because the system does not understand the concept of an option! I think a couple of things we need to keep in mind. For selling PUTs:

  1. You sell a PUT with strike price 15$ end expiry EOY 2022. Half a year later, you buy a PUT with the same strike price and expiry -> position is closed.
  2. Options can expire (they almost never do though) -> you make a profit if you sold the PUT (you get the full premium). Here, PP would just keep the option open forever unless you mark the security as bought.
  3. The PUT realizes and you now own the stock, with the strike price. Here, you would need to create a new buy for the security, and a buy for the stock.
  4. You roll over to a different strike price or a later period. This typically involves sell to close and buy to open on the same underlying stock.

Things get even more complicated with calls of course, because here it is easier to sell unbacked calls, have calls backed by some or all stock, and so on.

And then we still have the inverse, so buying PUTs and CALLs. Although, I think almost no private investor really does this except for rolling positions or closing positions.

Inbetween however, the reports can not properly reflect this. I think one issue too is that options are typically with a 10x or 100x multiplicator. So selling one put means you have to buy 100 stocks.

So in conclusion, I think options are a different type of security with different characteristics and implications. Wouldn't that warrant a new datatype in PP that can reflect this, and also interact with regular security types?

@jamespan
Copy link
Author

jamespan commented Dec 7, 2021

I have built my own trade tracker based on Obsidian.md and Dataview plugin, this PR is no longer supported

@jamespan jamespan closed this Dec 7, 2021
@pfalcon
Copy link
Contributor

pfalcon commented Jun 19, 2023

@jamespan :

I have built my own trade tracker based on Obsidian.md and Dataview plugin, this PR is no longer supported

Very interesting, do you have more info about your solution, a blog post perhaps?

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

Successfully merging this pull request may close these issues.

None yet

7 participants