|
| 1 | +from flask import Flask ,render_template |
| 2 | + |
| 3 | +app=Flask(__name__) |
| 4 | +@app.route('/plot/') |
| 5 | +def plot(): |
| 6 | + import pandas as pd |
| 7 | + pd.core.common.is_list_like = pd.api.types.is_list_like |
| 8 | + from pandas_datareader import data |
| 9 | + import datetime |
| 10 | + import fix_yahoo_finance as yf |
| 11 | + yf.pdr_override() |
| 12 | + from bokeh.plotting import figure, show, output_file |
| 13 | + from bokeh.embed import components |
| 14 | + from bokeh.resources import CDN |
| 15 | + |
| 16 | + start=datetime.datetime(2015,11,1) |
| 17 | + end=datetime.datetime(2016,3,10) |
| 18 | + |
| 19 | + df=data.get_data_yahoo(tickers="GOOG", start=start, end=end) |
| 20 | + |
| 21 | + |
| 22 | + def inc_dec(c, o): |
| 23 | + if c > o: |
| 24 | + value="Increase" |
| 25 | + elif c < o: |
| 26 | + value="Decrease" |
| 27 | + else: |
| 28 | + value="Equal" |
| 29 | + return value |
| 30 | + |
| 31 | + df["Status"]=[inc_dec(c,o) for c, o in zip(df.Close,df.Open)] |
| 32 | + df["Middle"]=(df.Open+df.Close)/2 |
| 33 | + df["Height"]=abs(df.Close-df.Open) |
| 34 | + |
| 35 | + p=figure(x_axis_type='datetime', width=1000, height=300) |
| 36 | + p.title.text="Candlestick Chart" |
| 37 | + p.grid.grid_line_alpha=0.3 |
| 38 | + |
| 39 | + hours_12=12*60*60*1000 |
| 40 | + |
| 41 | + p.segment(df.index, df.High, df.index, df.Low, color="Black") |
| 42 | + |
| 43 | + p.rect(df.index[df.Status=="Increase"],df.Middle[df.Status=="Increase"], |
| 44 | + hours_12, df.Height[df.Status=="Increase"],fill_color="#CCFFFF",line_color="black") |
| 45 | + |
| 46 | + p.rect(df.index[df.Status=="Decrease"],df.Middle[df.Status=="Decrease"], |
| 47 | + hours_12, df.Height[df.Status=="Decrease"],fill_color="#FF3333",line_color="black") |
| 48 | + |
| 49 | + script1, div1 = components(p) |
| 50 | + cdn_js=CDN.js_files[0] |
| 51 | + cdn_css=CDN.css_files[0] |
| 52 | + return render_template("plot.html", |
| 53 | + script1=script1, |
| 54 | + div1=div1, |
| 55 | + cdn_css=cdn_css, |
| 56 | + cdn_js=cdn_js ) |
| 57 | +@app.route('/') |
| 58 | +def home(): |
| 59 | + return render_template("homepage.html") |
| 60 | + |
| 61 | +@app.route('/about/') |
| 62 | +def about(): |
| 63 | + return render_template("about.html") |
| 64 | +if __name__=="__main__": |
| 65 | + print(__name__) |
| 66 | + app.run(debug=True) |
0 commit comments