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:
In [ ]:
# Useful Functions
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [ ]:
l = np.random.randint(1,100, size=1000)
s = pd.Series(l)
## Your code goes here
In [ ]:
## Your code goes here
## Your code goes here
In [ ]:
## Your code goes here
In [ ]:
## Your code goes here
## Your code goes here
In [ ]:
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
In [ ]:
## Your code goes here
In [ ]:
## Your code goes here
In [ ]:
## Your code goes here
In [ ]:
print "Summary Statistics"
## Your code goes here
In [ ]:
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
In [ ]:
# Rolling mean
## Your code goes here
## Your code goes here
In [ ]:
# Rolling Standard Deviation
## Your code goes here
## Your code goes here
In [ ]:
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
In [ ]:
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
In [ ]:
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()
In [ ]:
## Your code goes here
## Your code goes here
In [ ]:
## Your code goes here
prices
) to only print values where:nan
values ((BP > 30 and XOM < 100) or TOT is non-NaN
).
In [ ]:
# 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
In [ ]:
# Add a column for TSLA and drop the column for XOM
## Your code goes here
In [ ]:
# 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
In [ ]:
# Fill GOOG missing data with 0
## Your code goes here
prices
DataFrame from above.
In [ ]:
# Print a summary of the 'prices' times series.
## Your code goes here
In [ ]:
# Print the natural log returns of the first 10 values
## Your code goes here
In [ ]:
# Print the Muliplicative returns
## Your code goes here
In [ ]:
# Normlalize the returns and plot
## Your code goes here
In [ ]:
# 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.