Skip to content

Instantly share code, notes, and snippets.

View mlivingston40's full-sized avatar

Matt Livingston mlivingston40

  • Austin, Texas
View GitHub Profile
import quandl
import pandas as pd
class MeanReversion:
def __init__(self, security, start_date, end_date, sma_, lma_):
self.security = security
self.start_date = start_date
self.end_date = end_date
self.sma_ = sma_
@application.route('/meanreversion/result/<security>/<start_date>/<end_date>/<int:sma_>/<int:lma_>')
def meanreversion_result(security,start_date,end_date,sma_,lma_):
m = MeanReversion(security, start_date, end_date, sma_, lma_)
smadf = m.moving_average_df(m.sma_)
lmadf = m.moving_average_df(m.lma_)
from flask_wtf import FlaskForm
from wtforms import StringField, DateField, validators
class CorrelationForm(FlaskForm):
stock1 = StringField('Stock 1',
[validators.Required('Start typing ticker symbol and select'),
validators.Length(min=1, max=5)], id = "ticker1")
stock2 = StringField('Stock 2',
[validators.Required('Start typing ticker symbol and select'),
validators.Length(min=1, max=5)], id = "ticker2")
@application.route('/correlation', methods=['GET', 'POST'])
def correlation():
form = CorrelationForm()
if request.method == 'POST' and form.validate():
security1 = request.form['stock1']
security2 = request.form['stock2']
start_date = request.form['date_start']
end_date = request.form['date_end']
<form method=”post” action=”{{ url_for(‘correlation’) }}”>
{{ form.hidden_tag() }}
<div class=”form-group row”>
<div class=”col-sm-10 col-lg-10">
{{ form.stock1.label |safe }} {{ form.stock1(placeholder=”e.g., GOOG”, class=”form-control”)|safe }} {% if form.stock1.errors %}
<ul class=”alert alert-info alert-dismissible” role=”alert”>
<button type=”button” class=”close” data-dismiss=”alert” aria-label=”Close” <span aria-hidden=”true”>&times;</span>
</button>
{% for error in form.stock1.errors %}
<strong>{{ error }}</strong> {% endfor %}
@mlivingston40
mlivingston40 / Bootstrap_cols_example.html
Last active November 21, 2017 22:02
Bootstrap columns example
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-institution fa-4x"></i>
</div>
<div class="col-xs-9 text-right">
<div>
@mlivingston40
mlivingston40 / 404_500_flask.py
Created November 21, 2017 22:38
Error routing for 'page note found' and 'internal server error' in flask
# “404 Page Not Found”
@application.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
# “500 Internal Server Error”
@application.errorhandler(500)
def page_not_found(e):
return render_template('500.html'), 500
@mlivingston40
mlivingston40 / flask_flash.html
Created November 21, 2017 23:01
flashing 'flash' messages in flask
{% for message in get_flashed_messages() %}
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"
<span
aria-hidden="true">&times;</span></button>
{{ message }}
</div>
{% endfor %}
@mlivingston40
mlivingston40 / flash_routing.py
Last active November 21, 2017 23:12
flash flask routing
@application.route('/correlation/result/<security1>/<security2>/<start_date>/<end_date>')
def correlation_result(security1,security2,start_date,end_date):
try:
c = Correlation(security1, security2, start_date, end_date)
except:
if start_date > end_date:
@mlivingston40
mlivingston40 / 01_packages.config
Created November 22, 2017 02:46
python deployment .ebextensions
packages:
yum:
gcc-c++: []
python34-devel: []