Skip to content

Conversation

@jalextowle
Copy link
Contributor

@jalextowle jalextowle commented Feb 1, 2023

Adds the accounting used to close shorts.

The short pnl is given by $s_{pnl} = c_0 \cdot z_0 - c_1 \cdot z_1 + loss$, where $c_0$ is the initial share price, $c_1$ is the share price when the short is closed, $z_0$ is the amount of shares the bonds were worth at opening, $z_1$ is the amount of shares the bonds are worth at closing, and $loss = y - c_0 \cdot z_0$. $y$ is the equal to the amount of bonds that were shorted. Thus, we can restate the short pnl as $s_{pnl} = y - c_1 \cdot z_1$. We can generalize this to allow the partial closing of shorts by assuming that we have $c_i$ as the share price of the ith transaction, $z_i$ as the shares paid in the ith transaction, and $y_i$ are the amount of shorts closed in the ith transaction with the sum of the all $y_i$ equal to $y$. Then we have the short pnl given as:

$$ s_{pnl} = \sum_{i = 1}^{n} (y_i - c_i \cdot z_i) $$

Aside from trading pnl, shorts also receive interest on their shorts. The initial shares value of the bonds being shorted is given by $\frac{y}{c_0}$. In general, we can calculate interest on shares as $(c_1 - c_0) \cdot z$, so the interest on the bonds being shorted is given by: $(c_1 - c_0) \cdot \frac{y}{c_0} = (\frac{c_1}{c_0} - 1) \cdot y$. To generalize this to the case of partial closing, we again assume that we have $y_i$ bonds shorted in the ith partial closing where the sum of the $y_i$ equal to $y$ and that we have $c_i$ as the share price at the time of the ith partial closing. Then, the interest proceeds are given by:

$$ s_{interest} = \sum_{i = 1}^{n} (\frac{c_i}{c_0} - 1) \cdot y_i $$

Finally, we have that the total pnl is given by:

$$ s_{total} = s_{pnl} + s_{interest} = \sum_{i = 1}^{n} (y_i - c_i \cdot z_i) + \sum_{i = 1}^{n} (\frac{c_i}{c_0} - 1) \cdot y_i $$

@jalextowle jalextowle force-pushed the jalextowle/hyperdrive/close-shorts branch from 963e001 to f9e1f2c Compare February 1, 2023 23:19
@jalextowle jalextowle marked this pull request as ready for review February 1, 2023 23:21
@jalextowle jalextowle requested a review from jrhea February 1, 2023 23:21
Copy link
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions/comments and I'm cornfused about the share reserve accounting

@jalextowle jalextowle force-pushed the jalextowle/hyperdrive/close-shorts branch from 27ab347 to 2620280 Compare February 2, 2023 15:57
Copy link
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. approved

@jalextowle jalextowle merged commit 2af1e65 into main Feb 2, 2023
@jalextowle jalextowle deleted the jalextowle/hyperdrive/close-shorts branch February 2, 2023 19:23
@jalextowle jalextowle mentioned this pull request Feb 5, 2023
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.

3 participants