Beispiel #1
0
def five_year_check(stockTicker):
    """Figure out if a stock has risen or been created within the last five years.

    Args:
        stockTicker(str): Symbol of the stock we're querying

    Returns:
        True if the stock's current price is higher than it was five years ago, or the stock IPO'd within the last five years
        False otherwise
    """
    instrument = r.get_instruments_by_symbols(stockTicker)
    if(instrument is None or len(instrument) == 0):
        return True
    list_date = instrument[0].get("list_date")
    if ((pd.Timestamp("now") - pd.to_datetime(list_date)) < pd.Timedelta("5 Y")):
        return True
    fiveyear =  get_historicals(stockTicker, "day", "5year", "regular")
    if (fiveyear is None or None in fiveyear):
        return True
    closingPrices = []
    for item in fiveyear:
        closingPrices.append(float(item['close_price']))
    recent_price = closingPrices[len(closingPrices) - 1]
    oldest_price = closingPrices[0]
    return (recent_price > oldest_price)
Beispiel #2
0
def get_position_creation_date(symbol, holdings_data):
    """Returns the time at which we bought a certain stock in our portfolio

    Args:
        symbol(str): Symbol of the stock that we are trying to figure out when it was bought
        holdings_data(dict): dict returned by r.get_open_stock_positions()

    Returns:
        A string containing the date and time the stock was bought, or "Not found" otherwise
    """
    instrument = r.get_instruments_by_symbols(symbol)
    url = instrument[0].get('url')
    for dict in holdings_data:
        if(dict.get('instrument') == url):
            return dict.get('created_at')
    return "Not found"
Beispiel #3
0
 def test_instruments(self):
     quote = r.get_instruments_by_symbols(self.single_stock)
     assert (len(quote) == 1)
     assert (quote[0]['symbol'] == self.single_stock)
     quote = quote[0]
     assert ('id' in quote)
     assert ('url' in quote)
     assert ('quote' in quote)
     assert ('fundamentals' in quote)
     assert ('splits' in quote)
     assert ('state' in quote)
     assert ('market' in quote)
     assert ('simple_name' in quote)
     assert ('name' in quote)
     assert ('tradeable' in quote)
     assert ('tradability' in quote)
     assert ('symbol' in quote)
     assert ('bloomberg_unique' in quote)
     assert ('margin_initial_ratio' in quote)
     assert ('maintenance_ratio' in quote)
     assert ('country' in quote)
     assert ('day_trade_ratio' in quote)
     assert ('list_date' in quote)
     assert ('min_tick_size' in quote)
     assert ('type' in quote)
     assert ('tradable_chain_id' in quote)
     assert ('rhs_tradability' in quote)
     assert ('fractional_tradability' in quote)
     assert ('default_collar_fraction' in quote)
     #
     more_quotes = r.get_fundamentals(self.list_stocks, info=None)
     assert (len(more_quotes) == len(self.list_stocks))
     #
     fake_quotes = r.get_fundamentals(self.fake_stocks, info=None)
     assert (len(fake_quotes) == 1)
     assert (fake_quotes[0] == None)
Beispiel #4
0
 def returnCompanyInfo(self, symbol):
     return rs.get_instruments_by_symbols(symbol), rs.get_latest_price(
         symbol)