MulaiMulai sekarang secara gratis

Plot a return histogram

As a trader, it is important to analyze an asset's return profile, such as ranges of price changes, return distributions, etc. Over the years, Tesla fans and short sellers have been either betting on or against Tesla stocks aggressively, leading to volatile stock prices. You have some Tesla historical daily price data and want to verify this phenomenon.

The stock data has been preloaded in tsla_data, and matplotlib.pyplot has been imported as plt. Additional customizations to the plot such as a title and axis labels have already been provided for you.

Latihan ini adalah bagian dari kursus

Financial Trading in Python

Lihat Kursus

Petunjuk latihan

  • Calculate the daily percent change using the Close price and save it in a new column named daily_return.
  • Plot a histogram of daily_return, setting the bin size to 100.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Calculate daily returns
tsla_data['daily_return'] = tsla_data['____'].____() * 100

# Plot the histogram
tsla_data['____'].____(____, color='red')
plt.ylabel('Frequency')
plt.xlabel('Daily return')
plt.title('Daily return histogram')
plt.show()
Edit dan Jalankan Kode