KEMBAR78
Reading and Plotting Stock Data Notes | PDF | Comma Separated Values | Computer Science
0% found this document useful (0 votes)
24 views2 pages

Reading and Plotting Stock Data Notes

This document outlines the use of Python for financial applications, emphasizing its speed and strong scientific libraries. It explains the structure of CSV files containing stock data and introduces the Pandas and Matplotlib libraries for data manipulation and plotting. Key functions for reading CSV files, displaying data, and creating plots are also provided, along with techniques for normalizing price data and customizing plot titles and axes.

Uploaded by

pr1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Reading and Plotting Stock Data Notes

This document outlines the use of Python for financial applications, emphasizing its speed and strong scientific libraries. It explains the structure of CSV files containing stock data and introduces the Pandas and Matplotlib libraries for data manipulation and plotting. Key functions for reading CSV files, displaying data, and creating plots are also provided, along with techniques for normalizing price data and customizing plot titles and axes.

Uploaded by

pr1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lesson 01-01 - Reading and Plotting Stock Data

● Why use python for financial applications?


○ Allows you to quickly prototype algorithms
○ Provides computational speed
○ Features:
■ Strong scientific libraries
■ Strongly maintained
■ Fast if you can stick to metrics notation because lower levels are written
in C
● What a CSV file looks like
○ CSV - Comma Separated Values (plain text files)
○ Most CSV files have
■ Header Line
■ Rows of Data
● In a CSV of stock data, you would see
○ Date/Time
○ Open Price
○ High Price
○ Low Price
○ Closing Price
■ Actual price that was reported at the exchange when the stock closed for
that day
○ Volume
○ Adjusted Closing Price
■ Number that the data provider generates for us (adjusted for stocks,
splits, and dividend payments)
● Pandas - python library used to read, manipulate, and plot data
○ Dataframes are tables in pandas and a series is a column
○ Import statement to import pandas = import pandas as pd)
■ Use pd so that you don’t have to keep writing out pandas
○ Reading CSV files = pd.read_csv(“<name of csv>”)
○ Print out first n rows in a data frame called df = df.head(n)
○ Print out last n rows in a data frame called df = df.tail(n)
○ Print rows between index x and y = df[x:y+1]
○ Compute max value in column ‘Close’ = df[‘Close’].max()
○ Compute mean value in column ‘Value’ = df[‘Value’].mean()
● Matplotlib - python library used to plot data
○ Import statement to import matplotlib = import matplotlib.pyplot as plt
■ Use plt so that you don’t have to keep writing out matplotlib.pyplot
○ Plot column ‘Adjusted Close’ from dataframe df = df[‘Adjusted Close’].plot()
○ Plot columns ‘Adjusted Close’ and ‘Close’ from dataframe df = df[[‘Adjusted
Close’, ‘Close’]].plot()
○ Show a plot = plt.show()
● The best way to normalize price data so that all prices start at 1.0 (normalize to 1) is df1
= df1/df1[0]
● Set a title and font size in a plot = df.plot(title = “title”, fontsize = 2)
● Add x and y axis (need a handler for the plot and the output of df.plot is the handler)
○ ax = df.plot(title = “title”, fontsize = 2)
■ Create object ax for axis
○ ax.set_xlabel(“Date”) and ax.set_ylabel(“Price”) will set x and y labels
■ set_xlabel and set_ylabel are functions of the object retrieved from df.plot

You might also like