Often we are more interested in the trend of a data sample than in detrending it. Still we can get the trend back easily after detrending. Let's do that for 1 year of price data for QQQ:
Download quotes : Write code that gets the close price and corresponding dates for QQQ.
today = date.today() start = (today.year - 1, today.month, today.day) quotes = quotes_historical_yahoo("QQQ", start, today) quotes = numpy.array(quotes) dates = quotes.T[0] qqq = quotes.T[4]
Detrend the signal: Detrend the signal.
y = scipy.signal.detrend(qqq)
Create locators: Create month and day locators for the dates.
Date formatter: Create a date formatter that creates a string of month name and year.
month_formatter = DateFormatter("%b %Y")
Figure and subplot: Create a figure and subplot.
fig = matplotlib.pyplot.figure() ax = fig.add_subplot(111)
Data and underlying trend: Plot the data and underlying trend by subtracting the detrended...