Utility
Solution
def utilityCAL(ret1,ret2,var1,var2,cov,A):
returns = [(1-x/100)*ret1+(x/100)*ret2 for x in range(0,201)]
variances = [(1-x/100)**2*var1+(x/100)**2*var2+2*(1-x/100)*(x/100)*cov for x in range(0,101)]
utility = [x-.5*A*y for x,y in zip(returns,variances)]
utility.reverse()
standardDevs = [x**.5 for x in variances]
allocations = [(1-x/100) for x in range(0,101)]
plt.plot(allocations,utility)
plt.xlabel("Amount in Asset 1")
plt.ylabel("Utility")
plt.show()
utilityCAL(.05,.12,.02,.04,.005,2)
utilityCAL(.05,.12,.02,.04,.005,5)
utilityCAL(.05,.12,.02,.04,.005,10)
As you can see, the utility curves look very different with different A. The first investor is best off investing in the risky asset because they are not risk averse, the last investor is the best off investing in a combination of the two assets with the lowest variance since they are very risk averse.
Source Code