<jupyter_start><jupyter_text>Data manipulation and visualisation with stock data amd creating OHLC chart.<jupyter_code>import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')

df = pd.read_csv('tsla.csv', parse_dates=True, index_col=0)
# 100 day rolling moving average. So this will take the current price, and the prices from the
#past 99 days, add them up, divide by 100, and there's your current 100-day moving average.

df['100ma'] = df['Adj Close'].rolling(window=100,min_periods=0).mean()
print(df.head())
# Plotting graph 

ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1,sharex=ax1)

ax1.plot(df.index, df['Adj Close'])
ax1.plot(df.index, df['100ma'])
ax2.bar(df.index, df['Volume'])

plt.show()<jupyter_output><empty_output><jupyter_text>OHLC chart - candlesticks.<jupyter_code>import mplfinance as mpf
from mplfinance.original_flavor import candlestick_ohlc
import matplotlib.dates as mdates
df_ohlc = df['Adj Close'].resample('10D').ohlc()
df_volume = df['Volume'].resample('10D').sum()
print(df_ohlc.head())
df_ohlc = df_ohlc.reset_index()
df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num)
fig = plt.figure()
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1,sharex=ax1)
ax1.xaxis_date()

candlestick_ohlc(ax1, df_ohlc.values, width=2, colorup='g')

ax2.fill_between(df_volume.index.map(mdates.date2num),df_volume.values,0)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15299198025909932, 'fraction_numerical': 0.0431832202344232, 'mean_word_length': 7.11, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '194608', 'license': 'MIT', 'n_tokens_mistral': 666, 'n_tokens_neox': 635, 'n_words': 134, 'path': 'Python_in_finance3.ipynb', 'repo_name': 'jairajc/Python-in-Finance', 'size': '1621'}