Exemple #1
0
def get_rsi(
        start=datetime(2020, 1, 1),
        end=datetime(2020, 12, 31),
        brand='1305.JP',
        n=14,
):
    stooq = StooqDailyReader(brand, start=start, end=end)
    data = stooq.read()
    #input data must be pandas dataframe
    diff = data["Close"].diff()
    up = diff.copy()
    up[up < 0] = 0
    down = diff.copy()
    down[down > 0] = 0
    up_sma_14 = up.rolling(window=n, center=False).mean()

    down_sma_14 = down.abs().rolling(window=n, center=False).mean()
    RSI = (up_sma_14) / (down_sma_14 + up_sma_14)
    return RSI * 100, data["Close"]
Exemple #2
0
def update_graph(n_clicks, start_date, end_date, stock_ticker):
    #Convert passed date variables to date type since they change to string when they are paased to this function.
    start = dt.strptime(start_date[:10], '%Y-%m-%d')
    end = dt.strptime(end_date[:10], '%Y-%m-%d')
    #Create session variable for StooqDailyReader just in case if you got stuck behind company firewall.
    session = requests.Session()
    session.verify = False
    #Query each selected tick from Nasdaq and append its trace to traces list
    traces = []
    for tic in stock_ticker:
        data = StooqDailyReader(tic, start=start, end=end, session=session)
        df = data.read()
        traces.append({
            'x': df.index,
            'y': df['Close'],
            'name': tic,
            'hoverinfo': 'text',
            'text': df['Close']
        })
    #Create figure object to pass to main layout
    stocks = ['<b>' + stock + '</b>' for stock in stock_ticker]
    fig = {
        'data': traces,
        'layout': {
            'title': ', '.join(stocks) + ' Closing Prices',
            'hovermode': 'closest',
            'xaxis': {
                'title': 'Time',
                'showline': True
            },
            'yaxis': {
                'title': 'Price (USD)',
                'showline': True
            }
        }
    }
    return fig