I have the following sampled dataset:
df <- structure(list(Data = structure(c(1623888000, 1629158400, 1629158400
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Client = c("Client1",
"Client1", "Client1"), Fund = c("Fund1", "Fund1", "Fund2"), Nature = c("Application",
"Rescue", "Application"), Quantity = c(433.059697, 0, 171.546757
), Value = c(69800, -70305.67, 24875), `NAV Yesterday` = c(162.40991399996,
162.40991399996, 145.044589000056), `NAV in Application Date` = c(161.178702344125,
162.346370458944, 145.004198476337), `Var NAV` = c(0.00763879866215962,
0.00039140721678275, 0.000278547270652531), `Var * Value` = c(533.188146618741,
-27.5181466187465, 6.92886335748171), FinalValue = c(70333.1881466187,
-70333.1881466187, 24881.9288633575), `Rentability WRONG` = c(0.0210345899274819,
0.0210345899274819, 0.0210345899274819)), row.names = c(NA, -3L
), class = c("tbl_df", "tbl", "data.frame"))
Explaining the data: A client investments portfolio, with Ins/Positive Cash Flows/Applications and Outs/Negative Cash Flows/Rescues. This client has put money in Fund1, earned some profit and rescued everything two months later to then put money in Fund2.
NAV means the Funds' value
My question is: I was calculating the rentability by doing
(sum(df$FinalValue)/sum(df$Value))-1
but it gives me a wrong result and a very high interest.
The correct calculation for real rentability probably is:
((70305+24881)/(69800+24875)) - 1
How can I program a logic that do this everytime I have a Rescue with Quantity = 0? Cause I have other clients and some of them don't have rescues or have rescues with quantity > 0, so the formula (sum(df$FinalValue)/sum(df$Value))-1 fit well for those cases, only the Quantity = 0 is screwing my code.
Aucun commentaire:
Enregistrer un commentaire