示例#1
0
def launchBloombergMenu():

    print "Enter the path to the csv data file"
    print 'For example, if the file is called exampleData.csv, and it is located on your desktop,'
    print 'Type: ~/Desktop/exampleData.csv'

    data_file = raw_input()
    print data_file

    global bloomberg
    bloomberg = Bloomberg()

    bloomberg.initializeData(data_file)

    print 'Select an option:'
    print "1. Growth of a Dollar"
    print "2. Benchmarking"
    print "3. Exit"

    continueProgram = True

    while continueProgram == True:
        userChoice = input("What would you like to do? ")
        if userChoice == 1:
            launchGrowthMenu()
            break

        elif userChoice == 2:
            launchBenchmarkingMenu()
            break
        else:
            continueProgram = False
            break
示例#2
0
def launchBloombergMenu():

    print "Enter the path to the csv data file"
    print 'For example, if the file is called exampleData.csv, and it is located on your desktop,'
    print 'Type: ~/Desktop/exampleData.csv'

    data_file = raw_input()
    print data_file

    global bloomberg
    bloomberg = Bloomberg()

    bloomberg.initializeData(data_file)

    print 'Select an option:'
    print "1. Growth of a Dollar"
    print "2. Benchmarking"
    print "3. Exit"

    continueProgram = True

    while continueProgram == True:
        userChoice = input("What would you like to do? ")
        if userChoice == 1:
            launchGrowthMenu()
            break
                
        elif userChoice == 2:
            launchBenchmarkingMenu()
            break
        else:
            continueProgram = False
            break
示例#3
0
def crawling(request):

   article_dict = {}

   if request.POST:
        subject = request.POST["subject"]
        date_range = request.POST['date_range']
        source = request.POST['source']
        articles = []
        address = ""
        if source == 'Bloomberg':
            temp = datetime.utcnow().strftime("%Y-%m-%d") + 'T' + datetime.utcnow().strftime("%H:%M:%S.%f")
            end_date = temp[0:len(temp) - 3] + 'Z'
            blm = Bloomberg(subject, date_range, end_date)
            articles, address = blm.getNews()

        elif source == 'Reuters':
            if date_range == "-1d":
                rts = Reuters(subject, 'pastDay')
                articles, address = rts.get_news()
            elif date_range == "-1w":
                rts = Reuters(subject, 'pastWeek')
                articles, address = rts.get_news()
            elif date_range == "-1m":
                rts = Reuters(subject, 'pastMonth')
                articles, address = rts.get_news()

        elif source == 'Guardian':
            end = date.today()
            if date_range == "-1d":
                time_delta = 1
                start = end - timedelta(time_delta)
                gdn = Guardian(subject, start, end, 1)
                articles, address = gdn.get_news()
            elif date_range == "-1w":
                time_delta = 7
                start = end - timedelta(time_delta)
                gdn = Guardian(subject, start, end, 1)
                articles, address = gdn.get_news()
            elif date_range == "-1m":
                time_delta = 30
                start = end - timedelta(time_delta)
                gdn = Guardian(subject, start, end, 1)
                articles, address = gdn.get_news()


        for article in articles:
            title = BeautifulSoup(article['title']).text
            article_dict[title] = article['content']

        request.session['address'] = address
        request.session['subject'] = subject
        request.session.set_expiry(300)
   return render(request, "crawling.html", {'news': article_dict})
示例#4
0
 def __init__(self, path="data/bbg_data.h5", read_only=True):
     self.read_only = read_only
     self.path = path
     self.bbg = Bloomberg()
     self.hdfstore = pd.HDFStore(path,
                                 mode='r' if read_only else 'a',
                                 compression=0,
                                 complib='blosc')
示例#5
0
def index(request):
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    fig_dir = os.path.join(BASE_DIR, "static_in_pro", "our_static")
    def word_in_text(word, text):
        word = word.lower()
        text = text.lower()
        match = re.search(word, text)
        if match:
            return True
        return False

    ## Extracting links for the tutorials
    def extract_link(text):
        regex = r'http://www\.reuters\.com/articles/[\w]+'
        match = re.search(regex, text)
        if match:
            return match.group()
        return ''

    text_ls = []
    per = []
    org = []
    loc = []
    if (request.POST):
        subject = request.POST["subject"]
        date = request.POST['date']
        date_range = request.POST['range']
        blm = Bloomberg(subject, date_range, date)
        articles = blm.getNews()
        for article in articles:
            text_ls.append(article['content'])
        ner = NERClass(articles)
        total_list = ner.execute_ner()
        per, org, loc = ner.freq_entities(total_list)

    return render(request, "index.html", {"total": "Article Count: " + str(len(text_ls)),
                                          "data_text":"<br/><br/>".join(text_ls),
                                          "top_persons": per,
                                          "top_organizations": org,
                                          "top_locations": loc})
示例#6
0
def getRandomCompanyResponse():

    with open("bloomberg/companylist.csv") as csvfile:
        linereader = csv.reader(csvfile, delimiter=',')
        companies = []
        for row in linereader:
            companies.append(row[0])

        result = Bloomberg.getFieldValues(random.choice(companies),
                                          ["PX_LAST", "DS002", "DS004"])

        strResult = str(result['DS002']) + " last priced at: " + str(
            result['PX_LAST']) + " " + str(result['DS004'])
        return strResult
示例#7
0
def main():
    continueProgram = True
    bloomberg = Bloomberg()
    # What exactly does this line do?

    while continueProgram == True:
        print 'Welcome to the TimeSeriesComp program. Please choose from the menu below: ',
        print 'Select an option: \n1) Import data from Bloomberg \n2) Download data from Yahoo Finance API \n3) Quit'
        print ''
        userChoice = input("What would you like to do? ")
        if userChoice == 1:
            # Bloomberg data-scrub and push to next step
            #fileName = input('Please enter the name of the .csv file you would like to analyze: ')
            #print fileName

            launchBloombergMenu()
            break

        elif userChoice == 2:
            # Yahoo API stuff
            pass
        else:
            continueProgram = False
            break
def getSelectedCompanyResponse(company):
        result = Bloomberg.getFieldValues(company, ["PX_LAST", "DS002", "DS004"])

        strResult = str(result['DS002']) + " last priced at: " + str(result['PX_LAST']) + " " + str(result['DS004'])
        return strResult
示例#9
0
def main():
	bloomberg = Bloomberg()
	bloomberg.initializeData("exampleData.csv")

	print sorted(bloomberg.tickerObjects["SPX Index"].date_to_performance.items(), key=operator.itemgetter(0))
示例#10
0
from bloomberg import Bloomberg
import plotly.plotly as py
from plotly.graph_objs import *
import datetime

b = Bloomberg()
b.initializeData("exampleData.csv")

s_date = datetime.datetime(year=2014, month=1, day=12)
e_date = datetime.datetime(2014, 11, 28)

b.growthOfADollar("SPX Index", plot=False, start_date=s_date, end_date = e_date)

benchmark = [b.tickerObjects["SPX Index"]]
comparison_ticker = [b.tickerObjects["LYV US Equity"]]

b.benchmarking(benchmark, comparison_ticker)
示例#11
0
def respondToUser(request):
  from pprint import pprint
  pprint(request)
  smsStr = str(request.GET['Body']).upper()
  print request.GET['From']
  phoneNumber = str(request.GET['From'])
  print phoneNumber
  print smsStr

  splitStr = smsStr.split()
  print splitStr
  command = str(splitStr[0])
  print command

  if command == "YOSCRIBE":
    print "In yoscribe"
    name = str(splitStr[1])
    print name
    try:
      try:
        newUser = Yoscriber(yoname=name, phonenumber=phoneNumber)
        newUser.save()
      except Exception as e1:
        print e1
        try:
          respMessage = twiml.Response()
          respMessage.message("That username and number are in use or the database is down")
          return HttpResponse(respMessage)
          pass
        except Exception as e2:
          print e2
          return
      #TODO: add in an item to subscribe to, along with the data format required...

      respMessage = twiml.Response()
      respMessage.message("Yoscription successful! " + phoneNumber + ", Your Msg: " + smsStr +"")
      return HttpResponse(respMessage)
    except Exception as e3:
      print e3

  elif command == "RANDOM":
    print "In random"
    #data = RandomCompany.getRandomCompanyResponse()
    #sendText(phoneNumber, data) needs more parsing of the data
    #sendSMS(user, randomData)
    randomData = RandomCompany.getRandomCompanyResponse()
    respMessage = twiml.Response()
    respMessage.message(randomData)
    return HttpResponse(respMessage)

  elif command == "INFO":
    print "In info"
    name = smsStr[5:]
    try:
      chosenData = str(SelectedCompany.getSelectedCompanyResponse(name))
      print chosenData
      try:
        #Now we Yo to all other users who need it...
        stockYos = StockYoscription.objects.filter(stock=name)
        for scription in stockYos:
          yo_user(scription.user.yoname)

        respMessage = twiml.Response()
        respMessage.message(chosenData)
        return HttpResponse(respMessage)

      except Exception as e5:
        print e5
    except Exception as e4:
      print e4
      try:
        respMessage = twiml.Response()
        respMessage.message("The chosen data point, " + name + ", is not valid.")
        return HttpResponse(respMessage)
      except Exception as exep6:
        print exep6

  elif command == "STOCKSCRIBE":
    print "In stock subscription"
    stockName = str(splitStr[1])
    try:
      yoUser = Yoscriber.objects.get(phonenumber=phoneNumber)
      try:
        chosenData = str(SelectedCompany.getSelectedCompanyResponse(stockName))

        try:
          stockYo = StockYoscription.objects.get(user=yoUser)
          stockYo.stock = stockName
          stockYo.save()
        except Exception as ex4:
          print ex4
          stockYo = StockYoscription(user=yoUser, stock=stockName);
          stockYo.save()

        respMessage = twiml.Response()
        respMessage.message(chosenData)
        return HttpResponse(respMessage)

      except Exception as ex3:
        print ex3
        respMessage = twiml.Response()
        respMessage.message("That is not a valid stock. To verify, use: INFO <stock>")
        return HttpResponse(respMessage)

    except Exception as ex1:
      print ex1
      try:
        respMessage = twiml.Response()
        respMessage.message("User not subscribed. To register, send: YOSCRIBE <user>")
        return HttpResponse(respMessage)
      except Exception as ex2:
        print ex2

  elif command == "SEARCH":
    print "Returning current number of feilds set on query"
    stockName = str(splitStr[1])
    try:
      fields = Bloomberg.getFields(stockName)
      fields2 = ""
      for f in fields:
        fields2 += (f[0] + ": " + f[1] + " " + f[2] + "\n")
      try:
        respMessage = twiml.Response()
        respMessage.message(fields2)
        return HttpResponse(respMessage)
      except Exception as twilioE:
        print twilioE

    except Exception as e:
      print e

  elif command == "GET":
    print "GET FIELD TO USE"
    if not (splitStr and splitStr[1] and splitStr[2]):
      print "blargh"
      return
    stockName = str(splitStr[1])
    print stockName
    fieldsArr = [splitStr[2], "DS002"]
    print fieldsArr
    try:
      fieldVals = Bloomberg.getFieldValues(stockName, fieldsArr)
      print fieldVals
      if not (fieldsArr[0] in fieldVals):
        result = "No data exists for given field."
      else:
        result = str(fieldVals['DS002']) + " has " + str(fieldsArr[0]) + " of: " + str(fieldVals[fieldsArr[0]]) + " "
      print result
      try:
        respMessage = twiml.Response()
        respMessage.message(result)
        return HttpResponse(respMessage)
      except Exception as twilioE:
        print twilioE

    except Exception as e:
      print e

  elif command == "GUIDE":
    respMessage = twiml.Response()
    respMessage.message(helpText)
    return HttpResponse(respMessage)