By Christopher van Hoecke, Maxwell Margenot
https://www.quantopian.com/lectures/introduction-to-pandas
This lecture corresponds to the Introduction to Pandas lecture, which is part of the Quantopian lecture series. This homework expects you to rely heavily on the code presented in the corresponding lecture. Please copy and paste regularly from that lecture when starting to work on the problems, as trying to do them from scratch will likely be too difficult.
Part of the Quantopian Lecture Series:
# Useful Functions
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
l = np.random.randint(1,100, size=1000)
s = pd.Series(l)
## Your code goes here
s
.2017-02-20
.## Your code goes here
## Your code goes here
In the series s
, print all the values between 1 and 3.
## Your code goes here
## Your code goes here
## Your code goes here
symbol = "CMG"
start = "2012-01-01"
end = "2016-01-01"
prices = get_pricing(symbol, start_date=start, end_date=end, fields="price")
## Your code goes here
## Your code goes here
NaN
using the forward fill method. NaN
from the data.## Your code goes here
## Your code goes here
print "Summary Statistics"
## Your code goes here
data = get_pricing('GE', fields='open_price', start_date='2016-01-01', end_date='2017-01-01')
## Your code goes here
## Your code goes here
# Rolling mean
## Your code goes here
## Your code goes here
# Rolling Standard Deviation
## Your code goes here
## Your code goes here
l = {'fifth','fourth', 'third', 'second', 'first'}
dict_data = {'a' : [1, 2, 3, 4, 5], 'b' : ['L', 'K', 'J', 'M', 'Z'],'c' : np.random.normal(0, 1, 5)}
## Your code goes here
Good Numbers
and Bad Numbers
. 2016-01-01
.s1 = pd.Series([2, 3, 5, 7, 11, 13], name='prime')
s2 = pd.Series([1, 4, 6, 8, 9, 10], name='other')
## Your code goes here
## Your code goes here
## Your code goes here
symbol = ["XOM", "BP", "COP", "TOT"]
start = "2012-01-01"
end = "2016-01-01"
prices = get_pricing(symbol, start_date=start, end_date=end, fields="price")
if isinstance(symbol, list):
prices.columns = map(lambda x: x.symbol, prices.columns)
else:
prices.name = symbol
# Check Type of Data for these two.
prices.XOM.head()
prices.loc[:, 'XOM'].head()
## Your code goes here
## Your code goes here
## Your code goes here
prices
) to only print values where:nan
values ((BP > 30 and XOM < 100) or TOT is non-NaN
).# Filter the data for prices to only print out values where
# BP > 30
# XOM < 100
# BP > 30 AND XOM < 100
# The union of (BP > 30 AND XOM < 100) with TOT being non-nan
## Your code goes here
# Add a column for TSLA and drop the column for XOM
## Your code goes here
# Concatenate these dataframes
df_1 = get_pricing(['SPY', 'VXX'], start_date=start, end_date=end, fields='price')
df_2 = get_pricing(['MSFT', 'AAPL', 'GOOG'], start_date=start, end_date=end, fields='price')
## Your code goes here
# Fill GOOG missing data with 0
## Your code goes here
prices
DataFrame from above.# Print a summary of the 'prices' times series.
## Your code goes here
# Print the natural log returns of the first 10 values
## Your code goes here
# Print the Muliplicative returns
## Your code goes here
# Normlalize the returns and plot
## Your code goes here
# Rolling mean
## Your code goes here
# Rolling standard deviation
## Your code goes here
# Plotting
## Your code goes here
Congratulations on completing the Introduction to pandas exercises!
As you learn more about writing trading algorithms and the Quantopian platform, be sure to check out the daily Quantopian Contest, in which you can compete for a cash prize every day.
Start by going through the Writing a Contest Algorithm Tutorial.
This presentation is for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation for any security; nor does it constitute an offer to provide investment advisory or other services by Quantopian, Inc. ("Quantopian"). Nothing contained herein constitutes investment advice or offers any opinion with respect to the suitability of any security, and any views expressed herein should not be taken as advice to buy, sell, or hold any security or as an endorsement of any security or company. In preparing the information contained herein, Quantopian, Inc. has not taken into account the investment needs, objectives, and financial circumstances of any particular investor. Any views expressed and data illustrated herein were prepared based upon information, believed to be reliable, available to Quantopian, Inc. at the time of publication. Quantopian makes no guarantees as to their accuracy or completeness. All information is subject to change and may quickly become unreliable for various reasons, including changes in market conditions or economic circumstances.