Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added plotting functions and reversing return series data earlier

  • Loading branch information...
commit 2ceaf00ffeee31ac91e31203d4bb14f220f3270f 1 parent ed75c8e
commonlisp authored December 18, 2011

Showing 1 changed file with 14 additions and 5 deletions. Show diff stats Hide diff stats

  1. 19  correlations.py
19  correlations.py
@@ -43,23 +43,32 @@ def priceReturn(current, original):
43 43
 
44 44
 def returnSeries(config, sym):
45 45
   pd = yfpricedata(config, sym)
46  
-  sym0prices = map(lambda row: row.adj, pd)
  46
+  pd.reverse()
  47
+  sym0prices = array(map(lambda row: row.adj, pd))
47 48
   sym0dates = map(lambda row: row.date, pd)
  49
+  #print 'prices: ' + str(sym0prices)
48 50
   #print "Starting price: " + str(sym0prices[-1]) + " for day " + str(sym0dates[-1]) + " last price: " + str(sym0prices[0]) + " diff: " + str((sym0prices[0]-sym0prices[-1])/sym0prices[-1])
49  
-  sym0returns = map(lambda x: priceReturn(x,sym0prices[-1]), sym0prices)
50  
-  return sym0returns
  51
+  sym0returns = (sym0prices - sym0prices[0])/sym0prices[0]
  52
+  return zip(sym0dates, sym0returns)
51 53
 
52 54
 def portfolioIndex(syms, config=timeframe):
53 55
   portfolioData = array(map(lambda x: returnSeries(config, x), syms)).transpose()
54 56
   mktwgts = portfolioMktWeightings(syms)
55 57
   print 'mktwgts: ' + str(mktwgts)
56  
-  return dot(portfolioData, mktwgts)[ : : -1]
  58
+  dates, returns = portfolioData
  59
+  res = dot(returns, mktwgts)
  60
+  #print 'res : ' + str(res)
  61
+  return zip(map(lambda x:x[0], dates), res)
57 62
 
58  
-def plotTS(series):
  63
+def plotTSBar(series):
59 64
   nseries = series + 1
60 65
   plt.bar(arange(len(series)), nseries, width=1)
61 66
   plt.ylim(ymin=min(nseries))
62 67
 
  68
+def plotTS(series):
  69
+  dates, nseries = zip(*series)
  70
+  plt.plot_date(dates, array(nseries)+1, fmt='-')
  71
+  
63 72
 def monthsFromBusinessDate(d, months):
64 73
   monthago = d + relativedelta(months=-months)
65 74
   delta = timedelta((monthago.weekday() + 1) % 5)

0 notes on commit 2ceaf00

Please sign in to comment.
Something went wrong with that request. Please try again.