[Feature]: capital gain display in addition to the account variation in percent
Opened this issue · 0 comments
Describe your feature request
Hi,
Currently, in the Ledger Live application, the variation in percent of the value is displayed.
This value is computed using the current value of the account, and not capital gain ; this implies that, for example, if I add tokens in the account (get or buy tokens), the value of the account get up, hence drive the percent up, even if no real gain has been done.
As an example, if I have 100$, then buy 100$ more, and the value for one token get down 50%, 0% variation will be displayed for that account, even if I've spent 200$ and have a value of 100$ now.
It would be interesting to add (in addition, or as option) the capital gain computed with the data already stored in the transaction history (with the "transaction date" value and the "Current value" fields).
At the moment, I do the computation as follow in R :
library(readr)
library(dplyr)
library(reshape2)
library(magrittr)
options("scipen" = 100, "digits" = 4)
raw <- read_csv("ledgerlive-operations.csv", show_col_types = FALSE) %>%
filter(`Operation Type` %in% c("IN", "OUT")) %>%
mutate(
name = `Currency Ticker`,
fac = ifelse(`Operation Type` == "IN", 1, -1),
value_date = `Countervalue at Operation Date` * fac,
value_now = `Countervalue at CSV Export` * fac,
amount = `Operation Amount` * fac,
)
data <- raw %>%
select(c("name", "value_date", "value_now", "amount")) %>%
na.omit() %>%
melt(id = c("name")) %>%
dcast(name ~ variable, sum) %>%
mutate(
mean_price = value_date / amount,
gain = value_now - value_date,
gain_percent = gain / value_date * 100
) %>%
arrange(-gain_percent) %>%
filter(value_now > 1)
data
data %>%
summarise(
value_date = sum(value_date),
value_now = sum(value_now),
gain = sum(gain),
) %>%
mutate(gain_percent = gain / value_date * 100)