def post(self): ticker = self.request.get("ticker") peRatio = Common.parseFloat(self.request.get("peRatio")) pbRatio = Common.parseFloat(self.request.get("pbRatio")) # Find 'Stock' record for this 'ticker' st = Stock.query(Stock.ticker == ticker).get() if (st != None): price = st.price if (price == None): return if (peRatio == None): eps = None else: eps = round(price / peRatio, 2) if (pbRatio == None): bps = None else: bps = round(price / pbRatio, 2) st.eps = eps st.bps = bps st.put()
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Get latest Market Data q = MarketData.query().order(MarketData.entry_date).get() rf = q.Treasury10yrReturn rm = q.SP500Return # ticker, Beta, Number of Shares inputFile = open(os.path.join(os.path.dirname(__file__) + "/data", exchange + '_fundamentals_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') for row in inputReader: # Add the task to the default queue. taskqueue.add(url='/admin/UpdateStockFundamentals', params={'exchange': exchange, 'ticker': row[0], 'name': row[1], 'beta':Common.getEqFloat(row[2]), 'shares_os':Common.getEqMillions(row[3]), 'price':Common.getEqFloat(row[4]), 'eps':Common.getEqFloat(row[5]), 'rf':rf, 'rm':rm } ) inputFile.close() self.response.out.write("Fundamental data for Exchange=" + exchange + " in task queue.")
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Estimate data inputFile = open( os.path.join( os.path.dirname(__file__) + "/data", exchange + '_estimates_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') prevTicker = "-1" # ticker:year:estimate:shares_os: for row in inputReader: ticker = row[0] if (ticker != prevTicker): year = Common.CURRENT_YEAR prevTicker = ticker else: year = year + 1 niEst = Common.getEqFloat(row[2]) # If niEst is not defined, nothing can be done about this data if (row[2] == None): return shares_os = Common.getEqMillions(row[3]) # If shares_os is not defined, nothing can be done about this data if (shares_os == None): return # Add the task to the default queue. taskqueue.add(url='/admin/UpdateAnalystEstimatesForStock', params={ 'ticker': ticker, 'exchange': exchange, 'year': year, 'niEst': niEst, 'shares_os': shares_os }) inputFile.close() self.response.out.write("Analyst Estimate data for Exchange=" + exchange + " in task queue.")
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) vt = postDataDict['vt'] rc = postDataDict['rc'] # Get Current Date - 10days cutoffDate = datetime.datetime.now() - datetime.timedelta(days = 10) # Get data for last 10 days if (rc=='ALL'): q = AnalystRating.query(AnalystRating.date > cutoffDate).order(-AnalystRating.date) else: q = AnalystRating.query(AnalystRating.date > cutoffDate, AnalystRating.direction == rc).order(-AnalystRating.date) data = [] i = 0 for p in q.iter(): ticker = p.ticker # Get other data from Stock st = Stock.query(Stock.ticker == ticker).get() if (st != None): if (vt=='UV'): if (st.iValue<st.price): continue elif (vt=='OV'): if (st.iValue>st.price): continue data.append({'date': str(p.date), 'ticker':ticker, 'name':st.name, 'analyst': p.analyst, 'oldRating': p.oldRating, 'newRating': p.newRating, 'ivPrem': Common.xformNan(st.ivPrem), 'peRatio': Common.xformNan(st.peRatio), 'pbRatio': Common.xformNan(st.pbRatio) }) # JSON data self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {'data': data} ) )
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Estimate data inputFile = open(os.path.join(os.path.dirname(__file__) + "/data", exchange + '_estimates_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') prevTicker = "-1" # ticker:year:estimate:shares_os: for row in inputReader: ticker = row[0] if (ticker != prevTicker): year = Common.CURRENT_YEAR prevTicker = ticker else: year = year + 1 niEst = Common.getEqFloat(row[2]) # If niEst is not defined, nothing can be done about this data if (row[2] == None): return shares_os = Common.getEqMillions(row[3]) # If shares_os is not defined, nothing can be done about this data if (shares_os == None): return # Add the task to the default queue. taskqueue.add(url='/admin/UpdateAnalystEstimatesForStock', params={'ticker': ticker, 'exchange': exchange, 'year': year, 'niEst':niEst, 'shares_os':shares_os}) inputFile.close() self.response.out.write("Analyst Estimate data for Exchange=" + exchange + " in task queue.")
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) coe = Common.parseFloat(postDataDict['coe']) nbrOfShares = Common.parseFloat(postDataDict['nbrOfShares']) price = Common.parseFloat(postDataDict['price']) fcfListParam = postDataDict['fcfList'] fcfList = [] resultData = [] for i in range(0, Common.SHOW_PERIODS): fcf = Common.parseFloat(fcfListParam[i]) if (fcf == None or fcf == 0): resultData = getResultData("", "", nbrOfShares, "", "") self.response.out.write(json.dumps({'resultData': resultData})) return else: fcfList.append(fcf) divBase = 1 + (coe / 100) div = dfcfe = dfcfeTotal = 0 # Add terminal FCFE to the list div = pow(divBase, 0 - Common.COMPANY_LIFE) terminalFcfe = round(fcfList[Common.SHOW_PERIODS - 1] * (1 - div) / (coe / 100)) fcfList.append(terminalFcfe) for i in range(0, Common.SHOW_PERIODS + 1): div = pow(divBase, i + 1) dfcfe = round((fcfList[i] / div)) dfcfeTotal = dfcfeTotal + dfcfe # Calculate intrinsic value iValue = None if (nbrOfShares != 0): iValue = round(dfcfeTotal / nbrOfShares, 2) resultData = getResultData(terminalFcfe, dfcfeTotal, nbrOfShares, iValue, price) self.response.out.write(json.dumps({'resultData': resultData}))
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) coe = Common.parseFloat(postDataDict['coe']) nbrOfShares = Common.parseFloat(postDataDict['nbrOfShares']) price = Common.parseFloat(postDataDict['price']) fcfListParam = postDataDict['fcfList'] fcfList = [] resultData = [] for i in range(0, Common.SHOW_PERIODS): fcf = Common.parseFloat(fcfListParam[i]) if (fcf == None or fcf == 0): resultData = getResultData("", "", nbrOfShares, "", "") self.response.out.write(json.dumps({'resultData': resultData})) return else: fcfList.append(fcf) divBase = 1 + (coe/100); div = dfcfe = dfcfeTotal = 0 # Add terminal FCFE to the list div = pow(divBase, 0 - Common.COMPANY_LIFE); terminalFcfe = round(fcfList[Common.SHOW_PERIODS-1] * (1 - div) / (coe/100)) fcfList.append(terminalFcfe) for i in range(0, Common.SHOW_PERIODS+1): div = pow(divBase, i+1); dfcfe = round((fcfList[i] / div)); dfcfeTotal = dfcfeTotal + dfcfe; # Calculate intrinsic value iValue = None if (nbrOfShares != 0): iValue = round(dfcfeTotal/nbrOfShares, 2) resultData = getResultData(terminalFcfe, dfcfeTotal, nbrOfShares, iValue, price) self.response.out.write(json.dumps({'resultData': resultData}))
def get(self): inputFile = open( os.path.join( os.path.dirname(__file__) + "/data", 'earningSurprises_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') date = None for row in inputReader: ticker = row[0].upper() # Do it only once if (date == None): date = datetime.datetime.strptime(row[4], '%m/%d/%Y').date() # Check if the record already exists es = EarningSurprise.query( EarningSurprise.ticker == row[0], EarningSurprise.date == date, ).get() # if yes, this is a repeat file, abort if (es != None): self.response.out.write( "Earning Surprise file was already loaded.") return # Insert into EarningSurprise es = EarningSurprise(ticker=row[0].upper(), actual=Common.parseFloat(row[1]), estimate=Common.parseFloat(row[2]), percentSurprise=Common.parseFloat(row[3]), date=date, direction=row[5]) es.put() inputFile.close() self.response.out.write("Earning Surprises loaded.")
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Ticker, Year, Sales, NetIncome, Depreciation, CapEx, wcDelta, debtDelta inputFile = open(os.path.join(os.path.dirname(__file__) + "/data", exchange + '_financials_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') prevSales = None prevTicker = "-1" for row in inputReader: tickerVal = row[0].upper() #Ticker is changed if (tickerVal != prevTicker): prevTicker = tickerVal prevSales = None yearVal = int(row[1]) salesVal = Common.getEqMillions(row[2]) niVal = Common.getEqMillions(row[3]) depVal = Common.getEqMillions(row[4]) defTaxesVal = Common.getEqMillions(row[5]) otherVal = Common.getEqMillions(row[6]) # Marketwatch prints negative values for 'Increase in WC and CapEx' so it can add to NI for calculating FCF # TheVasp subtracts those values therefore negate marketwatch values capExVal = Common.getEqMillions(row[7]) if (capExVal != None): capExVal = 0 - float(capExVal) wcDeltaVal = Common.getEqMillions(row[8]) if (wcDeltaVal != None): wcDeltaVal = 0 - float(wcDeltaVal) # Add the task to the default queue. taskqueue.add(url='/admin/LoadStockFinancials', params={'tickerVal': tickerVal, 'yearVal': yearVal, 'salesVal': salesVal, 'prevSales': prevSales, 'niVal':niVal, 'depVal':depVal, 'defTaxesVal': defTaxesVal, 'otherVal': otherVal, 'capExVal':capExVal, 'wcDeltaVal':wcDeltaVal }) # Current Sales is 'prevSales' for next year prevSales = salesVal inputFile.close() self.response.out.write("Financial data for Exchange=" + exchange + " loaded.")
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Get latest Market Data q = MarketData.query().order(MarketData.entry_date).get() rf = q.Treasury10yrReturn rm = q.SP500Return # ticker, Beta, Number of Shares inputFile = open( os.path.join( os.path.dirname(__file__) + "/data", exchange + '_fundamentals_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') for row in inputReader: # Add the task to the default queue. taskqueue.add(url='/admin/UpdateStockFundamentals', params={ 'exchange': exchange, 'ticker': row[0], 'name': row[1], 'beta': Common.getEqFloat(row[2]), 'shares_os': Common.getEqMillions(row[3]), 'price': Common.getEqFloat(row[4]), 'eps': Common.getEqFloat(row[5]), 'rf': rf, 'rm': rm }) inputFile.close() self.response.out.write("Fundamental data for Exchange=" + exchange + " in task queue.")
def post(self): ticker = self.request.get("ticker") exchange = self.request.get("exchange") year = Common.parseInt(self.request.get("year")) niEst = Common.parseFloat(self.request.get("niEst")) shares_os = Common.parseFloat(self.request.get("shares_os")) # Find 'AnalystEstimate' record for this 'ticker' ae = AnalystEstimate.query(AnalystEstimate.ticker == ticker, AnalystEstimate.exchange == exchange, AnalystEstimate.year == year).get() # If AnalystEstimate does not exist, create a new record if (ae == None): ae = AnalystEstimate(ticker = ticker, exchange = exchange, year = year, ni = round((shares_os * niEst), 2) ) else: # Update data ae.ni = round((shares_os * niEst), 2) ae.put()
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) vt = postDataDict['vt'] # Get Current Date - 10days cutoffDate = datetime.datetime.now() - datetime.timedelta(days = 10) # Get data for last 10 days if (vt=='UV'): q = Stock.query(Stock.ivPrem > 0, Stock.ivPrem < 2).order(Stock.ivPrem) elif (vt=='OV'): q = Stock.query(Stock.ivPrem < 0, Stock.ivPrem > -1).order(-Stock.ivPrem) data = [] i = 0 for p in q.iter(): if (i > 99): break if (Common.xformNan(p.price) == '' or Common.xformNan(p.iValue) == ''): continue data.append({'ticker':p.ticker, 'name':p.name, 'price':p.price, 'iValue':p.iValue, 'ivPrem': p.ivPrem, 'peRatio': p.peRatio, 'pbRatio': p.pbRatio}) i = i + 1 # JSON data self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {'data': data} ) )
def post(self): ticker = self.request.get("ticker") exchange = self.request.get("exchange") year = Common.parseInt(self.request.get("year")) niEst = Common.parseFloat(self.request.get("niEst")) shares_os = Common.parseFloat(self.request.get("shares_os")) # Find 'AnalystEstimate' record for this 'ticker' ae = AnalystEstimate.query(AnalystEstimate.ticker == ticker, AnalystEstimate.exchange == exchange, AnalystEstimate.year == year).get() # If AnalystEstimate does not exist, create a new record if (ae == None): ae = AnalystEstimate(ticker=ticker, exchange=exchange, year=year, ni=round((shares_os * niEst), 2)) else: # Update data ae.ni = round((shares_os * niEst), 2) ae.put()
def get(self): inputFile = open(os.path.join(os.path.dirname(__file__) + "/data", 'earningSurprises_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') date = None for row in inputReader: ticker = row[0].upper() # Do it only once if (date == None): date = datetime.datetime.strptime(row[4], '%m/%d/%Y').date() # Check if the record already exists es = EarningSurprise.query(EarningSurprise.ticker==row[0], EarningSurprise.date==date, ).get() # if yes, this is a repeat file, abort if (es != None): self.response.out.write("Earning Surprise file was already loaded.") return # Insert into EarningSurprise es = EarningSurprise(ticker = row[0].upper(), actual= Common.parseFloat(row[1]), estimate = Common.parseFloat(row[2]), percentSurprise = Common.parseFloat(row[3]), date = date, direction = row[5] ) es.put() inputFile.close() self.response.out.write("Earning Surprises loaded.")
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Ticker, Year, Sales, NetIncome, Depreciation, CapEx, wcDelta, debtDelta inputFile = open( os.path.join( os.path.dirname(__file__) + "/data", exchange + '_price_data.csv')) inputReader = csv.reader(inputFile, delimiter=',') for row in inputReader: ticker = row[0].upper() price = Common.parseFloat(row[5]) # Find 'Stock' record for this 'ticker' st = Stock.query(Stock.ticker == ticker).get() if (st != None): if (price != None): st.price = price if (st.iValue != None and price != 0): st.ivPrem = round((st.iValue - price) / price, 2) if (st.eps != None and st.eps != 0): st.peRatio = round(price / st.eps, 2) if (st.bps != None and st.bps != 0): st.pbRatio = round(price / st.bps, 2) st.put() inputFile.close() self.response.out.write("New Prices for Exchange=" + exchange + " updated.")
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) vt = postDataDict['vt'] st = postDataDict['st'] # Get Current Date - 10days cutoffDate = datetime.datetime.now() - datetime.timedelta(days = 10) # Get data for last 10 days if (st=='ALL'): q = EarningSurprise.query(EarningSurprise.date > cutoffDate).order(-EarningSurprise.date) else: q = EarningSurprise.query(EarningSurprise.date > cutoffDate, EarningSurprise.direction == st).order(-EarningSurprise.date) data = [] i = 0 for p in q.iter(): ticker = p.ticker logging.info("ticker=" + ticker) # Get other data from Stock st = Stock.query(Stock.ticker == ticker).get() if (st != None): if (vt=='UV'): if (st.iValue<st.price): continue elif (vt=='OV'): if (st.iValue>st.price): continue data.append({'date': str(p.date), 'ticker':ticker, 'name':st.name, 'estimate':Common.xformNan(p.estimate), 'actual':Common.xformNan(p.actual), 'percentSurprise': Common.xformNan(p.percentSurprise), 'ivPrem': Common.xformNan(st.ivPrem), 'peRatio': Common.xformNan(st.peRatio), 'pbRatio': Common.xformNan(st.pbRatio) }) # JSON data self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {'data': data} ) )
def post(self): # Get 'exchange' and 'ticker' for the current process exchange = self.request.get("exchange") ticker = self.request.get("ticker") name = self.request.get("name") beta = Common.parseFloat(self.request.get("beta")) shares_os = Common.parseFloat(self.request.get("shares_os")) price = Common.parseFloat(self.request.get("price")) rf = Common.parseFloat(self.request.get("rf")) rm = Common.parseFloat(self.request.get("rm")) eps = Common.parseFloat(self.request.get("eps")) # Calculate cost of Equity if (beta== None): coe = rf + ( 1 * (rm - rf) ) else: coe = rf + ( float(beta) * (rm - rf) ) coe = round(coe, 2) # Find 'Stock' record for this 'ticker' q = Stock.query(Stock.ticker == ticker, Stock.exchange == exchange) stockRecord = q.get() # If stock does not exist, create a new record if (stockRecord == None): stockRecord = Stock(ticker = ticker, name = name, exchange = exchange, beta = beta, shares_os = shares_os, coe = coe, price = price, eps = eps ) stockRecord.put() else: # Update data stockRecord.beta = beta stockRecord.shares_os = shares_os stockRecord.price = price stockRecord.coe = coe # COE = RF + Beta(RM - RF) stockRecord.eps = eps stockRecord.put()
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Ticker, Year, Sales, NetIncome, Depreciation, CapEx, wcDelta, debtDelta inputFile = open(os.path.join(os.path.dirname(__file__) + "/data", exchange + '_price_data.csv')) inputReader = csv.reader(inputFile, delimiter=',') for row in inputReader: ticker = row[0].upper() price = Common.parseFloat(row[5]) # Find 'Stock' record for this 'ticker' st = Stock.query(Stock.ticker == ticker).get() if (st != None): if (price != None): st.price = price if (st.iValue != None and price != 0): st.ivPrem = round ((st.iValue-price)/price, 2) if (st.eps != None and st.eps != 0): st.peRatio = round (price/st.eps, 2) if (st.bps != None and st.bps != 0): st.pbRatio = round (price/st.bps, 2) st.put() inputFile.close() self.response.out.write("New Prices for Exchange=" + exchange + " updated.")
def post(self): # Get 'exchange' and 'ticker' for the current process exchange = self.request.get("exchange") ticker = self.request.get("ticker") name = self.request.get("name") beta = Common.parseFloat(self.request.get("beta")) shares_os = Common.parseFloat(self.request.get("shares_os")) price = Common.parseFloat(self.request.get("price")) rf = Common.parseFloat(self.request.get("rf")) rm = Common.parseFloat(self.request.get("rm")) eps = Common.parseFloat(self.request.get("eps")) # Calculate cost of Equity if (beta == None): coe = rf + (1 * (rm - rf)) else: coe = rf + (float(beta) * (rm - rf)) coe = round(coe, 2) # Find 'Stock' record for this 'ticker' q = Stock.query(Stock.ticker == ticker, Stock.exchange == exchange) stockRecord = q.get() # If stock does not exist, create a new record if (stockRecord == None): stockRecord = Stock(ticker=ticker, name=name, exchange=exchange, beta=beta, shares_os=shares_os, coe=coe, price=price, eps=eps) stockRecord.put() else: # Update data stockRecord.beta = beta stockRecord.shares_os = shares_os stockRecord.price = price stockRecord.coe = coe # COE = RF + Beta(RM - RF) stockRecord.eps = eps stockRecord.put()
def post(self): # Get'ticker' for the current process ticker = self.request.get("ticker") coe = Common.parseFloat(self.request.get("coe")) shares_os = Common.parseFloat(self.request.get("shares_os")) price = Common.parseFloat(self.request.get("price")) # Used in Intrinsic Value calculation fcf = 0 fcfList = [] # For each year for yr in range(Common.CURRENT_YEAR, (Common.CURRENT_YEAR + Common.SHOW_PERIODS)): q = UserStockForecast.query(UserStockForecast.ticker == ticker, UserStockForecast.year == yr) # if no UserStockForecast present if (q.count() == 0): continue # User Forecast Array ufA = None for p in q.iter(): # Data is counted only if FCF was calculated for that year if (p.fcf == 0 or p.fcf == None): continue if (ufA == None): ufA = numpy.array( [ [p.sales], [p.salesGrowth], [p.ni], [p.niPerSales], [p.dep], [p.depPerSales], [p.defTaxes], [p.defTaxesPerSales], [p.other], [p.otherPerSales], [p.capEx], [p.capExPerSales], [p.wcDelta], [p.wcDeltaPerSales], [p.fcf] ] ) else: ufA = numpy.append(ufA, [ [p.sales], [p.salesGrowth], [p.ni], [p.niPerSales], [p.dep], [p.depPerSales], [p.defTaxes], [p.defTaxesPerSales], [p.other], [p.otherPerSales], [p.capEx], [p.capExPerSales], [p.wcDelta], [p.wcDeltaPerSales], [p.fcf] ], axis=1 ) # Calculate and Update mean values in 'CrowdStockForecast' if (ufA != None): # Check if record alreday exists in 'CrowdStockForecast' csf = CrowdStockForecast.query(CrowdStockForecast.ticker == ticker, CrowdStockForecast.year == yr ).get() # If not, create it if (csf == None): csf = CrowdStockForecast(ticker = ticker, year=yr) csf.put() csf.sales = round(numpy.mean(filter(None,ufA[0]))) csf.salesVar = round(numpy.var(filter(None,ufA[0])), 2) csf.salesGrowth = round(numpy.mean(filter(None,ufA[1])), 2) csf.salesGrowthVar = round(numpy.var(filter(None,ufA[1])), 2) csf.ni = round(numpy.mean(filter(None,ufA[2]))) csf.niVar = round(numpy.var(filter(None,ufA[2])), 2) csf.niPerSales = round(numpy.mean(filter(None,ufA[3])), 2) csf.niPerSalesVar = round(numpy.var(filter(None,ufA[3])), 2) csf.dep = round(numpy.mean(filter(None,ufA[4]))) csf.depVar = round(numpy.var(filter(None,ufA[4])), 2) csf.depPerSales = round(numpy.mean(filter(None,ufA[5])), 2) csf.depPerSalesVar = round(numpy.var(filter(None,ufA[5])), 2) csf.defTaxes = round(numpy.mean(filter(None,ufA[6]))) csf.defTaxesVar = round(numpy.var(filter(None,ufA[6])), 2) csf.defTaxesPerSales = round(numpy.mean(filter(None,ufA[7])), 2) csf.defTaxesPerSalesVar = round(numpy.var(filter(None,ufA[7])), 2) csf.other = round(numpy.mean(filter(None,ufA[8]))) csf.otherVar = round(numpy.var(filter(None,ufA[8])), 2) csf.otherPerSales = round(numpy.mean(filter(None,ufA[9])), 2) csf.otherPerSalesVar = round(numpy.var(filter(None,ufA[9])), 2) csf.capEx = round(numpy.mean(filter(None,ufA[10]))) csf.capExVar = round(numpy.var(filter(None,ufA[10])), 2) csf.capExPerSales = round(numpy.mean(filter(None,ufA[11])), 2) csf.capExPerSalesVar = round(numpy.var(filter(None,ufA[11])), 2) csf.wcDelta = round(numpy.mean(filter(None,ufA[12]))) csf.wcDeltaVar = round(numpy.var(filter(None,ufA[12])), 2) csf.wcDeltaPerSales = round(numpy.mean(filter(None,ufA[13])), 2) csf.wcDeltaPerSalesVar = round(numpy.var(filter(None,ufA[13])), 2) fcf = round(numpy.mean(filter(None,ufA[14]))) csf.fcf = fcf # Add FCF to list for later calculation of Intrinsic value fcfList.append(csf.fcf) csf.fcfVar = round(numpy.var(filter(None,ufA[12])), 2) csf.put() # End of if # End of for # Check if FCF is available for all the periods if (len(fcfList) == Common.SHOW_PERIODS): divBase = 1 + (coe/100); div = dfcfe = dfcfeTotal = 0 # Add terminal FCFE to the list div = pow(divBase, 0 - Common.COMPANY_LIFE); terminalFcfe = round(fcfList[Common.SHOW_PERIODS-1] * (1 - div) / (coe/100)) fcfList.append(terminalFcfe) for i in range(0, Common.SHOW_PERIODS+1): div = pow(divBase, i+1); dfcfe = round((fcfList[i] / div)); dfcfeTotal = dfcfeTotal + dfcfe; dfcfeTotal = round(dfcfeTotal, 2) # Calculate intrinsic value iValue = None if (shares_os != 0): iValue = round(dfcfeTotal/shares_os, 2) # update Intrinsic Value in 'Stock' stock = Stock.query(Stock.ticker==ticker).get() if (stock != None): stock.terminalFcfe = terminalFcfe stock.fcfSum = dfcfeTotal stock.iValue = iValue if (iValue != None and price != None and iValue > 0): stock.pvRatio = round(price/iValue, 2) stock.pvRatioDev = round(abs(1 - stock.pvRatio), 2) stock.put()
def post(self): tickerVal = self.request.get("tickerVal") # Check first if stock is defined in 'Stock' # if not, no point in loading financial data q = Stock.query(Stock.ticker == tickerVal).get() if (q == None): return yearVal = Common.parseInt(self.request.get("yearVal")) salesVal = Common.parseFloat(self.request.get("salesVal")) prevSalesVal = Common.parseFloat(self.request.get("prevSales")) salesGrowthVal = None niVal = Common.parseFloat(self.request.get("niVal")) niPerSalesVal = None depVal = Common.parseFloat(self.request.get("depVal")) depPerSalesVal = None defTaxesVal = Common.parseFloat(self.request.get("defTaxesVal")) defTaxesPerSalesVal = None otherVal = Common.parseFloat(self.request.get("otherVal")) otherPerSalesVal = None capExVal = Common.parseFloat(self.request.get("capExVal")) capExPerSalesVal = None wcDeltaVal = Common.parseFloat(self.request.get("wcDeltaVal")) wcDeltaPerSalesVal = None fcf = None if (salesVal != None and salesVal != 0): fcf = 0 if (niVal != None): niPerSalesVal = round( ( (niVal * 100) / salesVal ), 2) fcf = niVal if (depVal != None): depPerSalesVal = round( ( (depVal * 100) / salesVal ), 2) fcf = fcf + depVal if (defTaxesVal != None): defTaxesPerSalesVal = round( ( (defTaxesVal * 100) / salesVal ), 2) fcf = fcf + defTaxesVal if (otherVal != None): otherPerSalesVal = round( ( (otherVal * 100) / salesVal ), 2) fcf = fcf + otherVal if (capExVal != None): capExPerSalesVal = round( ( (float(capExVal) * 100) / salesVal ), 2) fcf = fcf - float(capExVal) if (wcDeltaVal != None): wcDeltaPerSalesVal = round( ( (wcDeltaVal * 100) / salesVal ), 2) fcf = fcf - wcDeltaVal if (prevSalesVal != None and prevSalesVal != 0): salesGrowthVal = round( ( ( (salesVal - prevSalesVal)*100) / prevSalesVal), 2) # Check if the record already exists stockFin = YearlyFinancial.query(YearlyFinancial.ticker == tickerVal, YearlyFinancial.year == yearVal).get() # If record does not exist, create it if (stockFin == None): stockFin = YearlyFinancial(ticker = tickerVal, year = yearVal) stockFin.put() stockFin.sales = salesVal stockFin.ni = niVal stockFin.dep = depVal stockFin.defTaxes = defTaxesVal stockFin.other = otherVal stockFin.capEx = capExVal stockFin.wcDelta = wcDeltaVal if (fcf != None): stockFin.fcf = round(fcf) stockFin.salesGrowth = salesGrowthVal stockFin.niPerSales = niPerSalesVal stockFin.depPerSales = depPerSalesVal stockFin.defTaxesPerSales = defTaxesPerSalesVal stockFin.otherPerSales = otherPerSalesVal stockFin.capExPerSales = capExPerSalesVal stockFin.wcDeltaPerSales = wcDeltaPerSalesVal stockFin.put()
def get(self): # Get 'exchange' for the current process exchange = self.request.get("Exchange") if (exchange == None or exchange == ''): self.response.out.write("Exchange not specified.") return # Ticker, Year, Sales, NetIncome, Depreciation, CapEx, wcDelta, debtDelta inputFile = open( os.path.join( os.path.dirname(__file__) + "/data", exchange + '_financials_data.csv')) inputReader = csv.reader(inputFile, delimiter=':') prevSales = None prevTicker = "-1" for row in inputReader: tickerVal = row[0].upper() #Ticker is changed if (tickerVal != prevTicker): prevTicker = tickerVal prevSales = None yearVal = int(row[1]) salesVal = Common.getEqMillions(row[2]) niVal = Common.getEqMillions(row[3]) depVal = Common.getEqMillions(row[4]) defTaxesVal = Common.getEqMillions(row[5]) otherVal = Common.getEqMillions(row[6]) # Marketwatch prints negative values for 'Increase in WC and CapEx' so it can add to NI for calculating FCF # TheVasp subtracts those values therefore negate marketwatch values capExVal = Common.getEqMillions(row[7]) if (capExVal != None): capExVal = 0 - float(capExVal) wcDeltaVal = Common.getEqMillions(row[8]) if (wcDeltaVal != None): wcDeltaVal = 0 - float(wcDeltaVal) # Add the task to the default queue. taskqueue.add(url='/admin/LoadStockFinancials', params={ 'tickerVal': tickerVal, 'yearVal': yearVal, 'salesVal': salesVal, 'prevSales': prevSales, 'niVal': niVal, 'depVal': depVal, 'defTaxesVal': defTaxesVal, 'otherVal': otherVal, 'capExVal': capExVal, 'wcDeltaVal': wcDeltaVal }) # Current Sales is 'prevSales' for next year prevSales = salesVal inputFile.close() self.response.out.write("Financial data for Exchange=" + exchange + " loaded.")
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) ticker = postDataDict['ticker'] userFlag = postDataDict['userFlag'] token = postDataDict['token'] compareData = [] userName = None # Check if the request is coming from published url if (token != ''): if (token == 'Public'): userFlag = 'N' else: userFlag = 'Y' elif (userFlag == 'Y'): user = users.get_current_user() if (user == None): self.response.out.write( json.dumps({'compareData': compareData})) return else: userName = user.nickname() st = Stock.query(Stock.ticker == ticker).get() # If ticker not found, return empty if (st == None): self.response.out.write(json.dumps({'compareData': compareData})) return else: related = st.related if (related == None or related.strip() == ''): self.response.out.write( json.dumps({'compareData': compareData})) return # Get Stock records for the related stocks relList = related.split(',') q = Stock.query(Stock.ticker.IN(relList)) for p in q.iter(): price = Common.getRound(p.price, 2) iValue = Common.getRound(p.iValue, 2) ivPrem = Common.getRound(p.ivPrem, 2) peRatio = Common.getRound(p.peRatio, 2) pbRatio = Common.getRound(p.pbRatio, 2) compareData.append({ 'ticker': p.ticker, 'name': p.name, 'iValue': iValue, 'price': price, 'ivPrem': ivPrem, 'pbRatio': pbRatio, 'peRatio': peRatio }) # If userFlag is 'Y', update iValue and pvRatio based on UserStock values if (userFlag == 'Y'): # If this is coming from Published URL if (token != ''): q = UserStock.query(UserStock.pseudoname == token, Stock.ticker.IN(relList)) elif (userName != None): q = UserStock.query(UserStock.user == userName, Stock.ticker.IN(relList)) for p in q.iter(): ticker = p.ticker iValue = p.iValue ivPrem = None # Find corresponding record in 'compareData' for cd in compareData: if (cd['ticker'] == ticker): cd['iValue'] = iValue price = cd['price'] if (price != None and iValue != None and price > 0): cd['ivPrem'] = round((iValue - price) / price, 2) self.response.out.write(json.dumps({'compareData': compareData}))
def post(self): tickerVal = self.request.get("tickerVal") # Check first if stock is defined in 'Stock' # if not, no point in loading financial data q = Stock.query(Stock.ticker == tickerVal).get() if (q == None): return yearVal = Common.parseInt(self.request.get("yearVal")) salesVal = Common.parseFloat(self.request.get("salesVal")) prevSalesVal = Common.parseFloat(self.request.get("prevSales")) salesGrowthVal = None niVal = Common.parseFloat(self.request.get("niVal")) niPerSalesVal = None depVal = Common.parseFloat(self.request.get("depVal")) depPerSalesVal = None defTaxesVal = Common.parseFloat(self.request.get("defTaxesVal")) defTaxesPerSalesVal = None otherVal = Common.parseFloat(self.request.get("otherVal")) otherPerSalesVal = None capExVal = Common.parseFloat(self.request.get("capExVal")) capExPerSalesVal = None wcDeltaVal = Common.parseFloat(self.request.get("wcDeltaVal")) wcDeltaPerSalesVal = None fcf = None if (salesVal != None and salesVal != 0): fcf = 0 if (niVal != None): niPerSalesVal = round(((niVal * 100) / salesVal), 2) fcf = niVal if (depVal != None): depPerSalesVal = round(((depVal * 100) / salesVal), 2) fcf = fcf + depVal if (defTaxesVal != None): defTaxesPerSalesVal = round(((defTaxesVal * 100) / salesVal), 2) fcf = fcf + defTaxesVal if (otherVal != None): otherPerSalesVal = round(((otherVal * 100) / salesVal), 2) fcf = fcf + otherVal if (capExVal != None): capExPerSalesVal = round(((float(capExVal) * 100) / salesVal), 2) fcf = fcf - float(capExVal) if (wcDeltaVal != None): wcDeltaPerSalesVal = round(((wcDeltaVal * 100) / salesVal), 2) fcf = fcf - wcDeltaVal if (prevSalesVal != None and prevSalesVal != 0): salesGrowthVal = round( (((salesVal - prevSalesVal) * 100) / prevSalesVal), 2) # Check if the record already exists stockFin = YearlyFinancial.query( YearlyFinancial.ticker == tickerVal, YearlyFinancial.year == yearVal).get() # If record does not exist, create it if (stockFin == None): stockFin = YearlyFinancial(ticker=tickerVal, year=yearVal) stockFin.put() stockFin.sales = salesVal stockFin.ni = niVal stockFin.dep = depVal stockFin.defTaxes = defTaxesVal stockFin.other = otherVal stockFin.capEx = capExVal stockFin.wcDelta = wcDeltaVal if (fcf != None): stockFin.fcf = round(fcf) stockFin.salesGrowth = salesGrowthVal stockFin.niPerSales = niPerSalesVal stockFin.depPerSales = depPerSalesVal stockFin.defTaxesPerSales = defTaxesPerSalesVal stockFin.otherPerSales = otherPerSalesVal stockFin.capExPerSales = capExPerSalesVal stockFin.wcDeltaPerSales = wcDeltaPerSalesVal stockFin.put()
def post(self): self.response.headers['Content-Type'] = 'application/json' postDataDict = json.loads(cgi.escape(self.request.body)) ticker = postDataDict['ticker'] userFlag = postDataDict['userFlag'] token = postDataDict['token'] compareData = [] userName = None # Check if the request is coming from published url if (token != ''): if (token == 'Public'): userFlag = 'N' else: userFlag = 'Y' elif (userFlag == 'Y'): user = users.get_current_user() if (user == None): self.response.out.write(json.dumps({'compareData': compareData})) return else: userName = user.nickname() st = Stock.query(Stock.ticker==ticker).get() # If ticker not found, return empty if (st == None): self.response.out.write(json.dumps({'compareData': compareData})) return else: related = st.related if (related == None or related.strip() == ''): self.response.out.write(json.dumps({'compareData': compareData})) return # Get Stock records for the related stocks relList = related.split(',') q = Stock.query(Stock.ticker.IN(relList)) for p in q.iter(): price = Common.getRound(p.price, 2) iValue = Common.getRound(p.iValue, 2) ivPrem = Common.getRound(p.ivPrem, 2) peRatio = Common.getRound(p.peRatio, 2) pbRatio = Common.getRound(p.pbRatio, 2) compareData.append({'ticker':p.ticker, 'name': p.name, 'iValue': iValue, 'price': price, 'ivPrem': ivPrem, 'pbRatio': pbRatio, 'peRatio': peRatio}) # If userFlag is 'Y', update iValue and pvRatio based on UserStock values if (userFlag == 'Y'): # If this is coming from Published URL if (token != ''): q = UserStock.query(UserStock.pseudoname==token, Stock.ticker.IN(relList)) elif (userName != None): q = UserStock.query(UserStock.user==userName, Stock.ticker.IN(relList)) for p in q.iter(): ticker = p.ticker iValue = p.iValue ivPrem = None # Find corresponding record in 'compareData' for cd in compareData: if (cd['ticker'] == ticker): cd['iValue'] = iValue price = cd['price'] if (price != None and iValue != None and price > 0): cd['ivPrem'] = round((iValue - price)/price, 2) self.response.out.write(json.dumps({'compareData': compareData}))
def post(self): # Get'ticker' for the current process ticker = self.request.get("ticker") # Get Analyst Estimates for the given ticker q = AnalystEstimate.query(AnalystEstimate.ticker == ticker, AnalystEstimate.year >= Common.CURRENT_YEAR, AnalystEstimate.year < (Common.CURRENT_YEAR + Common.SHOW_PERIODS) ).order(AnalystEstimate.year) aEstList = [] for p in q.iter(): aEstList.append(p.ni) # Get records from 'YearlyFinanacial' table for the given ticker q = YearlyFinancial.query(YearlyFinancial.ticker == ticker, YearlyFinancial.year >= (Common.CURRENT_YEAR-Common.SHOW_PERIODS)).order(YearlyFinancial.year) # Some stocks may not have data populated, do nothing in that case if (q.count() == 0): return data = numpy.zeros([Common.TOTAL_FIELDS, Common.SHOW_PERIODS]) for p in q.iter(): yrCnt = p.year - (Common.CURRENT_YEAR-Common.SHOW_PERIODS) # If record is older than 5 years or newer than current year, skip if ( yrCnt >= Common.SHOW_PERIODS or yrCnt < 0 ): continue data[0, yrCnt] = p.sales data[1, yrCnt] = p.salesGrowth data[3, yrCnt] = p.niPerSales data[5, yrCnt] = p.depPerSales data[7, yrCnt] = p.defTaxesPerSales data[9, yrCnt] = p.otherPerSales data[11, yrCnt] = p.capExPerSales data[13, yrCnt] = p.wcDeltaPerSales # End of for loop for Yearly Financials # For sales, sales growth and ni, use last values. For everything else, use 5 year avg salesLast = data[0, 4] # If last value is not available, use average if (salesLast == None or salesLast == 0): salesLast = numpy.mean(filter(None, data[0])) # If we can't get a base value of sales, abort estimates if (salesLast == None or salesLast == 0): return salesGrowthLast = data[1, 4] # If last value is not available, use average if (salesGrowthLast == None or salesGrowthLast == 0): salesGrowthLastF = numpy.mean(filter(None, data[1])) # If we can't get a base value of salesGrowthLast, abort estimates if (salesGrowthLast == None or salesGrowthLast == 0): return niPerSalesLast = data[3, 4] # If last value is not available, Use average if (niPerSalesLast == None or niPerSalesLast == 0): niPerSalesLast = numpy.mean(filter(None, data[3])) # If we can't get a base value of niPerSalesLast, we may still have analyst estimates. depPerSalesAvg = Common.getPastAvg(data[5]) defTaxesPerSalesAvg = Common.getPastAvg(data[7]) otherPerSalesAvg = Common.getPastAvg(data[9]) capExPerSalesAvg = Common.getPastAvg(data[11]) wcDeltaPerSalesAvg = Common.getPastAvg(data[13]) curSales = 0 # Calculate and update values for next 5 years for i in range(0, 5): year = Common.CURRENT_YEAR + i # Check if record already exists usf = UserStockForecast.query(UserStockForecast.user == Common.AVG_USER, UserStockForecast.ticker == ticker, UserStockForecast.year == year).get() # If record does not exist, create it if (usf == None): usf = UserStockForecast(user = Common.AVG_USER, ticker = ticker, year = year) usf.put() curSales = round(salesLast * (1 + (salesGrowthLast/100))) if (curSales == 0): return salesLast = curSales # Update Sales usf.sales = curSales usf.salesGrowth = salesGrowthLast # Update ni # Use analyst estimate first if available if (len(aEstList) > i): usf.ni = aEstList[i] niPerSalesLast = round( ((aEstList[i] * 100) / curSales), 2) usf.niPerSales = niPerSalesLast else: usf.ni = round(curSales * (niPerSalesLast/100)) usf.niPerSales = niPerSalesLast usf.fcf = usf.ni if (depPerSalesAvg != None): usf.dep = round(curSales * (depPerSalesAvg/100)) usf.depPerSales = depPerSalesAvg usf.fcf = usf.fcf + usf.dep if (defTaxesPerSalesAvg != None): usf.defTaxes = round(curSales * (defTaxesPerSalesAvg/100)) usf.defTaxesPerSales = defTaxesPerSalesAvg usf.fcf = usf.fcf + usf.defTaxes if (otherPerSalesAvg != None): usf.other = round(curSales * (otherPerSalesAvg/100)) usf.otherPerSales = otherPerSalesAvg usf.fcf = usf.fcf + usf.other if (capExPerSalesAvg != None): usf.capEx = round(curSales * (capExPerSalesAvg/100)) usf.capExPerSales = capExPerSalesAvg usf.fcf = usf.fcf - usf.capEx if (wcDeltaPerSalesAvg != None): usf.wcDelta = round(curSales * (wcDeltaPerSalesAvg/100)) usf.wcDeltaPerSales = wcDeltaPerSalesAvg usf.fcf = usf.fcf - usf.wcDelta usf.fcf = round(usf.fcf, 2) usf.put()
def post(self): postDataDict = json.loads(cgi.escape(self.request.body)) ticker = postDataDict['ticker'] token = postDataDict['token'].strip() userFlag = postDataDict['userFlag'] userName = '' publicUrl = '' # If 'token' is specified, request came from 'publishValuation' if (token != ''): # Check if request came for Public 'publishValuation' if (token == 'Public'): userFlag = 'N' else: # Get userName from token us = UserStock.query(UserStock.pseudoname == token, UserStock.ticker == ticker).get() if (us == None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {"errMessage": "User valuation not found."} ) ) return else: userName = us.user userFlag == 'Y' else: token = 'Public' # Check for active Google account session user = users.get_current_user() # Check if current request is for 'User Estimates' # If user is not signed in, return error if (userFlag == 'Y' and user == None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {"errMessage": "User not signed in."} ) ) return if (user != None): userName = user.nickname() # If data fetched is user specific if (userFlag == 'Y'): token = hashlib.sha1(userName).hexdigest() fcfDataPast = Common.getPastData(ticker) # If last sales value is not defined, return error if (fcfDataPast[0,0] == 0 or fcfDataPast[0,0]==None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps( {"errMessage": "<p>Sorry, 'TheVasp' does not cover this stock.</p>" + "<p>Either the stock is from finance industry <br />or<br /> Data is not available for the stock.</p>" } ) ) return fcfDataForecast = Common.getForecastData(ticker, userFlag, userName) fcfData = [] # Create JSON object fcfData.append(Common.getFcfRecord(1, "<b>Sales</b>", 0, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "YrOverYr % Growth", 1, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(2, "<b>Net Income</b>", 2, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 3, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(3, "<b>Depreciation</b>", 4, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 5, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(4, "<b>Deferred Taxes</b>", 6, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 7, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(5, "<b>Other Funds</b>", 8, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 9, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(6, "<b>Capital Expenditure</b>", 10, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 11, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord(7, "<b>Working Capital Increase</b>", 12, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append(Common.getFcfRecord("", "As % of Sales", 13, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( {"id":"", "rowName":"", "n5_":"", "n4_":"", "n3_":"", "n2_":"", "n1_":"", "PastAvg":"", "n1":"", "n2":"", "n3":"", "n4":"", "n5":"", "FM":"" } ) fcfData.append(Common.getFcfRecord("", "<b>FCFE (2+3+4+5-6-7)</b>", 14, fcfDataPast, fcfDataForecast, userFlag)) #################################### End of HandsOnTable data create ############################## #logging.info(fcfData) publicUrlHtml = "<B>URL to publish this valuation:</B> " + \ "<U>" + self.request.host_url + "/?token=" + token + "&ticker=" + ticker + "</U>" self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({'fcfData': fcfData, 'userName': userName, 'publicUrlHtml': publicUrlHtml}, allow_nan=True))
def post(self): postDataDict = json.loads(cgi.escape(self.request.body)) ticker = postDataDict['ticker'] token = postDataDict['token'].strip() userFlag = postDataDict['userFlag'] userName = '' publicUrl = '' # If 'token' is specified, request came from 'publishValuation' if (token != ''): # Check if request came for Public 'publishValuation' if (token == 'Public'): userFlag = 'N' else: # Get userName from token us = UserStock.query(UserStock.pseudoname == token, UserStock.ticker == ticker).get() if (us == None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps({"errMessage": "User valuation not found."})) return else: userName = us.user userFlag == 'Y' else: token = 'Public' # Check for active Google account session user = users.get_current_user() # Check if current request is for 'User Estimates' # If user is not signed in, return error if (userFlag == 'Y' and user == None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps({"errMessage": "User not signed in."})) return if (user != None): userName = user.nickname() # If data fetched is user specific if (userFlag == 'Y'): token = hashlib.sha1(userName).hexdigest() fcfDataPast = Common.getPastData(ticker) # If last sales value is not defined, return error if (fcfDataPast[0, 0] == 0 or fcfDataPast[0, 0] == None): self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps({ "errMessage": "<p>Sorry, 'TheVasp' does not cover this stock.</p>" + "<p>Either the stock is from finance industry <br />or<br /> Data is not available for the stock.</p>" })) return fcfDataForecast = Common.getForecastData(ticker, userFlag, userName) fcfData = [] # Create JSON object fcfData.append( Common.getFcfRecord(1, "<b>Sales</b>", 0, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "YrOverYr % Growth", 1, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(2, "<b>Net Income</b>", 2, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 3, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(3, "<b>Depreciation</b>", 4, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 5, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(4, "<b>Deferred Taxes</b>", 6, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 7, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(5, "<b>Other Funds</b>", 8, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 9, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(6, "<b>Capital Expenditure</b>", 10, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 11, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord(7, "<b>Working Capital Increase</b>", 12, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append( Common.getFcfRecord("", "As % of Sales", 13, fcfDataPast, fcfDataForecast, userFlag)) fcfData.append({ "id": "", "rowName": "", "n5_": "", "n4_": "", "n3_": "", "n2_": "", "n1_": "", "PastAvg": "", "n1": "", "n2": "", "n3": "", "n4": "", "n5": "", "FM": "" }) fcfData.append( Common.getFcfRecord("", "<b>FCFE (2+3+4+5-6-7)</b>", 14, fcfDataPast, fcfDataForecast, userFlag)) #################################### End of HandsOnTable data create ############################## #logging.info(fcfData) publicUrlHtml = "<B>URL to publish this valuation:</B> " + \ "<U>" + self.request.host_url + "/?token=" + token + "&ticker=" + ticker + "</U>" self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps( { 'fcfData': fcfData, 'userName': userName, 'publicUrlHtml': publicUrlHtml }, allow_nan=True))