Exemplo n.º 1
0
 def main_fundamentals(stocks, start_year):
   start_date = DateUtils.getDateStr(start_year, 1, 2)
   end_date = DateUtils.getDateStr(start_year, 1, 3)
   for stock in stocks:
     dt = YahooStockTable.make_data_table(stock, start_date, end_date)
     print dt.header
     print dt.table
   return ''
Exemplo n.º 2
0
  def makeMonthlyTables(ticker_symbol, year):
     """Provide monthly (12 months) for a particular year for a particular
        ticker symbol.

     Ex: GOOG, 2012 -> tables for Jan 2012, Feb 2012, ..., Dec 2012     
     """
     months = [month for month in range(1, 13)]
     monthly_tables = []
     for month in months:
       # Assume we go from the 1st of the month, and then 30 days later.
       start_date = DateUtils.getDateStr(year, month, 1)
       end_date = DateUtils.getEndDate(start_date, 30)
       tbl = YahooStockTable.make_data_table(ticker_symbol, start_date, end_date)
       monthly_tables.append(tbl)
     return monthly_tables  
Exemplo n.º 3
0
 def main(stocks, year):
   start_date = DateUtils.getDateStr(year, 1, 1)
   end_date = DateUtils.getDateStr(year, 12, 30)
   return Question5.main_correlations(stocks, start_date, end_date)
Exemplo n.º 4
0
    for stock in stocks:
      tbl = YahooStockTable.make_data_table(stock, start_date, end_date)
      #print tbl.table
      try:
        infoTuple = self.getInformation(tbl)
      except Exception:
        #print tbl.table
        continue
      sInfo = {}
      sInfo['info'] = infoTuple
      sInfo['stock_name'] = stock       
      stockInfos.append(sInfo)
    stockInfos.sort(compareF)
    return stockInfos

if __name__ == '__main__':
  year = int(sys.argv[1])
  start_date = DateUtils.getDateStr(year, 1, 1)
  end_date = DateUtils.getDateStr(year, 12, 30)
  stocks = nasdaqtrader.TickerSymbols.getNasdaqMap().values()
  stocks = stocks[0:10]
  #print stocks
  q2 = Question2(start_date, end_date)
  #print time.time()
  ranked_stocks = q2.rank(stocks)
  for rstock in ranked_stocks:
    line1 = rstock['stock_name'] + ' ' + str(rstock['info']['total_return']) + ' ' + str(rstock['info']['closing_range'])
    line2 = '(' + str(rstock['info']['date_range']) + ')'
    #print line1 + line2
  #print time.time()
Exemplo n.º 5
0
 def makeYearlyTable(ticker_symbol, year):
   """Provide year data."""
   start_date = DateUtils.getDateStr(year, 1, 1)
   end_date = DateUtils.getDateStr(year, 12, 30)
   tbl = YahooStockTable.make_data_table(ticker_symbol, start_date, end_date)    
   return tbl
Exemplo n.º 6
0
        source = item.select('.a-pic-play')[0].get('href')
        data = {'date': date, 'title': title, 'source': source}
        result.append(data)
    return result


if __name__ == '__main__':
    url = 'http://list.hunantv.com/album/18.html'
    while True:

        for item in get_data(url):
            print item['title']
            print item['source']
            print item['date']
            publish_date = item['date'].date()
            print publish_date >= DateUtils.date()
            if publish_date >= DateUtils.date():
                MailUtils.send_mail('*****@*****.**', '您好,你定制的{0}即将开始播放'.format('天天向上'),
                                    '''
                                    <!DOCTYPE html>
                                    <html lang="en">
                                    <head>
                                    <meta charset="UTF-8">
                                    </head>
                                    <body>
                                    <center><h3>第{0}期{1}</h3></center>
                                    <center><a href="{2}">快点我查看吧!</a></center>
                                    </body>
                                    </html>
                                    '''.format(publish_date, item['title'].encode('utf-8'), item['source']))
            break
Exemplo n.º 7
0
 def runTests():
     Tests.assertEquals([1.0, 0.5], StockUtils.getPercentChanges([5, 10, 15]))
     Tests.assertEquals([0.75], [StockUtils.getAverageReturn([5, 10, 15])])
     Tests.assertEquals([-0.67], [StockUtils.getTotalReturn([15, 10, 5])])
     Tests.assertStrEquals(["20120220"], [DateUtils.getEndDate("20120215", 5)])
     Tests.assertStrEquals(["20121231"], [DateUtils.getDateStr(2012, 12, 31)])