Ejemplo n.º 1
0
def draw_viz(t1, t2):
    data_store = sds()
    delta = datetime.timedelta(days=1)

    t1_data = []
    t2_data = []
    dates = []

    d_cursor = data_store.get_company_data(t1)
    for d in d_cursor:
        t1_data.append(d["Adj Clos"])
        dates.append(d["date"])
    d_cursor = data_store.get_company_data(t2)
    for d in d_cursor:
        t2_data.append(d["Adj Clos"])
    print len(t1_data), len(t2_data)
    p, sprd, beta = fc.get_adf(t1, t2, spread=True)
    dates = mpl.dates.date2num(dates)
    p1 = plt.plot_date(dates, sprd, "b-.", label="Sprd")
    p2 = plt.plot_date(dates, t1_data, "g-.", label=t1)
    p3 = plt.plot_date(dates, t2_data, "r-.", label=t2)
    plt.grid(True)
    plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0)

    def add_vert_line(event):
        plt.avspan(event.xdata, event.xdata, ls="p-")

    print "Beta: %f" % beta
    plt.show()
Ejemplo n.º 2
0
def draw_viz(t1, t2):
    data_store = sds()
    delta = datetime.timedelta(days=1)

    t1_data = []
    t2_data = []
    dates = []

    d_cursor = data_store.get_company_data(t1)
    for d in d_cursor:
        t1_data.append(d['Adj Clos'])
        dates.append(d['date'])
    d_cursor = data_store.get_company_data(t2)
    for d in d_cursor:
        t2_data.append(d['Adj Clos'])
    print len(t1_data), len(t2_data)
    p, sprd, beta = fc.get_adf(t1, t2, spread=True)
    dates = mpl.dates.date2num(dates)
    p1 = plt.plot_date(dates, sprd, 'b-.', label='Sprd')
    p2 = plt.plot_date(dates, t1_data, 'g-.', label=t1)
    p3 = plt.plot_date(dates, t2_data, 'r-.', label=t2)
    plt.grid(True)
    plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

    def add_vert_line(event):
        plt.avspan(event.xdata, event.xdata, ls='p-')

    print 'Beta: %f' % beta
    plt.show()
Ejemplo n.º 3
0
def draw_plots_for_features(ticker, features):
  results = {}
  data_store = sds()
  delta = datetime.timedelta(days=1)
  
  for feature in features:
    results[feature] = list()
  data = data_store.get_company_data(ticker)
  dates = []
  for d in data:
    dates.append(d['date'])
    for f in features:
      try:
        results[f].append(d[f])
      except:
        pass
  
  dates = matplotlib.dates.date2num(dates)
  for i in range(len(features)):
    print features[i]
    plt.subplot(int('%d1%d' % (len(features), i+1)))
    print len(dates), len(results[features[i]])
    plt.plot_date(dates ,results[features[i]], 'r-.')
  plt.grid(True)
  plt.show()