绘制最佳拟合线股票

时间:2014-12-26 19:32:12

标签: matplotlib pandas plot line regression

到目前为止,我的课程将根据股票报价机用户输入的数据以及他们希望查看历史数据的天数从雅虎获取股票历史数据。

我想添加一条最合适的线(或线性回归线,我仍然真的很新),这将增加一条线,显示股票的走势。

任何帮助将不胜感激或链接将是伟大的:)

#import modules
import pandas as pd
from pandas import DataFrame, read_csv
import matplotlib.pyplot as plt
from pandas.io.data import DataReader
from datetime import date, timedelta

class stockGraph():
    #sets up what to graph
    def __init__(self, stock, goback):
        self.goback = goback
        self.stock = stock
        #subtracts amount user inputted to get how far back to get data
        self.d = date.today() - timedelta(days = self.goback)
        #uses pandas io Datareader to get historical stock daya from yahoo
        self.df_stock = DataReader(self.stock, 'yahoo', self.d)

        #shows top 5 of the datafram values
        print self.df_stock.head()

    def dispGraph(self):
        #plots df_stock 'Close' is Y axis and X axis is the index in this case Date
        self.df_stock['Close'].plot()
        #rotates label and makes the graph a more readable
        plt.xticks(rotation = 90)
        plt.tight_layout()
        #shows graph
        plt.show()

0 个答案:

没有答案