Markets end higher amid volatility; Midcaps outperform, Paytm, Auto stocks rally