13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

64

Pandas is used to obtain the raw pricing information and convert it into a returns stream

suitable for analysis with the stochastic vol model. This is achieved by taking the ratio of the

current days adjusted close to the previous days adjusted close. These percentage returns values

are then transformed with the natural logarithm function to produce the log returns.

def obtain_plot_amazon_prices_dataframe(start_date, end_date):

"""

Download, calculate and plot the AMZN logarithmic returns.

"""

print("Downloading and plotting AMZN log returns...")

amzn = pdr.get_data_yahoo("AMZN", start_date, end_date)

amzn["returns"] = amzn["Adj Close"]/amzn["Adj Close"].shift(1)

amzn.dropna(inplace=True)

amzn["log_returns"] = np.log(amzn["returns"])

amzn["log_returns"].plot(linewidth=0.5)

plt.ylabel("AMZN daily percentage returns")

plt.show()

return amzn

The returns are plotted in Figure 6.3.

Figure 6.3: AMZN returns over a ten year period–2006 to 2016.

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

Saved successfully!

Ooh no, something went wrong!