aapl_log_returns <- dailyReturn(AAPL, type = "log")
rolling_sd <- rollapply(aapl_returns, width = 30, FUN = sd, fill = NA) plot(rolling_sd, main = "30-day Rolling Volatility") financial analysis in r
R is no longer just a language for statisticians; it is a production-grade tool for financial analysis. As you have seen in this guide, you can go from raw CSV or API data to: type = "log") rolling_sd <
stock_prices <- tq_get(symbols, from = start_date, to = end_date, get = "stock.prices") width = 30
# Download Apple stock data getSymbols("AAPL", from = "2020-01-01", to = Sys.Date()) head(AAPL)
# Simple returns aapl_returns <- dailyReturn(AAPL)
cat("Expected Return:", round(port_return, 4), "\nExpected Risk:", round(port_risk, 4))