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
New Feature: support selling short #1736
Conversation
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. |
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. |
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”? |
Direction of buy and sell matters. https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/OrderType/ |
Would you mind to elaborate? |
I think the idea is
Without the direction you will always end up in one case. And especially performance wise it's not the same. |
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. |
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).
Not sure if that works everywhere but treating short as negative quantity seems to be reasonable. |
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:
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? |
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? |
Selling short and covering short support for PP.