weighted_value | R Documentation |
Calculate weighted stock values using FIFO/LIFO
weighted_value(
value,
n = rep(1, length(value)),
technique = NULL,
n_stocks = NULL,
buy_only = TRUE,
type = 1,
...
)
value |
Numeric vector. Representing the values of the stock. |
n |
Numeric vector. Representing the volume of the operation. Positive for 'Buy' and negative for 'Sale'. |
technique |
Character. Pick any of FIFO or LIFO, or NULL to skip. |
n_stocks |
Integer. Specify the number of stocks to consider. By
default will sum positive values of |
buy_only |
Boolean. Consider only buy (positive) values? |
type |
Integer. 1 for returning the value, 2 for returning the data.frame with the details ("df" attribute) |
... |
Additional parameters. |
The calculated weighted mean value.
values <- c(10, 20, 30, 40, 50)
weights <- c(2, 3, -4, 5, 6)
mean(values)
weighted_value(values)
weighted.mean(values, weights)
weighted_value(values, weights, buy_only = FALSE)
# Using FIFO and LIFO
weighted_value(values, weights, "FIFO")
weighted_value(values, weights, "LIFO", n_stocks = 8)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.