[This article was first published on
R Views, and kindly contributed to
R-bloggers]. (You can report issue about the content on this page
here)
Want to share your content on R-bloggers?
click here if you have a blog, or
here if you don't.
In two previous posts, we explored IPOs and IPO returns by sector and year since 2004 and then examined the returns of portfolios constructed by investing in IPOs each year. In today’s post, we will add a benchmark so that we can compare our IPO portfolios to something besides themselves. Next time, we will delve into return attribution to visualize how individual equities have contributed to portfolios over time.
I won’t review the code from the previous posts, but briefly we imported prices for every ticker that IPO’d between 2004 and 2014, found the monthly returns of those tickers, then constructed portfolios on a year-by-year basis, so that we had a portfolio formed each year consisting of equal weights in every IPO for that year.
# object holding time series of monthly closing prices, monthly returns, tickers, IOP year and sectoripo_riingo_prices_pins # function to calculate returns of portfolios constructed by investing equally in each IPO in each yearipo_by_year_portfolios <- function(year, show_growth = F){ ipo_riingo_prices_pins %>% select(ticker, date, monthly_returns, ipo.year) %>% filter(ipo.year == year) %>% tq_portfolio(assets_col = ticker, returns_col = monthly_returns, col_rename = paste(year, "_port_returns", sep = ""), wealth.index = show_growth, rebalance_on = "months")}# vector of yearsyears_numeric <- seq(2004, 2014, by = 1)# pass the years and the indiviual returns object to the functionreturns_each_year_ipo_portfolios <-map(years_numeric, ipo_by_year_portfolios) %>% reduce(left_join)
And here is the resulting object of portfolio returns:
returns_each_year_ipo_portfolios %>% tail()
# A tibble: 6 x 12 date `2004_port_retu… `2005_port_retu… `2006_port_retu… 1 2019-05-31 00:00:00 -0.101 -0.0575 0.261 2 2019-06-28 00:00:00 0.382 0.0635 0.0533 3 2019-07-31 00:00:00 0.00659 0.0185 0.0346 4 2019-08-30 00:00:00 -0.0229 -0.0317 -0.007895 2019-09-30 00:00:00 0.0256 0.00545 -0.005396 2019-10-31 00:00:00 0.0347 0.0180 0.0233 # … with 8 more variables: `2007_port_returns` ,# `2008_port_returns` , `2009_port_returns` ,# `2010_port_returns` , `2011_port_returns` ,# `2012_port_returns` , `2013_port_returns` ,# `2014_port_returns`
All that was done last time, and it gave us the returns of our 11 IPO portfolios from formation to today.
Now, let’s calculate the returns of a benchmark portfolio so we can compare those IPO portfolios to something besides themselves. We will use SPY as the benchmark and start by importing monthly prices since 2004. I’ll also go ahead and calculate monthly returns in the same piped flow.
spy_benchmark <- "SPY" %>% riingo_prices(start_date = "2004-01-01", end_date = "2019-10-31", resample_frequency = "monthly") %>% select(ticker, date, close) %>% mutate(spy_monthly_returns = close/lag(close) - 1) %>% na.omit()spy_benchmark %>% head()
# A tibble: 6 x 4 ticker date close spy_monthly_returns 1 SPY 2004-02-27 00:00:00 115. 0.01362 SPY 2004-03-31 00:00:00 113. -0.01673 SPY 2004-04-30 00:00:00 111. -0.01894 SPY 2004-05-31 00:00:00 113. 0.01715 SPY 2004-06-30 00:00:00 115. 0.01486 SPY 2004-07-30 00:00:00 111. -0.0322
From here, it’s straightforward to compare these benchmark returns to those of the 2004 IPO portfolio. First, we line up the two columns of returns.
returns_each_year_ipo_portfolios %>% select(date, `2004_port_returns`) %>% add_column(benchmark = spy_benchmark$spy_monthly_returns) %>% tail()
# A tibble: 6 x 3 date `2004_port_returns` benchmark 1 2019-05-31 00:00:00 -0.101 -0.06382 2019-06-28 00:00:00 0.382 0.06443 2019-07-31 00:00:00 0.00659 0.01514 2019-08-30 00:00:00 -0.0229 -0.01675 2019-09-30 00:00:00 0.0256 0.01486 2019-10-31 00:00:00 0.0347 0.0221
Then we pivot_longer()
and apply the SharpeRatio()
function, same as we did last time.
returns_each_year_ipo_portfolios %>% select(date, `2004_port_returns`) %>% add_column(benchmark = spy_benchmark$spy_monthly_returns) %>% pivot_longer(-date, names_to = "portfolio", values_to = "monthly_return") %>% group_by(portfolio) %>% arrange(portfolio, date) %>% filter(!is.na(monthly_return)) %>% tq_performance(Ra = monthly_return, performance_fun = SharpeRatio, Rf = 0, FUN= "StdDev")
# A tibble: 2 x 2# Groups: portfolio [2] portfolio `StdDevSharpe(Rf=0%,p=95%)` 1 2004_port_returns 0.2342 benchmark 0.153
Here’s the result piped straight to ggplot()
.
returns_each_year_ipo_portfolios %>% select(date, `2004_port_returns`) %>% add_column(benchmark = spy_benchmark$spy_monthly_returns) %>% pivot_longer(-date, names_to = "portfolio", values_to = "monthly_return") %>% group_by(portfolio) %>% arrange(portfolio, date) %>% filter(!is.na(monthly_return)) %>% tq_performance(Ra = monthly_return, performance_fun = SharpeRatio, Rf = 0, FUN= "StdDev") %>% `colnames<-`(c("portfolio", "port_sharpe")) %>% ggplot(aes(x = portfolio, y = port_sharpe, fill = portfolio)) + geom_col(width = .2) + labs(y = "sharpe ratio", title = "Benchmark v. IPO Portfolio")
![]()
Our IPO portfolio has a higher Sharpe Ratio, but remember that we built this without regard to survivorship bias, we didn’t invest in any companies that haven’t survived to 2019.
That’s a nice comparison of one portfolio to the benchmark, but we want to run this same analysis on all of our portfolios.
First, let’s calculate the Sharpes for all of our IPO portfolios, same as we did last time.
years_numeric <- seq(2004, 2014, by = 1)port_sharpes <- returns_each_year_ipo_portfolios %>% pivot_longer(-date, names_to = "portfolio_by_year", values_to = "monthly_return") %>% group_by(portfolio_by_year) %>% arrange(portfolio_by_year, date) %>% filter(!is.na(monthly_return)) %>% tq_performance(Ra = monthly_return, performance_fun = SharpeRatio, Rf = 0, FUN= "StdDev") %>% `colnames<-`(c("portfolio_by_year", "port_sharpe"))%>% add_column(year = years_numeric)port_sharpes
# A tibble: 11 x 3# Groups: portfolio_by_year [11] portfolio_by_year port_sharpe year 1 2004_port_returns 0.234 2004 2 2005_port_returns 0.192 2005 3 2006_port_returns 0.249 2006 4 2007_port_returns 0.190 2007 5 2008_port_returns 0.142 2008 6 2009_port_returns 0.220 2009 7 2010_port_returns 0.279 2010 8 2011_port_returns 0.152 2011 9 2012_port_returns 0.309 201210 2013_port_returns 0.182 201311 2014_port_returns 0.218 2014
And now, let’s calculate the Sharpe Ratio for the benchmark for each year. That means we will build or organize 11 different return streams for SPY, each starting in a year from 2004 to 2014, and then calculate the Sharpes for each of those 11 return streams.
Here’s how we do it for just 2004.
start_year <- "2004"start_date <- ymd(parse_date(start_year, format = "%Y"))spy_benchmark %>% filter(date >= start_date) %>% tq_performance(Ra = spy_monthly_returns, performance_fun = SharpeRatio, Rf = 0, FUN= "StdDev")
# A tibble: 1 x 1 `StdDevSharpe(Rf=0%,p=95%)` 1 0.153
This looks like a good candidate for a function that accepts one argument, the start_year
, that we can pass a vector of years.
spy_sharpe_function <- function(start_year){start_date <- ymd(parse_date(start_year, format = "%Y"))spy_benchmark %>% filter(date >= start_date) %>% tq_performance(Ra = spy_monthly_returns, performance_fun = SharpeRatio, Rf = 0, FUN = "StdDev") %>% `colnames<-`("spy_sharpe") %>% mutate(year = as.numeric(start_year))}
Let’s pass in one year and peek at the result.
spy_sharpe_function("2005")
# A tibble: 1 x 2 spy_sharpe year 1 0.150 2005
Now, let’s map across different years.
years_character <- as.character(years_numeric)spy_sharpes <- map_dfr(years_character, spy_sharpe_function)spy_sharpes
# A tibble: 11 x 2 spy_sharpe year 1 0.153 2004 2 0.150 2005 3 0.152 2006 4 0.139 2007 5 0.141 2008 6 0.258 2009 7 0.253 2010 8 0.263 2011 9 0.310 201210 0.300 201311 0.229 2014
That worked! Let’s join our benchmark results with the IPO portfolio results for ease of comparison and pipe straight to ggplot()
.
port_sharpes %>% left_join(spy_sharpes, by = "year") %>% pivot_longer(c(-year, -portfolio_by_year), names_to = "port_type", values_to = "sharpe") %>% ggplot(aes(x = year, y = sharpe, fill = port_type)) + geom_col(position = position_dodge2(padding = .2)) + scale_x_continuous(breaks = scales::pretty_breaks(n = 10))
![]()
It looks like our IPO portfolios outperformed in the years 2004-2007. That might be due to our survivorship bias since we’re only investing in companies that we know, with hindsight, have survived to 2019.
Let’s also remember that Sharpe Ratios aren’t everything. Our IPO portfolios might be so volatile that we wouldn’t have a the gumption to stick with them through the hard times. To get a better sense of what we’d have faced, let’s visualize the drawdowns for the 2004 IPO portfolio versus the benchmark.
returns_each_year_ipo_portfolios %>% select(date, `2004_port_returns`) %>% left_join(spy_benchmark %>% select(date, spy_monthly_returns), by = "date") %>% pivot_longer(-date, names_to = "fund", values_to = "drawdown") %>% mutate(drawdown = case_when(drawdown > 0 ~ 0, TRUE ~ drawdown), drawdown = drawdown * 100) %>% plot_ly(type = 'scatter', x = ~date, y = ~drawdown, color = ~fund, mode = 'lines', fill = 'tonexty') %>% layout(yaxis = list(ticksuffix = "%"))
{"x":{"visdat":{"1c2d816c1b2":["function () ","plotlyVisDat"]},"cur_data":"1c2d816c1b2","attrs":{"1c2d816c1b2":{"x":{},"y":{},"mode":"lines","fill":"tonexty","color":{},"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"type":"scatter"}},"layout":{"margin":{"b":40,"l":60,"t":25,"r":10},"yaxis":{"domain":[0,1],"automargin":true,"ticksuffix":"%","title":"drawdown"},"xaxis":{"domain":[0,1],"automargin":true,"title":"date"},"hovermode":"closest","showlegend":true},"source":"A","config":{"showSendToCloud":false},"data":[{"fillcolor":"rgba(102,194,165,0.5)","x":["2004-02-27","2004-03-31","2004-04-30","2004-05-31","2004-06-30","2004-07-30","2004-08-31","2004-09-30","2004-10-29","2004-11-30","2004-12-31","2005-01-31","2005-02-28","2005-03-31","2005-04-29","2005-05-31","2005-06-30","2005-07-29","2005-08-31","2005-09-30","2005-10-31","2005-11-30","2005-12-30","2006-01-31","2006-02-28","2006-03-31","2006-04-28","2006-05-31","2006-06-30","2006-07-31","2006-08-31","2006-09-29","2006-10-31","2006-11-30","2006-12-29","2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31","2007-11-30","2007-12-31","2008-01-31","2008-02-29","2008-03-31","2008-04-30","2008-05-30","2008-06-30","2008-07-31","2008-08-29","2008-09-30","2008-10-31","2008-11-28","2008-12-31","2009-01-30","2009-02-27","2009-03-31","2009-04-30","2009-05-29","2009-06-30","2009-07-31","2009-08-31","2009-09-30","2009-10-30","2009-11-30","2009-12-31","2010-01-29","2010-02-26","2010-03-31","2010-04-30","2010-05-31","2010-06-30","2010-07-30","2010-08-31","2010-09-30","2010-10-29","2010-11-30","2010-12-31","2011-01-31","2011-02-28","2011-03-31","2011-04-29","2011-05-31","2011-06-30","2011-07-29","2011-08-31","2011-09-30","2011-10-31","2011-11-30","2011-12-30","2012-01-31","2012-02-29","2012-03-30","2012-04-30","2012-05-31","2012-06-29","2012-07-31","2012-08-31","2012-09-28","2012-10-31","2012-11-30","2012-12-31","2013-01-31","2013-02-28","2013-03-29","2013-04-30","2013-05-31","2013-06-28","2013-07-31","2013-08-30","2013-09-30","2013-10-31","2013-11-29","2013-12-31","2014-01-31","2014-02-28","2014-03-31","2014-04-30","2014-05-30","2014-06-30","2014-07-31","2014-08-29","2014-09-30","2014-10-31","2014-11-28","2014-12-31","2015-01-30","2015-02-27","2015-03-31","2015-04-30","2015-05-29","2015-06-30","2015-07-31","2015-08-31","2015-09-30","2015-10-30","2015-11-30","2015-12-31","2016-01-29","2016-02-29","2016-03-31","2016-04-29","2016-05-31","2016-06-30","2016-07-29","2016-08-31","2016-09-30","2016-10-31","2016-11-30","2016-12-30","2017-01-31","2017-02-28","2017-03-31","2017-04-28","2017-05-31","2017-06-30","2017-07-31","2017-08-31","2017-09-29","2017-10-31","2017-11-30","2017-12-29","2018-01-31","2018-02-28","2018-03-30","2018-04-30","2018-05-31","2018-06-29","2018-07-31","2018-08-31","2018-09-28","2018-10-31","2018-11-30","2018-12-31","2019-01-31","2019-02-28","2019-03-29","2019-04-30","2019-05-31","2019-06-28","2019-07-31","2019-08-30","2019-09-30","2019-10-31"],"y":[0,-0.295815295815294,-0.141119593717165,0,-1.93752410637577,-4.72239982815398,0,0,0,0,0,-3.70639357490493,0,-3.00530627701531,-3.81806362298608,0,0,0,-1.26513049452097,0,-1.89137272158877,0,-0.946261996001996,0,0,0,0,-6.34596548654075,0,-5.91035612348375,0,0,0,0,0,0,-0.213265234430571,-2.62806652852446,0,-0.0149890386356488,-0.179904137311604,-4.89392192121064,0,0,-1.30469848582844,-5.48966214003839,-2.85051933350475,-4.52078240891041,-3.52702208486766,-5.95172682580952,0,0,-14.6995547145298,0,0,-6.33453655977434,-25.9957017144956,-22.4903446574257,0,-3.19761356345966,-13.5707334967038,0,0,0,0,0,0,0,-10.1494851182686,0,0,-2.69266473413294,0,0,0,-7.62824610612567,-5.13607276621238,0,-7.66044655752229,0,0,0,0,0,0,-1.7186077348644,0,-1.04402587300515,-4.68194003999343,-3.74610547774487,-10.5062737621681,-11.924927241082,0,0,-0.661402195159844,0,0,0,-2.73179449181347,-9.44002944351068,0,0,0,0,-5.21803432832407,-0.214676371621814,0,0,0,0,0,0,0,0,-3.59346172807691,0,0,0,0,0,0,-2.50275749731994,-3.37252195368758,0,0,-4.69405141116664,0,-6.10762482098695,0,0,0,-0.352254454582457,0,0,-2.92648248789646,0,0,-2.59109039955647,-3.74955696015122,0,0,0,-3.35379981060538,-7.31716451366049,-0.946199311782181,0,-0.324898561218778,0,0,0,0,-1.21733838357995,-5.33075702335386,0,0,0,0,0,-0.348674419893835,0,0,0,0,0,0,0,0,0,-5.2002051058019,0,-0.367518949618306,0,-1.73130237875992,-0.662274107634253,0,-1.80162853672178,-13.1202468083387,0,-12.4413126039325,0,0,0,0,-10.0519235664213,0,0,-2.29265699032184,0,0],"mode":"lines","fill":"tonexty","type":"scatter","name":"2004_port_returns","marker":{"color":"rgba(102,194,165,1)","line":{"color":"rgba(102,194,165,1)"}},"textfont":{"color":"rgba(102,194,165,1)"},"error_y":{"color":"rgba(102,194,165,1)"},"error_x":{"color":"rgba(102,194,165,1)"},"line":{"color":"rgba(102,194,165,1)"},"xaxis":"x","yaxis":"y","frame":null},{"fillcolor":"rgba(141,160,203,0.5)","x":["2004-02-27","2004-03-31","2004-04-30","2004-05-31","2004-06-30","2004-07-30","2004-08-31","2004-09-30","2004-10-29","2004-11-30","2004-12-31","2005-01-31","2005-02-28","2005-03-31","2005-04-29","2005-05-31","2005-06-30","2005-07-29","2005-08-31","2005-09-30","2005-10-31","2005-11-30","2005-12-30","2006-01-31","2006-02-28","2006-03-31","2006-04-28","2006-05-31","2006-06-30","2006-07-31","2006-08-31","2006-09-29","2006-10-31","2006-11-30","2006-12-29","2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31","2007-11-30","2007-12-31","2008-01-31","2008-02-29","2008-03-31","2008-04-30","2008-05-30","2008-06-30","2008-07-31","2008-08-29","2008-09-30","2008-10-31","2008-11-28","2008-12-31","2009-01-30","2009-02-27","2009-03-31","2009-04-30","2009-05-29","2009-06-30","2009-07-31","2009-08-31","2009-09-30","2009-10-30","2009-11-30","2009-12-31","2010-01-29","2010-02-26","2010-03-31","2010-04-30","2010-05-31","2010-06-30","2010-07-30","2010-08-31","2010-09-30","2010-10-29","2010-11-30","2010-12-31","2011-01-31","2011-02-28","2011-03-31","2011-04-29","2011-05-31","2011-06-30","2011-07-29","2011-08-31","2011-09-30","2011-10-31","2011-11-30","2011-12-30","2012-01-31","2012-02-29","2012-03-30","2012-04-30","2012-05-31","2012-06-29","2012-07-31","2012-08-31","2012-09-28","2012-10-31","2012-11-30","2012-12-31","2013-01-31","2013-02-28","2013-03-29","2013-04-30","2013-05-31","2013-06-28","2013-07-31","2013-08-30","2013-09-30","2013-10-31","2013-11-29","2013-12-31","2014-01-31","2014-02-28","2014-03-31","2014-04-30","2014-05-30","2014-06-30","2014-07-31","2014-08-29","2014-09-30","2014-10-31","2014-11-28","2014-12-31","2015-01-30","2015-02-27","2015-03-31","2015-04-30","2015-05-29","2015-06-30","2015-07-31","2015-08-31","2015-09-30","2015-10-30","2015-11-30","2015-12-31","2016-01-29","2016-02-29","2016-03-31","2016-04-29","2016-05-31","2016-06-30","2016-07-29","2016-08-31","2016-09-30","2016-10-31","2016-11-30","2016-12-30","2017-01-31","2017-02-28","2017-03-31","2017-04-28","2017-05-31","2017-06-30","2017-07-31","2017-08-31","2017-09-29","2017-10-31","2017-11-30","2017-12-29","2018-01-31","2018-02-28","2018-03-30","2018-04-30","2018-05-31","2018-06-29","2018-07-31","2018-08-31","2018-09-28","2018-10-31","2018-11-30","2018-12-31","2019-01-31","2019-02-28","2019-03-29","2019-04-30","2019-05-31","2019-06-28","2019-07-31","2019-08-30","2019-09-30","2019-10-31"],"y":[0,-1.66927490871153,-1.8921308576481,0,0,-3.22186326726621,0,0,0,0,0,-2.24207826590552,0,-2.21337975627953,-1.87351644625297,0,-0.251088048208903,0,-0.937449490867948,0,-2.36508452535762,0,-0.717646120724014,0,0,0,0,-3.01209401384346,-0.219590620343502,0,0,0,0,0,0,0,-1.96173913043478,0,0,0,-1.88494651708844,-3.13102439672938,0,0,0,-3.87326220497899,-1.64805596663526,-6.04609807810683,-2.58426148358449,-1.38245404274399,0,0,-8.81368008550053,-0.898577902797315,0,-9.70549382236382,-16.6695352839931,-6.96065269028193,0,-8.21143617021276,-10.7448991911143,0,0,0,-0.626823732843396,0,0,0,-1.92253054266502,0,0,-3.63424264178033,0,0,0,-7.94545913643633,-5.62311419950626,0,-4.49805024031921,0,0,0,0,0,0,-0.420578295155838,0,-1.12145422561021,-2.17197924388436,-2.0004546487838,-5.49756437021574,-7.42104401898216,0,-0.406374501992035,0,0,0,0,-0.667566223989768,-6.00557660684922,0,0,0,0,-1.81982357435577,0,0,0,0,0,0,0,-1.85377791373509,0,-2.99922944698002,0,0,0,0,-3.52482538307434,0,0,0,0,0,-1.34375638667484,0,-1.83847341936126,0,0,-0.8011583011583,-2.96292692419967,0,-2.00797493591569,0,0,-2.48650184711566,0,-6.13447374673319,-3.01204819277108,0,0,-2.30964588624275,-4.97827046647373,-0.0830060582033498,0,0,0,-0.173942051086551,0,0,-0.496825834943415,-1.73370319001387,0,0,0,0,-0.308707235590133,0,0,0,0,0,0,0,0,0,0,-3.63604114934374,-3.12902632063317,0,0,0,0,0,0,-6.91042927903138,0,-9.33430074369671,0,0,0,0,-6.37711720291136,0,0,-1.67343576639882,0,0],"mode":"lines","fill":"tonexty","type":"scatter","name":"spy_monthly_returns","marker":{"color":"rgba(141,160,203,1)","line":{"color":"rgba(141,160,203,1)"}},"textfont":{"color":"rgba(141,160,203,1)"},"error_y":{"color":"rgba(141,160,203,1)"},"error_x":{"color":"rgba(141,160,203,1)"},"line":{"color":"rgba(141,160,203,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.2,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}
Click on the legend to isolate the chart of either the IPO portfolio or the benchmark and notice the much rougher history of the IPO portfolio. Our IPO portfolio had a large drawdown of around 26% in 2008 – would we have stuck with it?
I’ve been making my way through more of the courses over at Business Science U and one habit I’ve picked up is to wrap visualizations into functions. Let’s do that for the drawdown chart so that all we have to do is supply a year. This would be helpful in a Shiny application where we wanted to explore different years interactively.
drawdown_vis_fun <- function(start_year){ start_date <- ymd(parse_date(start_year, format = "%Y"))spy_benchmark <- spy_benchmark %>% filter(date >= start_date) ipo_port <- paste(start_year, "_port_returns", sep = "") returns_each_year_ipo_portfolios %>% select(date, `ipo_port`) %>% left_join(spy_benchmark %>% select(date, spy_monthly_returns), by = "date") %>% pivot_longer(-date, names_to = "fund", values_to = "drawdown") %>% mutate(drawdown = case_when(drawdown > 0 ~ 0, TRUE ~ drawdown), drawdown = drawdown * 100) %>% plot_ly(type = 'scatter', x = ~date, y = ~drawdown, color = ~fund, mode = 'lines', fill = 'tonexty') %>% layout(yaxis = list(ticksuffix = "%"))}
Now, let’s pass the function a single year and examine the drawdown history.
drawdown_vis_fun("2007")
{"x":{"visdat":{"1c2d36aa5053":["function () ","plotlyVisDat"]},"cur_data":"1c2d36aa5053","attrs":{"1c2d36aa5053":{"x":{},"y":{},"mode":"lines","fill":"tonexty","color":{},"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"type":"scatter"}},"layout":{"margin":{"b":40,"l":60,"t":25,"r":10},"yaxis":{"domain":[0,1],"automargin":true,"ticksuffix":"%","title":"drawdown"},"xaxis":{"domain":[0,1],"automargin":true,"title":"date"},"hovermode":"closest","showlegend":true},"source":"A","config":{"showSendToCloud":false},"data":[{"fillcolor":"rgba(102,194,165,0.5)","x":["2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31","2007-11-30","2007-12-31","2008-01-31","2008-02-29","2008-03-31","2008-04-30","2008-05-30","2008-06-30","2008-07-31","2008-08-29","2008-09-30","2008-10-31","2008-11-28","2008-12-31","2009-01-30","2009-02-27","2009-03-31","2009-04-30","2009-05-29","2009-06-30","2009-07-31","2009-08-31","2009-09-30","2009-10-30","2009-11-30","2009-12-31","2010-01-29","2010-02-26","2010-03-31","2010-04-30","2010-05-31","2010-06-30","2010-07-30","2010-08-31","2010-09-30","2010-10-29","2010-11-30","2010-12-31","2011-01-31","2011-02-28","2011-03-31","2011-04-29","2011-05-31","2011-06-30","2011-07-29","2011-08-31","2011-09-30","2011-10-31","2011-11-30","2011-12-30","2012-01-31","2012-02-29","2012-03-30","2012-04-30","2012-05-31","2012-06-29","2012-07-31","2012-08-31","2012-09-28","2012-10-31","2012-11-30","2012-12-31","2013-01-31","2013-02-28","2013-03-29","2013-04-30","2013-05-31","2013-06-28","2013-07-31","2013-08-30","2013-09-30","2013-10-31","2013-11-29","2013-12-31","2014-01-31","2014-02-28","2014-03-31","2014-04-30","2014-05-30","2014-06-30","2014-07-31","2014-08-29","2014-09-30","2014-10-31","2014-11-28","2014-12-31","2015-01-30","2015-02-27","2015-03-31","2015-04-30","2015-05-29","2015-06-30","2015-07-31","2015-08-31","2015-09-30","2015-10-30","2015-11-30","2015-12-31","2016-01-29","2016-02-29","2016-03-31","2016-04-29","2016-05-31","2016-06-30","2016-07-29","2016-08-31","2016-09-30","2016-10-31","2016-11-30","2016-12-30","2017-01-31","2017-02-28","2017-03-31","2017-04-28","2017-05-31","2017-06-30","2017-07-31","2017-08-31","2017-09-29","2017-10-31","2017-11-30","2017-12-29","2018-01-31","2018-02-28","2018-03-30","2018-04-30","2018-05-31","2018-06-29","2018-07-31","2018-08-31","2018-09-28","2018-10-31","2018-11-30","2018-12-31","2019-01-31","2019-02-28","2019-03-29","2019-04-30","2019-05-31","2019-06-28","2019-07-31","2019-08-30","2019-09-30","2019-10-31"],"y":[0,-0.373478121108783,-1.74466100562406,0,0,0,-0.646655280753494,-4.16698102659766,0,0,-7.84116144552191,0,-12.5261858003238,-0.761375544927934,-8.41546406112341,0,0,-7.72383002955002,-5.22477498462259,-1.16889306696306,-15.5643025440785,-27.2114725750787,-18.8429438575648,0,0,-6.82909690190625,0,0,0,0,0,0,0,-4.70128314867936,0,0,-1.23202686533598,0,0,0,-8.74464671654541,-2.67372549436515,0,-5.26967152950111,0,0,0,0,0,0,0,0,-4.97749445494336,-1.71666420595028,-3.05341639125853,-11.1533864834295,-15.454152423244,0,-1.54733863191958,-0.00294685957703544,0,0,0,-1.13750337137658,-11.3753635996192,0,-4.88436685786374,0,0,-2.53295151173353,-4.75769652330029,-1.71540133562261,0,-2.82787871140896,0,-0.659882872341055,0,-1.68496029635025,0,-1.66941637433361,0,0,0,0,-2.50439112167042,0,0,-3.94153379770423,-2.01805933213378,0,-1.38074311052729,0,-7.93139264231868,0,-1.09739890208397,-3.10374227192922,-5.55668433840695,0,0,0,-1.29480670415534,0,-4.52811783200635,-8.51422697587041,-9.68873837040534,0,0,0,-12.1017998327581,-3.62317011175987,0,0,-0.45417973231382,-3.29728291359559,0,0,0,-7.5867765025703,0,0,0,0,0,0,0,0,0,-0.965209777102616,0,-1.64044438257266,0,0,0,-3.15737391942515,0,0,0,0,-0.798267109614914,0,-0.974214173223709,-9.89447442748346,-2.69109718592567,-13.6085358819367,0,0,0,0,0,0,0,-6.98395462729431,0,0],"mode":"lines","fill":"tonexty","type":"scatter","name":"2007_port_returns","marker":{"color":"rgba(102,194,165,1)","line":{"color":"rgba(102,194,165,1)"}},"textfont":{"color":"rgba(102,194,165,1)"},"error_y":{"color":"rgba(102,194,165,1)"},"error_x":{"color":"rgba(102,194,165,1)"},"line":{"color":"rgba(102,194,165,1)"},"xaxis":"x","yaxis":"y","frame":null},{"fillcolor":"rgba(141,160,203,0.5)","x":["2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31","2007-11-30","2007-12-31","2008-01-31","2008-02-29","2008-03-31","2008-04-30","2008-05-30","2008-06-30","2008-07-31","2008-08-29","2008-09-30","2008-10-31","2008-11-28","2008-12-31","2009-01-30","2009-02-27","2009-03-31","2009-04-30","2009-05-29","2009-06-30","2009-07-31","2009-08-31","2009-09-30","2009-10-30","2009-11-30","2009-12-31","2010-01-29","2010-02-26","2010-03-31","2010-04-30","2010-05-31","2010-06-30","2010-07-30","2010-08-31","2010-09-30","2010-10-29","2010-11-30","2010-12-31","2011-01-31","2011-02-28","2011-03-31","2011-04-29","2011-05-31","2011-06-30","2011-07-29","2011-08-31","2011-09-30","2011-10-31","2011-11-30","2011-12-30","2012-01-31","2012-02-29","2012-03-30","2012-04-30","2012-05-31","2012-06-29","2012-07-31","2012-08-31","2012-09-28","2012-10-31","2012-11-30","2012-12-31","2013-01-31","2013-02-28","2013-03-29","2013-04-30","2013-05-31","2013-06-28","2013-07-31","2013-08-30","2013-09-30","2013-10-31","2013-11-29","2013-12-31","2014-01-31","2014-02-28","2014-03-31","2014-04-30","2014-05-30","2014-06-30","2014-07-31","2014-08-29","2014-09-30","2014-10-31","2014-11-28","2014-12-31","2015-01-30","2015-02-27","2015-03-31","2015-04-30","2015-05-29","2015-06-30","2015-07-31","2015-08-31","2015-09-30","2015-10-30","2015-11-30","2015-12-31","2016-01-29","2016-02-29","2016-03-31","2016-04-29","2016-05-31","2016-06-30","2016-07-29","2016-08-31","2016-09-30","2016-10-31","2016-11-30","2016-12-30","2017-01-31","2017-02-28","2017-03-31","2017-04-28","2017-05-31","2017-06-30","2017-07-31","2017-08-31","2017-09-29","2017-10-31","2017-11-30","2017-12-29","2018-01-31","2018-02-28","2018-03-30","2018-04-30","2018-05-31","2018-06-29","2018-07-31","2018-08-31","2018-09-28","2018-10-31","2018-11-30","2018-12-31","2019-01-31","2019-02-28","2019-03-29","2019-04-30","2019-05-31","2019-06-28","2019-07-31","2019-08-30","2019-09-30","2019-10-31"],"y":[0,-1.96173913043478,0,0,0,-1.88494651708844,-3.13102439672938,0,0,0,-3.87326220497899,-1.64805596663526,-6.04609807810683,-2.58426148358449,-1.38245404274399,0,0,-8.81368008550053,-0.898577902797315,0,-9.70549382236382,-16.6695352839931,-6.96065269028193,0,-8.21143617021276,-10.7448991911143,0,0,0,-0.626823732843396,0,0,0,-1.92253054266502,0,0,-3.63424264178033,0,0,0,-7.94545913643633,-5.62311419950626,0,-4.49805024031921,0,0,0,0,0,0,-0.420578295155838,0,-1.12145422561021,-2.17197924388436,-2.0004546487838,-5.49756437021574,-7.42104401898216,0,-0.406374501992035,0,0,0,0,-0.667566223989768,-6.00557660684922,0,0,0,0,-1.81982357435577,0,0,0,0,0,0,0,-1.85377791373509,0,-2.99922944698002,0,0,0,0,-3.52482538307434,0,0,0,0,0,-1.34375638667484,0,-1.83847341936126,0,0,-0.8011583011583,-2.96292692419967,0,-2.00797493591569,0,0,-2.48650184711566,0,-6.13447374673319,-3.01204819277108,0,0,-2.30964588624275,-4.97827046647373,-0.0830060582033498,0,0,0,-0.173942051086551,0,0,-0.496825834943415,-1.73370319001387,0,0,0,0,-0.308707235590133,0,0,0,0,0,0,0,0,0,0,-3.63604114934374,-3.12902632063317,0,0,0,0,0,0,-6.91042927903138,0,-9.33430074369671,0,0,0,0,-6.37711720291136,0,0,-1.67343576639882,0,0],"mode":"lines","fill":"tonexty","type":"scatter","name":"spy_monthly_returns","marker":{"color":"rgba(141,160,203,1)","line":{"color":"rgba(141,160,203,1)"}},"textfont":{"color":"rgba(141,160,203,1)"},"error_y":{"color":"rgba(141,160,203,1)"},"error_x":{"color":"rgba(141,160,203,1)"},"line":{"color":"rgba(141,160,203,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.2,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}
That’s all for today’s addendum.
I’m also going to be posting weekly code snippets on linkedin, connect with me there if you’re keen for some R finance stuff.
Thanks for reading and see you next time when we’ll tackle asset contribution to portfolio return!
_____='https://rviews.rstudio.com/2019/12/11/ipo-portfolios-and-a-benchmark/';
var vglnk = { key: '949efb41171ac6ec1bf7f206d57e90b8' }; (function(d, t) {var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;s.src = '//cdn.viglink.com/api/vglnk.js';var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));