-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Feature/hedge #1768
Feature/hedge #1768
Conversation
Hi @lepla, Thanks for the PR! I made some significant contributions to the menu fixing the errors received, making the code more robust and more intuitive. I have the following remarks:
There is a singular matrix error you receive because there are multiple answers. I haven't delved too deeply into this mathematical error and thus the code will warn the user about it. This also makes the menu experimental, I can not confidently say that the methods deployed are 100% correct.
|
So let me know if this is too overboard, but in the case of multiple solutions, you could do some minimization technique. Maybe look for the mininum sum of absolute weights, constraining the greeks to be zero. Doing this would give you the solution of net zero greeks and having the purchase the lowest amount of instruments. Can be implemented using |
Thank you for the tips! For now, if there are multiple solutions, the command will yield the first feasible solution. Of course, this doesn't mean it will necessarily be the best one. After communicating with @JerBouma, we decided to keep this for now until the feature is monitored and proven to be worthy to many. |
Hi @lepla, Looking good! I went ahead and tidied up the options menu as a whole a bit as well. I also got rid of the If tests pass I feel like we are all set to merge :) |
@colin99d Mind checking briefly and approving the PR if everything works for you? Given that Lepla took your |
Great PR! I really like what people could do with this in the future. I found a small bug with the help menu that I fixed. Other than that here are my comments. Would love to hear from @JerBouma on whether he agrees.
|
I agree with @colin99d, it seems weird the underlying is an actual call or put option as your intention is not to hedge an option right? Instead, you want to hedge the underlying (stock). Could you elaborate on this? For example, I have the feeling that
I think it is fine to keep it at 2 options for now for the plot functionality. You can quite quickly switch between options anyways right? |
My solution as mentioned in the PR is influenced by the article. From that, I would like to point out two parts:
The fact that the underlying asset’s delta is 1 is not actually used anywhere, except for the fact that it changes the amount of equations we need (from 3 to 2). In his example, the portfolio is a short call option position, for which he needs to buy shares of the underlying asset in order to hedge his position. Just like the summary of the article example: |
Hi @lepla, So while I can agree with that, I have a feeling there is still something off with how Short and Long Puts and Calls are taken into account as they seem to be netting the same position every time. To some degree this makes sense to me, if you move 10 steps forward or 10 steps backwards, it should be the same number to return to the starting position. However, I'd expect a sign change. Does this make sense? |
Yes it totally does and I do agree as well. Not exactly sure how the code should be manipulated for this. |
Description
This feature is not quite intuitive, so in order for everyone to easily understand what this offers please read the article.
The hedge_model is based on @colin99d 's stocks/options/payoff menu.
My proposed feature is called 'hedge' and lives inside the stocks/options menu. It gives the user the opportunity to hedge their portfolio in order to neutralize its exposure to delta, gamma and vega. This means that whatever happens to the market, our investor will take profit (as long as it is volatile).
The user needs to firstly load a ticker (let's say tsla) and expiry date.
load tsla
exp 1
Then, after typing the command 'hedge', the user needs to pick their position option using the command 'pick'.
An example of this command is:
pick long -s call -a 500 -p 900
(This indicates that the user's position is a Long position, with 500 calls in the strike price of $900)
Then, the user needs to add 2 options using the 'add' command. The reason for this is that in order to find the neutral exposure portfolio, we need to use linear algebra, and therefore we need 3 equations with 3 unknowns. (The 3 unknowns are delta, gamma and vega - the feature could be enhanced in the future to include more greeks).
We can check for all the available options for this expiry date:
list
Let's say we select Option A:
add 45
And Option B:
Add 47
Right after we add the 2 options needed, the terminal automatically calculates the weight of the Options and the underlying asset that will lead to a delta, gamma and vega neutral exposure.
How has this been tested?
I have tried out many different combinations of options, expiry dates and positions (long calls, short puts etc.)
There is an issue that occurs in certain combinations which leads to a non invertible singular matrix error. (Unfortunately it happens quite often)
Checklist:
General Comments:
There are minor enhancements needed in the hedge_controller file, such as improve the help commands, some titles etc. , but first I would like its outputs to be validated and correct. After making sure it is correct, I will move on to the minor enhancements.
Others
pre-commit install
.pytest tests/...
.