We derive the exact expression for the weights of the Hodrick-Prescott (HP) filter in finite sample without making any assumptions about the statistical properties of the time series. We use the results to give insights about the properties of the HP filter and to build a fast algorithm with computational improvements by a factor of up to three times in samples typical in economics