The tech-heavy Nasdaq 100 index added 39.7% in the first six months of the year, its biggest first-half gain on record, regaining much of its 2022 losses.