Python for Finance: Analyze Big Financial Data

(Elle) #1
because the respective graphical results are easier to understand and interpret (they are visually “more

appealing”). However, for real-world financial applications you would instead rely on relative return data.

Using the mean alpha and beta values, we can illustrate how the regression is updated


over time. Figure 11-27 again shows the data points as a scatter plot. In addition, the 39


regression lines resulting from the mean alpha and beta values are displayed. It is


obvious that updating over time increases the regression fit (for the current/most recent


data) tremendously — in other words, every time period needs its own regression:


In  [ 50 ]: plt.figure(figsize=( 10 ,    5 ))
plt.scatter(data[‘GDX’], data[‘GLD’], c=mpl_dates, marker=‘o’)
plt.colorbar(ticks=mpl.dates.DayLocator(interval= 250 ),
format=mpl.dates.DateFormatter(’%d %b %y’))
plt.grid(True)
plt.xlabel(‘GDX’)
plt.ylabel(‘GLD’)
x = np.linspace(min(data[‘GDX’]), max(data[‘GDX’]))
for i in range( 39 ):
alpha_rw = np.mean(trace_rw[‘alpha’].T[i])
beta_rw = np.mean(trace_rw[‘beta’].T[i])
plt.plot(x, alpha_rw + beta_rw * x, color=plt.cm.jet( 256 * i / 39 ))

Figure 11-27. Scatter plot with time-dependent regression lines (updated estimates)

This concludes the section on Bayesian regression, which shows that Python offers with


PyMC3 a powerful library to implement different approaches from Bayesian statistics.


Bayesian regression in particular is a tool that has become quite popular and important


recently in quantitative finance.

Free download pdf