def StockGrpah(StockID): graph = pygal.Line() graph.title = 'Stock Graph for ' + StockID #Getting DB connection connection_string, engine, connection = get_connections() #Stock Graph stock_query = "exec spMovingAverage @StockID= ? , @NumOfYears=2" stockResults = pd.read_sql_query(stock_query,connection,params=[StockID]) graph.x_labels = stockResults.StockPriceDate graph.add('Stock Price', stockResults.StockClosePrice) graph.add('50 MA', stockResults.Stock50MA) graph.add('200 MA', stockResults.Stock200MA) graph_data = graph.render_data_uri() #Bollinger_Band_graph graph_bb = pygal.Line() graph_bb.title = 'Bollinger Band for ' + StockID stock_query = "exec spBollingerBands @StockID= ? , @NumOfYears=3" stockResults = pd.read_sql_query(stock_query,connection,params=[StockID]) graph_bb.x_labels = stockResults.StockPriceDate graph_bb.add('Stock Price', stockResults.StockClosePrice) graph_bb.add('50 MA', stockResults.MA50) graph_bb.add('Upper Bound', stockResults.UpperBollinger) graph_bb.add('Lower Bound', stockResults.LowerBollinger) Bollinger_Band_graph = graph_bb.render_data_uri() return render_template("app/graph/lineGraph.html", graph_data = graph_data, Bollinger_Band_graph = Bollinger_Band_graph)
def SellPut(): form = SellPutForm() if form.validate_on_submit(): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() # Insert Sell Put Transaction insertPut = "EXEC CoveredCalls.dbo.spiCreatePutOption @AccountID= ?,@StockID= ?,@PositionID=NULL,@PutStrikePrice= ?,@PutExpiry= ?,@PutPrice= ?,@IsOptionPriceWithCommission= ?,@PutNumberOfShares= ?,@PutWriteDate= ?,@IsDemo= ?,@TranType= ?" connection.execute(insertPut, [ accountID, form.StockID.data, form.PutStrikePrice.data, form.PutExpiry.data, form.PutPrice.data, form.IsOptionPriceWithCommission.data, form.PutNumberOfShares.data, form.PutWriteDate.data, form.IsDemo.data, form.TranType.data ]) flash( 'SELL put option has been inserted for Stock %s' % form.StockID.data, 'success') return redirect(url_for('main.index')) elif form.is_submitted(): error = 'Information incorrect, please check all fields and submit again' flash(form.errors) return render_template('app/put/SellPut.html', form=form, error=error) return render_template('app/put/SellPut.html', form=form)
def NextCoveredCall(): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() #Stocks Picks query = "exec spNextCall @AccountID= ?, @StockID=NULL" results = pd.read_sql_query(query,connection,params=(str(accountID),)) return render_template('app/call/NextCoveredCallPosition.html',NextPicks=results.values)
def Portfolio(): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() #Stocks Picks query = "SELECT StockID, AvgStockPurchasePriceAfterComm,StockPurchaseDate , BreakEvenNet, TotalNumOfShares, TotalStockInvestment FROM [CoveredCalls].[dbo].[vStockPurchasePortfolio] where HoldingStock=1 and AccountID= %s;" % accountID results = pd.read_sql_query(query, connection) return render_template('app/account/Portfolio.html', StockPicks=results.values)
def CoveredCallsResults(): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() lastTradingDate = getLastTradingDate() #Stocks Picks query = "EXEC spCoveredCallResults @AccountID= ?, @TradingDate= ?, @StockID=NULL" results = pd.read_sql_query(query,connection,params=(str(accountID),lastTradingDate.values[0][0])) return render_template('app/call/CoveredCallsResults.html',StockPicks=results.values)
def NextCoveredCallStock(StockID): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() #Stocks Picks query = "exec spNextCall @AccountID= %s, @StockID= %s " %(accountID,StockID) results = pd.read_sql_query(query,connection) stockQueryDetail = "exec spStockDetails @StockID= %s" %StockID resultsStockQuery = pd.read_sql_query(stockQueryDetail,connection) return render_template('app/call/NextCoveredCallPosition.html',NextPicks=results.values, stockQueryResult=resultsStockQuery.values)
def putResults(): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() #Stocks Picks query = "exec spViewPutResuls @AccountID= ?, @StockID= ? " results = pd.read_sql_query(query, connection, params=(str(accountID), None)) return render_template('app/put/putResults.html', StockPicks=results.values)
def CoveredCallsResultsStock(StockID): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() lastTradingDate = getLastTradingDate() #Stocks Picks query = "EXEC spCoveredCallResults @AccountID= ?, @TradingDate= ?, @StockID= ? " results = pd.read_sql_query(query,connection,params=(str(accountID),lastTradingDate.values[0][0],StockID)) stockQueryDetail = "exec spStockDetails @StockID= %s" %StockID resultsStockQuery = pd.read_sql_query(stockQueryDetail,connection) return render_template('app/call/CoveredCallsResults.html',StockPicks=results.values, stockQueryResult=resultsStockQuery.values)
def putResultsStock(StockID): #Getting DB connection connection_string, engine, connection = get_connections() #Getting Account accountID = current_user.get_id() #Stocks Picks query = "exec spViewPutResuls @AccountID= ?, @StockID= ? " results = pd.read_sql_query(query, connection, params=(str(accountID), StockID)) stockQueryDetail = "exec spStockDetails @StockID= %s" % StockID resultsStockQuery = pd.read_sql_query(stockQueryDetail, connection) return render_template('app/put/putResults.html', StockPicks=results.values, stockQueryResult=resultsStockQuery.values)
def getAccountID(username): connection_string, engine, connection = get_connections() #Getting Account accountIDquery = "EXEC spGetAccount @Username= %r ,@email=NULL,@AccountName='Live'" % username accountID = pd.read_sql_query(accountIDquery, connection) return str(accountID.values[0][0])