Abstract We investigate the optimal performance of the quantum Otto engine and refrigeration cycles of a time-dependent harmonic oscillator under a trade-off figure of merit for both adiabatic and nonadiabatic (sudden-switch) frequency modulations. For heat engines (refrigerators), the chosen trade-off figure of merit is an objective function defined by the product of efficiency (coefficient of performance) and work output (cooling load), thus representing a compromise between them. We obtain analytical expressions for the efficiency and coefficient of performance of the harmonic Otto cycle for the optimal performance of the thermal machine in various operational regimes. Particularly, in the sudden-switch regime, we discuss the implications of the nonadiabatic driving on the performance of the thermal machine under consideration and obtain analytic expressions for the maximum achievable efficiency and coefficient of performance of the harmonic Otto thermal machine. Particularly, we show that the quantum harmonic Otto cycle driven by sudden-switch protocol cannot work as a heat engine or refrigerator in the low-temperature limit. Finally, we show that in the high-temperature limit, the frictional effects give rise to a richer structure of the phase diagram of the harmonic Otto cycle. We identify the parametric regime for the operation of the Otto cycle as a heat engine, refrigerator, accelerator, and heater.