Ejemplo n.º 1
0
def getHistoricEMA(ticker: str,
                   sampleSize: int = 25,
                   returnPrice: bool = False,
                   closeData: list = []):
    '''
    returns a list of a exponential moving avarage (equal weighted)

    * The list used should be shifted forward @param sampleSize times, since EMA is not calculated for those
    * if @param returnPrice is true, this will return a tuple containing the SMA and the current price (mostly used for comparison)
    '''
    if len(closeData) != 0:
        stockData = closeData
    else:
        stockData = IM.getCandle(ticker, timeframe="Y",
                                 quality="high").get("c")

    mult = 2 / (sampleSize + 1)
    ema = []
    for i in range(sampleSize - 1, len(stockData)):
        if len(ema) == 0:
            # Calculate inital SMA value
            ema.append(sum(stockData[i - sampleSize + 1:i]) / sampleSize)
        else:
            # Calculate todays EMA, based on yesterdays EMA
            ema.append(((stockData[i] - ema[len(ema) - 1]) * mult) +
                       ema[len(ema) - 1])

    if returnPrice:
        return ema, stockData[-1]
    return ema
Ejemplo n.º 2
0
def getCurrentSMA(ticker: str,
                  sampleSize: int = 25,
                  returnPrice: bool = False,
                  closeData: list = []):
    '''
    returns the current simple avarage with @param sampleSize days

    * if @param returnPrice is true, this will return a tuple containing the SMA and the current price (mostly used for comparison)
    '''
    if len(closeData) != 0:
        stockData = closeData
    else:
        stockData = IM.getCandle(ticker, timeframe="Y",
                                 quality="high").get("c")

    stockData = stockData[-sampleSize - 1:]

    sma = 0
    for i in range(0, len(stockData) - sampleSize):
        sma = (sum(stockData[i:i + sampleSize]) / sampleSize)

    if returnPrice:
        return round(sma, 2), stockData[-1]
    else:
        return round(sma, 2)
Ejemplo n.º 3
0
 def __init__(self, bot, project_system):
     # _info is the main point of access for anything specific to a project (e.g. urls, triggers, keywords).
     self._info = InfoManager.ProjectSystemInfoManager(project_system)
     # Use _bot to interact with the user (e.g. ask a question, clarify between options, acknowledge keywords).
     self._bot = bot
     
     # Maps an intent to a function.
     self._STRATAGIES = {
         'Get Help': self._get_help,
         'undefined': self._undefined
     }
Ejemplo n.º 4
0
def getCurrentTrend(ticker: str, weeksBack: int = 1, closeData: list = []):
    '''
    returns the current trend for @param weeksBack in precentage
    '''
    if len(closeData) != 0:
        stockData = closeData
    else:
        stockData = IM.getCandle(ticker, timeframe="Y",
                                 quality="high").get("c")

    priceDiff = stockData[-1] - stockData[-weeksBack * 7]
    diffPrecentage = (priceDiff / stockData[-weeksBack * 7]) * 100
    return round(diffPrecentage, 3)
Ejemplo n.º 5
0
def getHistoricSMA(ticker: str, sampleSize: int = 25, closeData: list = []):
    '''
    returns a list of a simple moving avarage (equal weighted)

    * The list used should be shifted forward @param sampleSize times, since SMA is not calculated for those
    '''
    if len(closeData) != 0:
        stockData = closeData
    else:
        stockData = IM.getCandle(ticker, timeframe="Y",
                                 quality="high").get("c")
    sma = []
    for i in range(0, len(stockData) - sampleSize):
        sma.append(sum(stockData[i:i + sampleSize]) / sampleSize)
    return sma
Ejemplo n.º 6
0
def test():
    ticker = 'AAPL'
    normalStockY = IM.getCandle(ticker, timeframe="Y", quality="high").get("c")
    normalStockX = [x for x in range(len(normalStockY))]

    sampleSize = 30
    smaY = getHistoricSMA(ticker, sampleSize)
    smaX = [x + sampleSize for x in range(len(smaY))]

    emaY = getHistoricEMA(ticker, sampleSize)
    emaX = [x + sampleSize for x in range(len(emaY))]

    plt.plot(normalStockX, normalStockY)
    plt.plot(smaX, smaY)
    plt.plot(emaX, emaY)
    print(getCurrentEMA("AAPL", sampleSize), emaY[-1])
    plt.show()
Ejemplo n.º 7
0
def getWikiArticle(ticker: str) -> str:
    '''
    returns a wikipedia article about the stock ticker. If it cant find a article, it gives an article about the stock market
    '''
    name = IM.getName(ticker)
    defaultArticle = "https://en.m.wikipedia.org/wiki/Stock_market"
    if name == ticker:
        return defaultArticle
    else:
        quary = name
    url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search="{}"&limit=1&format=json'.format(
        quary)

    try:
        wikilink = requests.get(url).json()[-1][0].replace("en.", "en.m.")
    except Exception:
        return defaultArticle
    return wikilink
Ejemplo n.º 8
0
    info = info.readlines()
    infobox = []
    for i in info:
        temp = i.replace('\n', '')
        temp = temp.replace('\t', '')
        temp = temp.split('_')
        heading = int(temp[1])
        heading = heading % 90
        temp[1] = heading
        temp = tuple(temp)
        infobox.append(temp)
        # DB.savein_tuple("Beijing",temp)
    DB.update_list(CITYname, infobox)

#连接数据库
test = InfoManager("test_"+city_name+".db")
#支持给出目录绝对地址,之后在目录下链接数据库(无则创建)
#支持在当前目录下连接数据库(无则创建)
#支持给出数据库绝对地址,无则失败

#在数据库内创建表单
test.creNewTable(city_name)

#在表单city_name中从source文件中载入数据
#create(city_name,source,test)

#删除数据库中的表单city_name(表单内的数据消失,不可恢复)
#test.dropTable(city_name)

#在表单city_name中在经纬度范围内搜索数据,返回值为list,包含的元素为元组,包含满足条件点的所有信息
#r = test.selectByRange(city_name,(23.1,23.3),(113.70,113.79))