Markets end marginally lower in volatile trade; mid-cap and