Joseph Haydn's Symphony No. 31 in D major was composed in 1765 for Haydn's patron Nikolaus Esterházy. It is nicknamed the "Hornsignal" symphony, because it gives a prominent role to an unusually large horn section, i.e. four players. Probably because of its prominent obbligato writing for the horns, in Paris, the publisher Sieber published this symphony as a "symphonie concertante" around 1785.
The backdrop of this and other early Haydn symphonies was a patron who loved music and wanted his household music to be performed by top musicians – but whose budget did not accommodate anything like the orchestras of the size seen in modern times. Personnel fluctuated, and thus also the forces Haydn had available to work with. Haydn himself sought to retain the best instrumentalists, and he did so in part by writing interesting and challenging solos for them in his early symphonies.
Prince Nikolaus's orchestra had included a large horn section (four players) earlier in the 1760s, but one horn player, Franz Reiner, left in 1763 and was not replaced. A further loss is reported in the a letter by Haydn dated 23 January 1765 (the earliest preserved letter of the composer). This informs the Prince of the death of a horn player named Knoblauch. Haydn suggested a replacement, but his suggestion was not accepted. The same letter serves an illustration of Haydn's role as lobbyist for his men (see Papa Haydn): he requests that the Prince provide a fringe benefit for the musicians by covering the cost of their medications. This too was (temporarily) turned down.
Prince Nikolaus brought the horn section back to full strength in May 1765, when hornists Franz Stamitz and Joseph Dietzl were engaged to fill the missing places. The "Hornsignal" Symphony evidently was written to celebrate this event. (Other four-horn symphonies from roughly the same time are No. 13, No. 39, and the misnumbered No. 72.)
The exact date of the symphony is not known, other than the year. However, the symphony must have been premiered no earlier than May (since that is when Stamitz and Dietzl arrived) and before September 13, 1765. The latter date is known since the symphony includes a flute part, and the flautist (Franz Siegl) was dismissed on this date for having carelessly started a fire while shooting birds; it was only the following year that Haydn was able to persuade his patron to reinstate Siegl.