Exemplo n.º 1
0
def stock_chart(ticker):
    title = "Stock Chart"
    symbol = ticker.upper()
    chartname = ticker
    symbols = stockdb.getSymbols(DATABASE_URL)
    name = [n for s, n in symbols if s == symbol]
    if (len(name) > 0):
        chartname = name[0]
    df = stockdb.getSymbolData(symbol, DATABASE_URL)
    if df is not None:
        df20 = df.iloc[-20:]
        df40 = df.iloc[-40:]
        df60 = df.iloc[-60:]
        div = stockdb.getPlot(symbol, chartname, [df, df20, df40, df60])
        return render_template('stock.html',
                               title=title,
                               chart=div,
                               symbols=symbols,
                               annotation='Source: Yahoo Finance')
    else:
        return render_template('stock.html',
                               title=title,
                               chart=str.format('No Data For Ticker {}',
                                                symbol),
                               annotiation='Source: Yahoo Finance')
Exemplo n.º 2
0
def reset_request(resetid):
    symbols = stockdb.getSymbols(DATABASE_URL)

    userRequestReset, email = userdb.getResetRequest(DATABASE_URL, resetid)
    if userRequestReset:
        return render_template('changepass.html',
                               resetid=resetid,
                               email=email,
                               symbols=symbols)
    else:
        return redirect(url_for('get_index'))
Exemplo n.º 3
0
def reset():
    symbols = stockdb.getSymbols(DATABASE_URL)
    if request.method == 'GET':
        return render_template('reset.html', symbols=symbols)
    userConfirmed, confirmationid, id = userdb.userConfirmed(
        DATABASE_URL, request.form['email'])
    if userConfirmed:
        resetid = str(uuid.uuid4()).replace('-', '')
        userdb.setUserAccountToReset(DATABASE_URL, id, resetid)
        emailing.sendResetEmail(request.form['email'], resetid)
    flash('Reset email on its way!')
    return redirect(url_for('reset'))
Exemplo n.º 4
0
def plot_correlation():
    if 'ticker' not in request.form:
        flash('No Assets Chosen')
        return redirect(url_for('get_correlation'))
    tickers = request.form.getlist('ticker')
    if len(tickers) < 2:
        flash('Choose at least two stocks.')
        return redirect(url_for('get_correlation'))
    symbols = stockdb.getSymbols(DATABASE_URL)
    if len(tickers) > 0:
        df = stockdb.getPortfolioPrices(tickers, DATABASE_URL)
        scatter = stockdb.plotScatter(df, 800, 800)
        return render_template('corr.html',
                               symbols=symbols,
                               title='Asset Correlation',
                               scatter=scatter,
                               annotation='Source: Future Trends Consulting')
Exemplo n.º 5
0
def register():
    symbols = stockdb.getSymbols(DATABASE_URL)
    confirmationid = str(uuid.uuid4()).replace('-', '')

    if request.method == 'GET':
        return render_template('register.html', symbols=symbols)
    if request.form['password'] != request.form['passwordconfirm']:
        flash("Passwords don't match")
        return redirect(url_for('register'))
    if userdb.createUser(DATABASE_URL, request.form['email'],
                         request.form['password'], confirmationid):
        emailing.sendWelcomeEmail(request.form['email'], confirmationid)
        flash("Email confirmation on its way!")
        return redirect(url_for('signin'))
    else:
        flash("User email already registered.")
        return redirect(url_for('register'))
Exemplo n.º 6
0
def signin():
    symbols = stockdb.getSymbols(DATABASE_URL)
    if request.method == 'GET':
        return render_template('signin.html', symbols=symbols)
    email = request.form['email']
    userConfirmed, confirmationid, _ = userdb.userConfirmed(
        DATABASE_URL, email)
    if not userConfirmed:
        flash(
            'Account unconfirmed. Please check your email for confirmation link.'
        )
        return redirect(url_for('signin'))
    if userdb.authenticateUser(DATABASE_URL, email, request.form['password']):
        user = userdb.User()
        user.id = email
        flask_login.login_user(user)
        return redirect(url_for('get_index'))
    flash('Bad login')
    return redirect(url_for('signin'))
Exemplo n.º 7
0
def plot_portfolio():
    if 'ticker' not in request.form:
        flash('No Portfolio Chosen')
        return redirect(url_for('get_portfolio'))
    tickers = request.form.getlist('ticker')
    symbols = stockdb.getSymbols(DATABASE_URL)
    if len(tickers) > 0:
        df = stockdb.getPortfolioPrices(tickers, DATABASE_URL)
        traces = stockdb.createTraces(df / df.iloc[0])
        div = stockdb.plotTraces(traces, 'Returns', 'Date', 'Return', 800)
        vol_arr, ret_arr, sharpe_arr, max_sr_vol, max_sr_ret = stockdb.monteCarloPortfolios(
            df, 1000)
        divfr = stockdb.frontierPlot(vol_arr, ret_arr, sharpe_arr, 500, 800,
                                     max_sr_vol, max_sr_ret)
        allocations = stockdb.getOptimalAllocation(df)
        return render_template(
            'portfolio.html',
            symbols=symbols,
            title='Portfolio Analysis',
            chart=div,
            frontier=divfr,
            allocations=[a for a in allocations if a[1] > 0],
            annotation='Source: Future Trends Consulting')
Exemplo n.º 8
0
def get_index():
    symbols = stockdb.getSymbols(DATABASE_URL)
    return render_template('index.html', symbols=symbols)
Exemplo n.º 9
0
def portfoliomgr():
    symbols = stockdb.getSymbols(DATABASE_URL)
    return render_template('portfoliomgr.html', symbols=symbols)
Exemplo n.º 10
0
def symbols():
    return json.dumps(stockdb.getSymbols(DATABASE_URL))
Exemplo n.º 11
0
def get_portfolio():
    symbols = stockdb.getSymbols(DATABASE_URL)
    return render_template('portfolio.html',
                           symbols=symbols,
                           title='Portfolio Analysis')
Exemplo n.º 12
0
def get_correlation():
    symbols = stockdb.getSymbols(DATABASE_URL)
    return render_template('corr.html',
                           symbols=symbols,
                           title='Asset Correlation')