# Raising a Polynomial to the Nth Power?

Hi all,

I’m currently using Julia to perform utility optimization on an n-period model with one stock implementing a buy-and-hold strategy. I want to generalize my program to find the optimal number of shares for any general utility function U(x) of the form

U(x) = 1/\beta * x^\beta


Where x represents the terminal capital at time n. I’m using the PolynomialRoots packages to find the roots of the expected value of U(x) (E[U(x)], x is of type Polynomial), but I’m running into an issue where I can’t raise the Polynomial type to a power. I was able to work around this when using specific integer values (just by doing x * x * x instead of x^3, etc.), but now that I want to generalize it I’m stuck on how to do it for non-integer values like 1/2, 1/3, etc. Ideally, I would be able to do this for any rational value of \beta.

Any help/tips would be much appreciated! Thanks for your time.

Integer exponents should work as-is with the Polynomials package:

julia> using Polynomials

julia> Poly([1,0,3,4])
Poly(1 + 3*x^2 + 4*x^3)

julia> Poly([1,0,3,4])^6
Poly(1 + 18*x^2 + 24*x^3 + 135*x^4 + 360*x^5 + 780*x^6 + 2160*x^7 + 4095*x^8 + 7760*x^9 + 14418*x^10 + 21240*x^11 + 30489*x^12 + 40392*x^13 + 42480*x^14 + 40704*x^15 + 34560*x^16 + 18432*x^17 + 4096*x^18)


I don’t understand what you mean by computing non-integer powers. Polynomials raised to fractional powers are generally no longer polynomials. You’ll need to reformulate your problem a bit in order to exploit fast root-finding procedures, I’m guessing; I’m not completely clear on what you are doing, but maybe you can reformulate your problem to put it back in terms of positive integer powers of your polynomial.

2 Likes

Can’t you just evaluate the polynomial, obtain the x, and raise that to a power to calculate U? This would, of course, require a general optimization algorithm like (L)BGFS in Optim.jl, but if your problem is well-behaved it should be fine.