<jupyter_start><jupyter_text>Volatility- Different ways to look at it- Here we will use: Average True Range (ATR) What is Volatility?- Volatility has a number of different meanings- We use it in relation to price movement- Can be thought as the equivalent as risk  Resourses- Volatility https://www.investopedia.com/terms/v/volatility.asp- Average True Range https://www.investopedia.com/terms/a/atr.asp- Matplotlib http://matplotlib.org (https://youtu.be/2ywUfs0rgtU)<jupyter_code>import numpy as np
import pandas_datareader as pdr
import datetime as dt
import pandas as pd
start = dt.datetime(2020, 1, 1)
data = pdr.get_data_yahoo("NFLX", start)
data.head()<jupyter_output><empty_output><jupyter_text>Formula$TR = \max[H − L, |H − C_P|, |L − C_P|]$$ATR = \frac{1}{n}\sum_{i=1}^{n} TR_i$- $TR_i$: A particular True Range- $n$: The time period employed- $H$: Current High- $L$: Current Low- $C_P$: Previous Close<jupyter_code>high_low = data['High'] - data['Low']
high_cp = np.abs(data['High'] - data['Close'].shift())
low_cp = np.abs(data['Low'] - data['Close'].shift())
df = pd.concat([high_low, high_cp, low_cp], axis=1)
true_range = np.max(df, axis=1)
average_true_range = true_range.rolling(14).mean()
average_true_range
true_range.rolling(14).sum()/14
import matplotlib.pyplot as plt
%matplotlib notebook
fig, ax = plt.subplots()
average_true_range.plot(ax=ax)
ax2 = data['Close'].plot(ax=ax, secondary_y=True, alpha=.3)
ax.set_ylabel("ATR")
ax2.set_ylabel("Price")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15456362425049966, 'fraction_numerical': 0.013990672884743505, 'mean_word_length': 5.858447488584475, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '233370', 'license': 'MIT', 'n_tokens_mistral': 578, 'n_tokens_neox': 552, 'n_words': 140, 'path': 'Python For Finance Risk And Return/02 - Volatitlity.ipynb', 'repo_name': 'shreejitverma/Data-Scientist', 'size': '1501'}