Python for Finance: Analyze Big Financial Data
In [ 10 ]: plt.plot(x, f(x), ‘b’, label=‘f(x)’) plt.plot(x, ry, ‘r.’, label=‘regression’) plt.legend(loc= 0 ) plt.grid(T ...
In [ 17 ]: plt.plot(x, f(x), ‘b’, label=‘f(x)’) plt.plot(x, ry, ‘r.’, label=‘regression’) plt.legend(loc= 0 ) plt.grid(T ...
In [ 21 ]: np.sum((f(x) - ry) ** 2 ) / len(x) Out[21]: 2.2749084503102031e-31 In fact, the minimization rou ...
Out[27]: [ 4.09 0.5 1.48 -1.85 1.65 4.51 -5.7 1.83 4.42 -4.2 ] ...
ax.set_zlabel(‘f(x, y)’) fig.colorbar(surf, shrink=0.5, aspect= 5 ) Figure 9-9. Function with two parameters To get ...
f5 = a[ 5 ] * np.sin(x) f4 = a[ 4 ] * y ** 2 f3 = a[ 3 ] * x ** 2 f2 = a[ 2 ] * y f1 = a[ 1 ] ...
approach also works in general with quadratic and even linear splines. First, the importing of the respecti ...
ext Behavior if x not in knot sequence (0 extrapolate, 1 return 0, 2 raise ValueError) Applied to ...
Figure 9-12. Example plot (detail) with linear interpolation Therefore, let us repeat the complete exercise, ...
Convex Optimization In finance and economics, convex optimization plays an important role. Examples are the cali ...
In [ 58 ]: def fo((x, y)): z = np.sin(x) + 0.05 * x ** 2 + np.sin(y) + 0.05 * y ** 2 if outpu ...
In [ 62 ]: output = True opt2 = spo.fmin(fo, opt1, xtol=0.001, ftol=0.001, maxiter= 15 , maxfun= 20 ) opt2 Out[6 ...
Equation 9-2. Expected utility maximizing problem Putting in all numerical assumptions, we get the problem in ...
def Eu((s, b)): return -(0.5 * sqrt(s * 15 + b * 5 ) + 0.5 * sqrt(s * 5 + b * 12 )) # ...
Integration Especially when it comes to valuation and option pricing, integration is an important mathematical ...
Figure 9-15. Example function with integral area Numerical Integration The integrate sublibrary contains ...
In [ 81 ]: for i in range( 1 , 20 ): np.random.seed( 1000 ) x = np.random.random(i 10 ) (b - a) + a print ...
Symbolic Computation The previous sections are mainly concerned with numerical computation. This secti ...
We can not go into details here, but SymPy also provides many other useful mathematical functions — for e ...
| (0.5*x + sin(x)) dx | ...
«
7
8
9
10
11
12
13
14
15
16
»
Free download pdf