Optimal direct data-driven control with stability guarantees