laresbernardo / lares

Analytics & Machine Learning R Sidekick
https://laresbernardo.github.io/lares/
232 stars 49 forks source link

Portfolio performance: some issues and questions #24

Closed ElKron closed 4 years ago

ElKron commented 4 years ago

Hi Bernardo,

I tried out your portfolio performance functions. The graphs are very useful in conjunction with the automatic data scraping and processing. I have some questions and uncovered some issues you could have a look at if you have the time. I also have some suggestions for functionality but will put that in a separate issue,

Issues:

Questions:

Sorry for the long post. Thank you for all the help!

ElKron

laresbernardo commented 4 years ago

Hi @ElKron Thanks for your feedback and comments. I'll start commenting below:

$stocks [1] "Date" "Symbol" "Value" "Quant" "Each" "Invested" "Cost"
[8] "Dividend" "CumValue" "CumInvested" "CumROI" "CumQuant" "DifUSD" "CumDividend" [15] "CumCost" "Weight" "Type"

$portfolio [1] "Date" "CumInvested" "CumValue" "CumCost" "CumDividend" "ROI" "Invested"
[8] "Dividend" "Cash" "DifUSD" "CumCash" "Portfolio"

$plots [1] "roi1" "roi2" "growth" "summary" "change1" "change2" "types"


- And for your last question, I'd simply add those up in the transactions tab with a minus. So instead of deposits, those costs would be negative deposits.
laresbernardo commented 4 years ago

So, my homework here would be:

Good-to-haves that I will NOT invest my time in right now:

ElKron commented 4 years ago

Thank you for all the help!

I have 2 follow-up concerns:

PortfolioDummy.xlsx

Code you can use to check the above:

library(lares)
df <- stocks_file(filename = "PortfolioDummy.xlsx")
df$transactions$Date <- as.Date(df$transactions$Date)
str(df$transactions)
dfp <- stocks_obj(df)
dfp$stocks

In any case, thank you for your time and help!

laresbernardo commented 4 years ago
laresbernardo commented 4 years ago

@ElKron done! With the latest fix, you should have the correct cumulative value even though for some days you have no quotes over some of the stocks. Cheers and thanks for reporting this case!

ElKron commented 4 years ago

@laresbernardo ,

The dividends work like a charm indeed! Many thanks!

The cumulative stock quantity however is not yet fully fixed (see previous example Excel). The issue lies in the following line daily <- hist %>% left_join(trans, by = c("Date", "Symbol")) If the history does not contain the same date for a specific symbol as is present in the transaction data, the quantity sold or bought will not show up in the daily dataframe. Maybe another join function (full_join?) might help, but then the follow-up data wrangling code needs adjustments. I do understand that you don't want repeated rows though.

Sorry to bother you with these tedious bugs and thanks for all the help...

laresbernardo commented 4 years ago

Ok, please do check again. Should be fixed by now to work with your portfolio @ElKron A full_join wouldn't work. I did an expand.grid over all dates and existing Symbols so every day has all possible tickers, and tidyr::filled up the values.