This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculates the remaining inventory, current average buy price, total cost and total gains using FIFO (First In First Out) method. | |
* The function expects three parameters: transactionsType, transactionQuantities and transactionPrices sorted by date. | |
* | |
* Inspired by: https://www.allstacksdeveloper.com/2022/09/fifo-stock-portfolio-google-sheets.html | |
* | |
* @param {string[] | string} transactionsType - An array or a single string representing transaction types. Each string should be either 'B' for buy or 'S' for sell. | |
* @param {number[] | number} transactionQuantities - An array or a single number representing the quantities for each transaction. | |
* @param {number[] | number} transactionPrices - An array or a single number representing the prices for each transaction. | |
* @throws Will throw an error if transactionPrices and transactionQuantities are not arrays or if their lengths are not equal. |