0% found this document useful (0 votes)
31 views1 page

Homework 4

This homework assignment involves reading stock price data from a file into Pandas DataFrames for each stock, computing returns, and comparing returns between stocks. Students will create DataFrames for each stock's price data, add columns for the symbol, logarithmic price, returns calculated as the difference in logarithmic price between each time step, and convert the time column from seconds to a time format. They will also graph the price series for each stock. The grading will check that the script runs correctly on a separate stock data file and produces accurate results.

Uploaded by

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

Homework 4

This homework assignment involves reading stock price data from a file into Pandas DataFrames for each stock, computing returns, and comparing returns between stocks. Students will create DataFrames for each stock's price data, add columns for the symbol, logarithmic price, returns calculated as the difference in logarithmic price between each time step, and convert the time column from seconds to a time format. They will also graph the price series for each stock. The grading will check that the script runs correctly on a separate stock data file and produces accurate results.

Uploaded by

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

Homework 4

Pandas and stock price paths


Due September 22nd by 11:59 PM
Submit assignments as last_first_hw4.py

Summary:

In this assignment you will create a python script that reads through a file of stock
data, compute returns, and compare the returns between stocks.

New programming elements introduced in this assignment:


- Working with Pandas to hold data
- Video introduction by Wes McKinney, the original creator of Pandas

Notation for financial mathematics


- Denote the spot price and logarithmic price as 𝑆𝑡 and 𝑋𝑡 = log⁡(𝑆𝑡 ), respectively
▪ Logarithmic return at time 𝑡 is then defined as 𝑟𝑡 = 𝑋𝑡 − 𝑋𝑡−1
- Denote continuous time as 𝑡 ∈ [0, 𝑇]
- Denote the discretization of 𝑇 into a grid of 𝑛 ∈ [0, 𝑁] steps (indexes) as 𝑡𝑛
𝑇
▪ The step size is then Δ𝑡 =
𝑁
▪ The time of the initial observation occurs at 𝑛 = 0, i.e. 𝑡 = 𝑡0.
▪ In our setting, 𝑇 = 23400, 𝑁 = 4680, and Δ𝑡 = 5

Homework Instructions:

Using the two files on canvas: hw4_start.py and hw4_stockClass.py.


1. Read the Feb 1 stock data file located on Canvas (Feb 5 WIP).
2. After reading the data, create a Pandas DataFrame for each stock:
DFname = pd.DataFrame(symDict[“ticker”].Xn,columns=[‘seconds’, ‘S’)

3. For each stock DataFrame, create the following columns (aka pd.Series):
a. Symbol: DFname['symbol'] = 'TSLA'
b. X: DFname[X] = 'TSLA'
c. Returns: DFname['return'] = DFname.X - DFname.X.shift(1)
d. Time: DFname['time'] = pd.to_time(DFname['seconds'],unit='s')
or DFname['time'] = pd.to_time(DFname['seconds'],unit='s').dt.time

4. For each stock, graph the price series:


DFname.plot(x=’time’,y=’S’)

Grading Process

I will award points according the rubric in the syllabus. To determine whether the script
is correct and efficient, the program will be run on a separate stock-day file. The script, if
done correctly, will report accurate results for a random stock day file.
If you are unable to complete all the tasks above, at a minimum make sure your script can
run and produce some output. A script that doesn’t run receives the least amount of points.

You might also like