13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

69

plt.xlabel(’Time’)

plt.ylabel(’Log Volatility’)

plt.show()

print("Plotting the absolute returns overlaid with vol...")

plt.plot(np.abs(np.exp(log_returns))-1.0, linewidth=0.5)

plt.plot(np.exp(trace[s][::k].T), ’r’, alpha=opacity)

plt.xlabel("Trading Days")

plt.ylabel("Absolute Returns/Volatility")

plt.show()

if __name__ == "__main__":

# State the starting and ending dates of the AMZN returns

start_date = datetime.datetime(2006, 1, 1)

end_date = datetime.datetime(2015, 12, 31)

# Obtain and plot the logarithmic returns of Amazon prices

amzn_df = obtain_plot_amazon_prices_dataframe(start_date, end_date)

log_returns = np.array(amzn_df["log_returns"])

# Configure the stochastic volatility model and carry out

# MCMC sampling using NUTS, plotting the trace

samples = 2000

configure_sample_stoch_vol_model(log_returns, samples)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!