I don't have a formula.

But horsepower is calculated by timing the acceleration of a known amount of inertia from one rpm to another. (Work/time, lb ft/sec, or power)

Knowing engine rpm, torque can then be calculated.