Context : With the discovery of a planetary system around the ultracool dwarf TRAPPIST-1 , there has been a surge of interest in such stars as potential planet hosts . Planetary systems around ultracool dwarfs represent our best chance of characterising temperate rocky-planet atmospheres with JWST . However , TRAPPIST-1 remains the only known system of its kind , and the occurrence rate of planets around ultracool dwarfs is still poorly constrained . Aims : We seek to perform a complete transit search on the ultracool dwarfs observed by NASA ’ s K2 mission , and use the results to constrain the occurrence rate of planets around these stars . Methods : We filter and characterise the sample of ultracool dwarfs observed by K2 , by fitting their spectral energy distributions , and using parallaxes from Gaia . We build an automatic pipeline to perform photometry , detrend the lightcurves , and search for transit signals . Using extensive injection-recovery tests of our pipeline , we compute the detection sensitivity of our search , and thus the completeness of our sample . We infer the planetary occurrence rates within a hierarchical Bayesian model ( HBM ) to treat uncertain planetary parameters . With the occurrence rate parametrised by a step-wise function , we show a convenient way to directly marginalise over the second level of our HBM ( the planetary parameters ) . Our method is applicable generally and can greatly speed up inference with larger catalogues of detected planets . Results : We detect one planet in our sample of 702 ultracool dwarfs : a previously-validated mini-Neptune . We thus infer a mini-Neptune ( 2 - 4 \si { \Re } ) occurrence rate of \eta = 0.20 ^ { +0.16 } _ { -0.11 } within orbital periods of 1 - 20 days . For super-Earths ( 1 - 2 \si { \Re } ) and ice/gas giants ( 4 - 6 \si { \Re } ) within 1 - 20 days , we place 95 % credible intervals of \eta < 1.14 and \eta < 0.29 , respectively . If TRAPPIST-1-like systems were ubiquitous , we would have had a \sim 96 \% chance of finding at least one . Conclusions :