Skip to content

Commit

Permalink
feat: add calculateSalesForNetWithdrawal
Browse files Browse the repository at this point in the history
* Add calculateSalesForNetWithdrawal and docs
* Break index.ts into files
  • Loading branch information
bernardobelchior committed May 26, 2020
1 parent dba9b74 commit 4f84706
Show file tree
Hide file tree
Showing 13 changed files with 1,759 additions and 972 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,61 @@ const capitalGainsByYear = aggregateByYear(capitalGains)
// }
```

### `calculateSalesForNetWithdrawal(history: Operation[], options: NetSalesOptions): Operation[]`

This method calculates the sales required to obtain a withdrawal amount set, given the history of purchases and sales and some settings.

```ts
const history: Operation[] = [
{
amount: 10,
date: new Date('2020-01-01'),
price: 100,
symbol: 'STK1',
type: 'BUY',
},
{
amount: 10,
date: new Date('2021-01-01'),
price: 200,
symbol: 'STK2',
type: 'BUY',
},
{
amount: 10,
date: new Date('2021-01-01'),
price: 200,
symbol: 'STK1',
type: 'BUY',
},
]

const options: NetSalesOptions = {
netWithdrawal: 4000,
capitalGainsTax: 0.5,
date: new Date('2022-01-01'),
prices: { STK1: 300, STK2: 600 },
}

const sales = calculateSalesForNetWithdrawal(history, options))
// [
// {
// amount: 10,
// date: new Date('2022-01-01'),
// price: 300,
// symbol: 'STK1',
// type: 'SELL',
// },
// {
// amount: 5,
// date: new Date('2022-01-01'),
// price: 600,
// symbol: 'STK2',
// type: 'SELL',
// },
// ])
```

## 🥂 License

[MIT](./LICENSE.md) as always

0 comments on commit 4f84706

Please sign in to comment.