Estimating how much money you can earn in the stock market?

Estimating how much money you can earn in the stock market?

Manage alerts

Loading saved threads...

stats_noob · External communityPost link
External question — Economics Stack Exchange Author: stats_noob Original post: https://economics.stackexchange.com/questions/59746 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I live in Canada. I know very little about the stock market. I am trying to answer the following question: If on date1, I had X Canadian dollars and wanted to invest all of it into an ETF like SPY - how much would it be worth on date2 (date2>date1) after we factor in currency conversion (Canadian to American on purchase and American to Canadian on selling) and management fees? Basically, given my initial investment at the initial date - what would be my pure profit in Canadian dollars (every day until the end) until I finally decide to sell ... after taking everything into consideration? Using real world data, here is my attempt to do this in R. To begin, I defined the initial parameters (i.e. dates, amounts) and got the currency exchange data from Bank of Canada: library(quantmod) library(ggplot2) library(xts) library(tidyverse) library(patchwork) library(lubridate) cad_amount <- 10000 start_date <- as.Date("2020-01-01") end_date <- as.Date("2024-01-05") annual_fee <- 0.000945 exchange_url <- sprintf( "https://www.bankofcanada.ca/valet/observations/FXUSDCAD/csv?start_date=%s&end_date=%s", format(start_date, "%Y-%m-%d"), format(end_date, "%Y-%m-%d") ) exchange_data <- read_csv(exchange_url, skip = 8) %>% rename(exchange_rate = FXUSDCAD) initial_exchange_rate <- exchange_data$exchange_rate[1] usd_investment <- cad_amount / initial_exchange_rate Then, I got the SPY data and factored in all fees (this was taken from a tutorial online): spy_data <- getSymbols("SPY", from = start_date, to = end_date, auto.assign = FALSE) adj_prices <- Ad(spy_data) daily_fee_rate <- annual_fee / 252 # 252 trading days in a year trading_days <- 1:length(adj_prices) cumulative_fee_factor <- (1 - daily_fee_rate)^trading_days shares_bought <- usd_investment / as.numeric(adj_prices[1]) portfolio_value_usd_with_fees <- shares_bought * adj_prices * cumulative_fee_factor portfolio_value_usd_no_fees <- shares_bought * adj_prices In the next part, I merged the currency exchange data with the SPY data: spy_df <- data.frame( date = index(portfolio_value_usd_with_fees), value_usd_with_fees = as.numeric(portfolio_value_usd_with_fees), value_usd_no_fees = as.numeric(portfolio_value_usd_no_fees) ) final_df <- spy_df %>% left_join(exchange_data, by = c("date" = "date")) %>% mutate( value_cad_with_fees = value_usd_with_fees * exchange_rate, value_cad_no_fees = value_usd_no_fees * exchange_rate ) %>% pivot_longer( cols = c(value_cad_with_fees, value_cad_no_fees), names_to = "type", values_to = "value" ) final_values <- spy_df %>% tail(1) %>% left_join(exchange_data, by = c("date" = "date")) %>% mutate( final_cad_with_fees = value_usd_with_fees * exchange_rate, final_cad_no_fees = value_usd_no_fees * exchange_rate ) The last part is optional, but I (spent a lot of time) and plotted the final results: value_plot <- ggplot(final_df, aes(x = date, y = value, color = type)) + geom_line(size = 0.8) + theme_minimal() + labs( title = "SPY Investment Value in Canadian Dollars", subtitle = sprintf( "Period: %s to %s\nInitial: CAD $%s (USD $%s)\nFinal with fees: CAD $%s (USD $%s)\nFinal without fees: CAD $%s (USD $%s)\nAnnual Fee: %.3f%%", format(start_date, "%B %d, %Y"), format(end_date, "%B %d, %Y"), format(cad_amount, big.mark = ","), format(round(usd_investment, 2), big.mark = ","), format(round(final_values$final_cad_with_fees, 2), big.mark = ","), format(round(final_values$value_usd_with_fees, 2), big.mark = ","), format(round(final_values$final_cad_no_fees, 2), big.mark = ","), format(round(final_values$value_usd_no_fees, 2), big.mark = ","), annual_fee * 100 ), x = "Date", y = "Value (CAD)", color = "Scenario" ) + scale_y_continuous(labels = scales::dollar_format(prefix = "CAD $")) + scale_color_manual( values = c( "value_cad_with_fees" = "red", "value_cad_no_fees" = "blue" ), labels = c( "value_cad_with_fees" = "With Fees", "value_cad_no_fees" = "Without Fees" ) ) + theme( plot.title = element_text(size = 12, face = "bold"), plot.subtitle = element_text(size = 10), legend.position = "bottom" ) exchange_plot <- ggplot(exchange_data, aes(x = date, y = exchange_rate)) + geom_line(color = "black", size = 0.8) + theme_minimal() + labs( title = "USD/CAD Exchange Rate", subtitle = sprintf( "Period: %s to %s\nInitial Rate: %.4f\nFinal Rate: %.4f\nChange: %.2f%%", format(start_date, "%B %d, %Y"), format(end_date, "%B %d, %Y"), initial_exchange_rate, tail(exchange_data$exchange_rate, 1), (tail(exchange_data$exchange_rate, 1) / initial_exchange_rate - 1) * 100 ), x = "Date", y = "Exchange Rate (CAD per 1 USD)" ) + scale_y_continuous(labels = scales::number_format(accuracy = 0.001)) + theme( plot.title = element_text(size = 12, face = "bold"), plot.subtitle = element_text(size = 10) ) While the results look reasonable (by reasonable, I mean that the graphs are not showing absurd impossible values), I am not sure if I did this correctly. There are a lot of moving parts (e.g. currency conversion, management fee application) and I am not sure if I my understanding of all this matches what actually happens in the market. Can someone please help me review this? Thank you! Note: I did not use the retail fee for converting Canadian to American dollars (and vice versa) ... I also did not use the dividend payment scheme because I do not fully understand it.
Quote
Report
AKdemy · External communityPost link
External answer — Economics Stack Exchange Author: AKdemy Original post: https://economics.stackexchange.com/a/59767 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You generally don't need to separately take into account expense ratios, because they're not itemized on your account statements or confirmations. Instead, each fund's expenses are deducted from its total value on a regular basis. And those expenses cut directly into your investment returns. Source: https://investor.vanguard.com/investor-resources-education/education/expense-ratio The SPY prospectus is very detailed. See https://economics.stackexchange.com/a/59767/37817 . There is one complication of you look at return charts though, namely they assume the reinvestment of dividends. This will have a big impact in the long run. FX adjustment Calculate currency adjusted returns explains it in detail? It's quite simple essentially, especially for a single buy and hold strategy like you have. It's really just the combination of the two returns. I wouldn't worry about exact details because the real problem is that the future is unknown. Yes, SPX has had some very good years recently, but there have been some lost decades too. Same for FX rates, no one knows where they will be heading. See https://quant.stackexchange.com/a/67940/54838 for lots of theory and empirical tests. So even if your chary looks as if it's a great deal, you will only know with the benefit of hindsight.
Quote
Report

Post Reply

Checking account access…