PortfolioAnalytics is not working

Hello,

I have used the following r code for plotting the maximum drawdown of a stock in the past. But since a few days my code is not working anymore. It seems that the PortfolioAnalytics package is not working. Does anybody know what is wrong here. Or maybe someone can test my code if it works:

library(PortfolioAnalytics)
library(ROI)
library(ROI.plugin.quadprog)
library(MASS)
library(dplyr)
library(caTools)
library(quantmod)
library(timeSeries)
library(astsa)
library(forecast)
library(ggplot2)
library(tidyquant)
library(timetk)
library(tibble)
library(corrplot)
library(tidyr)

# Get risk-free rate (1 month T-Bond rate) from FRED
rf <- getSymbols('DGS1MO', src = 'FRED', auto.assign = FALSE)

# ticker for Stock
ndx_symbol <- '^GSPC'


ndx <- getSymbols(ndx_symbol, from = "1950-01-01", auto.assign = FALSE)

str(ndx)

any(is.na(ndx))
dailyReturn

ndx_daily <- to.daily(ndx)

ndx_returns <- Return.calculate(ndx_daily$ndx.Adjusted)
ndx_returns <- ndx_returns[(-1),]
names(ndx_returns) <- 'NDX_daily'

plot.zoo(ndx_returns, main = 'SBUX Daily Returns', xlab = 'Date')

chart.Drawdown(ndx_returns, plot.engine = "ggplot2") +
  geom_hline(yintercept = -0.55, size = 1) +
  theme_minimal() +
  theme(legend.position = "none", 
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.caption = element_text(hjust = 0, lineheight = 0.5)) +
            scale_y_continuous(labels = scales::percent, limits=c(-1,0))+
ggtitle(paste0("Drawdowns of ",ndx_symbol,", monthly data"),
          subtitle = "Black line indicates bear markets")
          


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.