コード例 #1
0
ファイル: momentum.py プロジェクト: venkiiee/ta
class TestTSIIndicator(unittest.TestCase):
    """
    https://school.stockcharts.com/doku.php?id=technical_indicators:true_strength_index
    """

    _filename = 'ta/tests/data/cs-tsi.csv'

    def setUp(self):
        self._df = pd.read_csv(self._filename, sep=',')
        self._indicator = TSIIndicator(close=self._df['Close'], r=25, s=13, fillna=False)

    def tearDown(self):
        del(self._df)

    def test_kama(self):
        target = 'TSI'
        result = self._indicator.tsi()
        pd.testing.assert_series_equal(
            self._df[target].tail(), result.tail(), check_names=False, check_less_precise=True)
コード例 #2
0
ファイル: routes.py プロジェクト: jande48/StockData
def calculate_Momentum_Indicators():

    JSON_sent = request.get_json()
    df = pd.DataFrame(JSON_sent[0])

    _, RSI, TSI, UO, STOCH, STOCH_SIGNAL, WR, AO, KAMA, ROC = JSON_sent

    indicator_RSI = RSIIndicator(close=df["close"], n=RSI['N'])
    df['rsi'] = indicator_RSI.rsi()

    if TSI['displayTSI']:
        indicator_TSI = TSIIndicator(close=df["close"],
                                     r=TSI['rTSI'],
                                     s=TSI['sTSI'])
        df['tsi'] = indicator_TSI.tsi()

    if UO['displayUO']:
        indicator_UO = uo(high=df['high'],
                          low=df['low'],
                          close=df['close'],
                          s=UO['sForUO'],
                          m=UO['mForUO'],
                          len=UO['lenForUO'],
                          ws=UO['wsForUO'],
                          wm=UO['wmForUO'],
                          wl=UO['wlForUO'])
        df['uo'] = indicator_UO

    if STOCH['displaySTOCH']:
        indicator_Stoch = stoch(high=df['high'],
                                low=df['low'],
                                close=df['close'],
                                n=STOCH['nForSTOCH'],
                                d_n=STOCH['dnForSTOCH'])
        df['stoch'] = indicator_Stoch

    if STOCH_SIGNAL['displayStochSignal']:
        indicator_StochSignal = stoch_signal(
            high=df['high'],
            low=df['low'],
            close=df['close'],
            n=STOCH_SIGNAL['nForStochSignal'],
            d_n=STOCH_SIGNAL['dnForStochSignal'])
        df['stoch_signal'] = indicator_StochSignal

    if WR['displayWR']:
        indicator_wr = wr(high=df['high'],
                          low=df['low'],
                          close=df['close'],
                          lbp=WR['lbpForWR'])
        df['wr'] = indicator_wr

    if AO['displayAO']:
        indicator_ao = ao(high=df['high'],
                          low=df['low'],
                          s=AO['sForAO'],
                          len=AO['lenForAO'])
        df['ao'] = indicator_ao

    if KAMA['displayKama']:
        indicator_kama = kama(close=df['close'],
                              n=KAMA['nForKama'],
                              pow1=KAMA['pow1ForKama'],
                              pow2=KAMA['pow2ForKama'])
        df['kama'] = indicator_kama

    if ROC['displayROC']:
        indicator_roc = roc(close=df['close'], n=ROC['nForROC'])
        df['roc'] = indicator_roc

    df.fillna(0, inplace=True)
    export_df = df.drop(columns=['open', 'high', 'low', 'close', 'volume'])
    return (json.dumps(export_df.to_dict('records')))