To increase max hp of a unit, you must add an item ability to it that has a negative hp modifier. When the ability is removed, the unit gains max hp. Vice versa for reducing max hp. Use positive values for that.
Then create copies of both abilities.
Ability 1 has -1 hp
ability 2 has -2 hp
.. -4, -8, -16 , -32 , -64 , -128 , -256 , -512 , -1024...
Then you calculate the % increase. After that, run the health increase number through a loop that first finds the highest hp gain amount that is lower than the hp amount that should be added. Add and remove the ability from the unit. Reduce the health increase number. Then check whether you still need to add hp.
For example if a unit has 1000 health, and the bonus is 50%. The unit should gain 500 hp. Loop through the abilities and you'll find that the first bonus that is lower than 500 is 256. Add/remove the 256 ability for the unit. Then 500-256=244 of health that's still missing. 128 is the next value to be added/remove since it's lower than 244. Then 244-128 =116. 116-64=52. 52-32=20. 20-16=4. 4-4=0.
So you have to add/remove the following abilities:
256, 128, 64, 32 , 16 , 4.
After that you have gained 500 hp. When you want to remove the bonus, add positive value abilities and remove them.
Health is in reals so you may end up with a value of 1>x>0. Ignore that.
There's a system for this in the spell section I believe.
For armor, devotion aura has data field "percent bonus". Set it to true. Maybe you can use that.