Don't work with closing prices for statistical analysis. Work with returns (really log returns). This would have simplified some of the code, and made the plots in the same units rather than requiring separate axes.
More detail: https://quantivity.wordpress.com/2011/02/21/why-log-returns/