Anytime. The Algarve is blessed with good weather, with a mild winter and sun almost year-round. In short, weather-wise it is pretty safe most of the year.
For deserted beaches, come outside school holidays. The best months are April, May, June or September, when the sun is hot and visitors few. High summer is in July and August, which can mean loads of fun, nightlife, but also crowded facilities along the coastline. Head inland to find a quiet rural paradise that has changed little over the centuries.
In the winter time, from November to February, although it’s colder at night, there’s often warm sunshine in the middle of the day, so although swimming would only be for the truly hardy it is a wonderful time to have the Algarve to yourself.