Skip to content

Commit

Permalink
load local data with get, fix strip()
Browse files Browse the repository at this point in the history
  • Loading branch information
dbricare committed Oct 22, 2016
1 parent 2b9c9e2 commit c0dff55
Show file tree
Hide file tree
Showing 8 changed files with 9,083 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ target/
.ipynb_checkpoints

# ignore data
*.csv
# *.csv
*.ipynb
*.tsv
*.pkl
apikey.txt

# ignore temp files
._*
Expand Down
2 changes: 1 addition & 1 deletion bricdatascience/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def genidx():
},
{'name':'candlestick',
'title':'Equity Price Movement', 'img':'img/stocks.jpg',
'text':'Provides elementary information concerning equity prices, movement, dividends, and splits.',
'text':'Provides elementary information concerning equity prices, movement, dividends, splits, and calculates moving averages.',
'doc': 'Web application'
},
{'name':'expedia',
Expand Down
9 changes: 9 additions & 0 deletions bricdatascience/static/css/portfolio-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ a {
font-weight: 600;
}

ul {
padding-left: 20px;
}

li {
margin-left: 0px;
padding-left: 0px;
}

.formlbls {
padding: 12px;
}
Expand Down
3 changes: 2 additions & 1 deletion bricdatascience/templates/candlestick.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ <h4 class="panel-title"><a data-toggle="collapse" href="#collapse2">Split histor
</form>
<p>&nbsp;</p>
<h4>Project Description</h4>
<p>This project is designed to serve as a source of elementary information on equities including historical prices, dividends, and splits.</p>
<p>This project is designed to serve as a source of elementary information on equities including historical prices, dividends, splits, and calculates moving averages over several windows.</p>
<p>Quandl's API is free however it is a bit slow, data retrieval may take a few seconds.</p>
<h4>Project Details</h4>
<ul>
<li>Full project analysis on <a href="http://github.com/dbricare/">GitHub</a></li>
Expand Down
29 changes: 16 additions & 13 deletions bricdatascience/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,27 @@ def shelteranimals():
### equities analysis
@app.route('/candlestick', methods=['GET', 'POST'])
def candlestick():
# first time through
# first time loading to fetch data from API
if request.method=='GET':
ticker='AAPL'
elif request.method=='POST':
# else:
ticker=request.form['ticker'].upper()
with open('candleget.txt','r') as f:
name=f.readline()
desc=f.read()
df = pd.read_csv('candleget.csv', sep=',', index_col='Date', parse_dates=True)

df,name,desc = df_from_ticker(ticker)
elif request.method=='POST':
ticker=request.form['ticker'].strip().upper()
df,name,desc = df_from_ticker(ticker)

if len(df)==0:
error = '<div class="alert alert-danger">'+\
'<strong>No Matching Ticker</strong> Please enter a new ticker.'+\
'<strong>No Matches Found</strong> Please enter a new ticker.'+\
'</div>'
return render_template('candlestick.html', header='Equities Price Movement', div=error,
ticker=ticker)

return render_template('candlestick.html', header='Equities Price Movement',
div=error, ticker=ticker)
else:
dfdrop = df.drop(['Open', 'High', 'Low', 'Close', 'Volume'], axis=1, inplace=False)
dfdrop = df.drop(['Open', 'High', 'Low', 'Close', 'Volume'], axis=1,
inplace=False)
dividend_table = dfdrop[(dfdrop['Ex-Dividend']>0) & (df.index>=pd.to_datetime('2000-01-01'))].drop(
'Split Ratio', axis=1, inplace=False).to_html(
classes='table', float_format=lambda x: '{:.2f}'.format(x))
Expand All @@ -329,6 +332,6 @@ def candlestick():
# set plot components
script, div = components(p)

return render_template('candlestick.html', dividend=dividend_table, split=split_table, header=name,
description=desc, script=script, div=div, ticker=ticker,
updated = moddate())
return render_template('candlestick.html', dividend=dividend_table,
split=split_table, header=name, description=desc, script=script, div=div,
ticker=ticker, updated = moddate())
9,045 changes: 9,045 additions & 0 deletions candleget.csv

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions candleget.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Apple Inc (AAPL) Prices, Dividends, Splits and Trading Volume
End of day open, high, low, close and volume, dividends and splits, and split/dividend adjusted open, high, low close and volume for Apple Inc. (AAPL). Ex-Dividend is non-zero on ex-dividend dates. Split Ratio is 1 on non-split dates. Adjusted prices are calculated per CRSP (<a href="http://www.crsp.com/products/documentation/crsp-calculations" rel="nofollow" target="blank">www.crsp.com/products/documentation/crsp-calculations</a>)

<p>This data is in the public domain. You may copy, distribute, disseminate or include the data in other products for commercial and/or noncommercial purposes.</p>
<p>This data is part of Quandl's Wiki initiative to get financial data permanently into the public domain. Quandl relies on users like you to flag errors and provide data where data is wrong or missing. Get involved: <a href="mailto:[email protected]" rel="nofollow" target="blank">[email protected]</a>
4 changes: 2 additions & 2 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bricdatascience import app

if __name__ == "__main__":
app.run(host='0.0.0.0')
# app.run(host='0.0.0.0', debug=True)
# app.run(host='0.0.0.0')
app.run(host='0.0.0.0', debug=True)

0 comments on commit c0dff55

Please sign in to comment.