Image for post
Image for post

Stocktwits — The Twitter of stocks, offers a free API to access trending stocks on its site. This list of trending stock tickers can be iterated over to scrape any number of useful sentiment indicators. One such indicator is a weighed opinion of thousands of investors, and it’s a good predictor of short-term valuation.

import requests
from bs4 import BeautifulSoup
import time
stocktwits_trending = requests.get('').json()stocktwits_trending_tickers = [stocktwits_trending['messages'][index]['symbols'][0]['symbol'] for index in range(len(stocktwits_trending['messages']))]trending_sentiment = {}for index in stocktwits_trending_tickers: try: time.sleep(2) x = requests.get('{}'.format(index)) soup = BeautifulSoup(x.text, 'html.parser') texts = soup.findAll(text=True) Real_time=texts.index('Real-Time') Sentiment_index=texts[Real_time+1].index('sentimentChange') trending_sentiment['%s'%index]=texts[Real_time+1][Sentiment_index:Sentiment_index+21] except: pass…

Five-minute web apps with Python.

Image for post
Image for post

The Flask micro web framework for Python allows for rapid development of web applications. Apps can be deployed to any free web hosting service, but one is particular makes the process seamless, and that is PythonAnywhere.

The Example:

Below is the full code for a (very) simple application, explained in detail further down. For the sake of simplicity and speed, everything is kept inside one Python file, including the HTML which is normally separate:

Brief explanation for those unfamiliar with Flask or HTML

This application is asking the user for data, sending a request to the server with the HTTP method ‘POST’, and then returning a string as HTML.


Image for post
Image for post

Regression is fundamental to Predictive Analytics, and a good example of an optimization problem. The simplest cases of regression are calculable by hand (the results of which we can verify with Python). Below is the linear regression model of some predictor variable ‘x’ with response variable ‘y’.

Image for post
Image for post

Populations that undergo a fixed set of age transitions can be modeled as a system of linear equations, from which age distributions can be calculated.

As a brief review of linear algebra, a system of linear equations can be represented as a matrix equation of the form Ax = b. In this form, ‘A is the set of coefficients as some m × n matrix, ‘x is some input vector in n, and ‘b’ is the product of ‘A’ and ‘x’ as an output vector in m, shown below:


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store