コード例 #1
0
ファイル: _Harami.py プロジェクト: zuongthaotn/algo-stocks
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            hasBuySignal = jModel.isBullishHarami(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow)
            hasSellSignal = jModel.isBearishHarami(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow)

            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2018-07-12T00:00:00.000000000'):
            #     t4 = jModel.isMorningStarsPattern(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)
            #     print('today - isMorningStarsPattern - ' + str(t4))
            #     print(jModel.isBlackCandlestick(self.data.Open[-3], self.data.Close[-3]))
            #     print(jModel.isBodyOver45(self.data.Body[-3], self.data.Height[-3]))
            #     print(jModel.isBodyLess35(self.data.Body[-2], self.data.Height[-2]))
            #     print(jModel.isWhiteCandlestick(self.data.Open[-1], self.data.Close[-1]))
            #     exit()

            if hasBuySignal is not False and self.orderPending is False:
                self.buy()
                self.orderPending = True

            if hasSellSignal is not False and self.orderPending is True:
                self.position.close()
                self.orderPending = False
コード例 #2
0
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            prices = self.data.Close
            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2018-01-29T00:00:00.000000000'):
            #     t4 = jModel.isBearishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)
            #     print('today - isBearishEngulfing - ' + str(t4))
            #     exit()

            the1stDayIsBlack = jModel.isBlackCandlestick(
                self.data.Open[-3], self.data.Close[-3])
            isDownTrend = jModel.isDownTrendV1(self.data.Open, self.data.Close,
                                               self.data.High, self.data.Low,
                                               self.data.Body,
                                               self.data.Height,
                                               self.data.UpShadow,
                                               self.data.LowerShadow)
            the2ndDayIsDoji = jModel.isDoji(self.data.Body[-2],
                                            self.data.Height[-2])
            todayIsShavenHead = jModel.isShavenHead(self.data.Height[-1],
                                                    self.data.UpShadow[-1])
            todayIsWhite = jModel.isWhiteCandlestick(self.data.Open[-1],
                                                     self.data.Close[-1])

            if isDownTrend is True and the2ndDayIsDoji is True and todayIsShavenHead is True and todayIsWhite is True:
                hasBuySignal = True
            else:
                hasBuySignal = False

            if hasBuySignal is not False:
                self.buy(sl=0.9 * prices[-1], tp=1.2 * prices[-1])
コード例 #3
0
    def next(self):
        if len(self.data.Volume) > 4:
            prices = self.data.Close
            opens = self.data.Open
            bodies = self.data.Body
            ups = self.data.UpShadow
            lows = self.data.LowerShadow
            height = self.data.Height
            dates = self.data.Date
            current_date = numpy.datetime_as_string(dates[-1], unit="D")

            isUmbrellaCandlestick = jModel.isUmbrellaCandlestick(
                bodies[-2], height[-2], ups[-2], lows[-2])
            isWhiteCandlestick = jModel.isWhiteCandlestick(
                opens[-1], prices[-1])
            isBlackCandlestick = jModel.isBlackCandlestick(
                opens[-1], prices[-1])
            isShavenHead = jModel.isShavenHead(height[-1], ups[-1])
            if isUmbrellaCandlestick is True and isWhiteCandlestick is True and prices[
                    -1] > prices[-2] and isShavenHead is True:
                self.buy(sl=0.9 * prices[-1], tp=1.2 * prices[-1])
                # self.buy(sl=0.9*prices[-1])
            # if isUmbrellaCandlestick is True and isBlackCandlestick is True:
            #     self.position.close()

            py_date = datetime.datetime.strptime(current_date, "%Y-%m-%d")
            week_day = py_date.weekday()
            day = py_date.day
            if day > 22 and week_day > 2:
                self.position.close()
コード例 #4
0
ファイル: Test-04.py プロジェクト: zuongthaotn/algo-stocks
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            prices = self.data.Close
            hasBuySignal = jModel.hasBuySignal(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow, self.data.Volume, self.data.Date)
            hasSellSignal = jModel.hasSellSignal(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow, self.data.Volume, self.data.Date)
            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2021-01-29T00:00:00.000000000'):
            #     t4 = jModel.isBullishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)
            #     print('today - isBullishEngulfing - ' + str(t4))
            #     print('today - isDoji - ' + str(jModel.isDoji(self.data.Body[-2], self.data.Height[-2])))
            #     print('today - isWhiteCandlestick - ' + str(jModel.isWhiteCandlestick(self.data.Open[-1], self.data.Close[-1])))
            #     print('today - isDownTrendV1 - ' + str(jModel.isDownTrendV1(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)))
            #     exit()

            if hasBuySignal is not False and self.orderPending is False:
                self.buy()
                self.orderIndex = self.orderIndex + 1
                print(
                    str(self.orderIndex) + ". Buy at " +
                    str(self.data.Date[-1]) + " by signal: " + hasBuySignal)
                self.orderPending = True

            if hasSellSignal is not False and self.orderPending is True:
                self.position.close()
                print("----------- Sell at " + str(self.data.Date[-1]) +
                      " by signal: " + hasSellSignal)
                self.orderPending = False
コード例 #5
0
ファイル: Test-05.py プロジェクト: zuongthaotn/algo-stocks
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            prices = self.data.Close
            hasBuySignal = jModel.hasCustomBuySignal(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow)
            hasSellSignal = jModel.hasCustomSellSignal(
                self.data.Open, self.data.Close, self.data.High, self.data.Low,
                self.data.Body, self.data.Height, self.data.UpShadow,
                self.data.LowerShadow)
            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2018-01-29T00:00:00.000000000'):
            #     t4 = jModel.isBearishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)
            #     print('today - isBearishEngulfing - ' + str(t4))
            #     exit()

            if hasBuySignal is not False and self.orderPending is False:
                self.buy()
                self.orderIndex = self.orderIndex + 1
                print(
                    str(self.orderIndex) + ". Buy at " +
                    str(self.data.Date[-1]) + " by signal: " +
                    str(hasBuySignal))
                self.orderPending = True

            if hasSellSignal is not False and self.orderPending is True:
                self.position.close()
                print("----------- Sell at " + str(self.data.Date[-1]) +
                      " by signal: " + str(hasSellSignal))
                self.orderPending = False
コード例 #6
0
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            hasHammerSignal = jModel.isHammerModel(self.data.Open, self.data.Close, self.data.High, self.data.Low,
                                            self.data.Body, self.data.Height, self.data.UpShadow,
                                            self.data.LowerShadow)
            hasHangingManSignal = jModel.isHangingManModel(self.data.Open, self.data.Close, self.data.High, self.data.Low,
                                                 self.data.Body, self.data.Height, self.data.UpShadow,
                                                 self.data.LowerShadow)

            if hasHammerSignal is not False and self.orderPending is False:
                self.buy()
                self.orderPending = True

            if hasHangingManSignal is not False and self.orderPending is True:
                self.position.close()
                self.orderPending = False
コード例 #7
0
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            hasBuySignal = jModel.isBullishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low,
                                            self.data.Body, self.data.Height, self.data.UpShadow,
                                            self.data.LowerShadow)
            hasSellSignal = jModel.isBearishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low,
                                                 self.data.Body, self.data.Height, self.data.UpShadow,
                                                 self.data.LowerShadow)

            if hasBuySignal is not False and self.orderPending is False:
                self.buy()
                self.orderPending = True

            if hasSellSignal is not False and self.orderPending is True:
                self.position.close()
                self.orderPending = False
コード例 #8
0
    def next(self):
        if len(self.data.Volume) > 4:
            prices = self.data.Close
            opens = self.data.Open
            bodies = self.data.Body
            ups = self.data.UpShadow
            lows = self.data.LowerShadow
            height = self.data.Height
            dates = self.data.Date

            prevDayIsSpinningTopCandlestick = jModel.isSpinningTopCandlestick(
                bodies[-2], height[-2], ups[-2], lows[-2])
            prevDayIsBlackCandlestick = jModel.isBlackCandlestick(
                opens[-2], prices[-2])
            prevDayIsWhiteCandlestick = jModel.isWhiteCandlestick(
                opens[-2], prices[-2])
            prevDayMaxOpenClose = opens[
                -2] if opens[-2] > prices[-2] else prices[-2]
            prevDayMinOpenClose = opens[
                -2] if opens[-2] < prices[-2] else prices[-2]

            todayIsWhiteCandlestick = jModel.isWhiteCandlestick(
                opens[-1], prices[-1])
            todayIsBlackCandlestick = jModel.isBlackCandlestick(
                opens[-1], prices[-1])
            todayMaxOpenClose = opens[
                -1] if opens[-1] > prices[-1] else prices[-1]
            todayMinOpenClose = opens[
                -1] if opens[-1] < prices[-1] else prices[-1]

            if prevDayIsBlackCandlestick is True \
                    and prices[-1] >= opens[-2] \
                    and opens[-1] <= prices[-2] \
                    and todayIsWhiteCandlestick is True:
                # self.buy(sl=0.9*prices[-1], tp=1.2 * prices[-1])
                self.buy(sl=0.9 * prices[-1])

            if prevDayIsWhiteCandlestick is True \
                    and prices[-1] <= opens[-2] \
                    and opens[-1] >= prices[-2] \
                    and todayIsBlackCandlestick is True:
                self.position.close()

            if prevDayIsBlackCandlestick is True \
                    and ((prices[-1] <= opens[-2] and opens[-1] <= prices[-2] and todayIsBlackCandlestick is True) \
                            or prevDayMinOpenClose > todayMaxOpenClose):
                self.position.close()
コード例 #9
0
    def next(self):
        if len(self.data.Volume) > LOOK_BACK:
            prices = self.data.Close
            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2020-04-03T00:00:00.000000000'):
            #     print('yesterday - isShavenBottom - ' + str(jModel.isShavenBottom(self.data.Height[-2], self.data.LowerShadow[-2])))
            #     print('today - isShavenHead - ' + str(jModel.isShavenHead(self.data.Height[-1], self.data.UpShadow[-1])))
            #     print('today - isWhiteCandlestick - ' + str(jModel.isWhiteCandlestick(self.data.Open[-1], self.data.Close[-1])))
            #     exit()

            hasBuySignal = jModel.hasCustomBuySignal(self.data.Open, self.data.Close, self.data.High, self.data.Low,
                                                     self.data.Body, self.data.Height, self.data.UpShadow,
                                                     self.data.LowerShadow, 3)

            if hasBuySignal is not False:
                self.buy(sl=0.9 * prices[-1], tp=1.2 * prices[-1])
コード例 #10
0
    close = ticker_data['matchedPrice']
    highest = ticker_data['highest']
    lowest = ticker_data['lowest']
    total_height = highest - lowest
    body = abs(close - open)
    head = _upf(close, open, highest)
    tail = _botf(close, open, lowest)
    price = close / 1000

    if open == close:
        """ Today is a doji candlestick """
        ch = datetime.now().strftime("%H")
        if int(ch) < 14:
            continue
        history_ticker_data = stockHistory.getStockHistoryData(ticker)
        htd = jModel.convertToJapanCandle(history_ticker_data)
        _close = htd.Close.to_numpy()
        isDownTrend = jModel.isDownTrendV2ByRSI(_close)
        if isDownTrend is True:
            selectedTickers.append(ticker)
            message += ticker + "(" + str(price) + ")\n"
    elif open < close:
        """ Today is a white candlestick """
        go_pass = False
        # ----------------------------------------------------------------------------------------------
        isHammer = jModel.isHammer(body, total_height, head, tail)
        isSpinningTopCandlestick = jModel.isSpinningTopCandlestick(
            body, total_height, head, tail)
        isShavenHead = jModel.isShavenHead(total_height, head)
        isShavenBottom = jModel.isShavenBottom(total_height, tail)
        isBigBody = jModel.isBigBody(body, total_height, open, close)
コード例 #11
0
ファイル: _Harami.py プロジェクト: zuongthaotn/algo-stocks
                self.data.LowerShadow)

            # if np.datetime64(self.data.Date[-1]) == np.datetime64('2018-07-12T00:00:00.000000000'):
            #     t4 = jModel.isMorningStarsPattern(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow)
            #     print('today - isMorningStarsPattern - ' + str(t4))
            #     print(jModel.isBlackCandlestick(self.data.Open[-3], self.data.Close[-3]))
            #     print(jModel.isBodyOver45(self.data.Body[-3], self.data.Height[-3]))
            #     print(jModel.isBodyLess35(self.data.Body[-2], self.data.Height[-2]))
            #     print(jModel.isWhiteCandlestick(self.data.Open[-1], self.data.Close[-1]))
            #     exit()

            if hasBuySignal is not False and self.orderPending is False:
                self.buy()
                self.orderPending = True

            if hasSellSignal is not False and self.orderPending is True:
                self.position.close()
                self.orderPending = False


DATA_PATH = os.path.abspath('../../vn-stock-data/VNX/')
ticker_id = 'VRE'
ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id + '.csv',
                                      '2018-01-01')
new_data = jModel.convertToJapanCandle(ticker_data)
bt = Backtest(ticker_data, Harami, commission=.005, exclusive_orders=False)
stats = bt.run()
print(stats)
# print(stats['_trades'])
bt.plot()
コード例 #12
0
import os
import sys
METHOD_MODULE_PATH = os.path.abspath('../..')
sys.path.insert(1, METHOD_MODULE_PATH)
import method.algofuncs as _af
import method.JavCan as jModel

DATA_PATH = os.path.abspath('../../vn-stock-data/VNX/')
# vn30_ticker = _af.getListVN30()
vnx_file = os.path.abspath('../../vn-stock-data/VNX.csv')
hose_ticker = _af.getHOSETickers(vnx_file)

for ticker_id in hose_ticker:
    ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id + '.csv',
                                          '2021-07-01')
    _1hit_data = ticker_data.tail(3)
    new_data = jModel.convertToJapanCandle(_1hit_data)
    prices = new_data.Close
    opens = new_data.Open
    bodies = new_data.Body
    ups = new_data.UpShadow
    lows = new_data.LowerShadow
    height = new_data.Height

    isUmbrellaCandlestick = jModel.isUmbrellaCandlestick(
        bodies[-2], height[-2], ups[-2], lows[-2])
    isWhiteCandlestick = jModel.isWhiteCandlestick(opens[-1], prices[-1])
    if isUmbrellaCandlestick is True and isWhiteCandlestick is True and prices[
            -1] > prices[-2]:
        print(ticker_id)
コード例 #13
0
    if len(ticker) != 3:
        continue
    _volume = ticker_data['nmTotalTradedQty']
    _minVol = getMinVolumeByTime()
    if type(_volume) is not int or _volume < _minVol:
        continue
    open = ticker_data['openPrice']
    close = ticker_data['matchedPrice']
    highest = ticker_data['highest']
    lowest = ticker_data['lowest']
    total_height = highest - lowest
    body = abs(close - open)
    head = _upf(close, open, highest)
    tail = _botf(close, open, lowest)

    condition1 = True if tail > 0.65 * total_height else False
    condition2 = True if total_height > 0.05 * close else False
    # today has a long tail
    if condition1 is True:
        # print(ticker)
        if condition2 is True:
            # print(ticker)
            history_ticker_data = stockHistory.getStockHistoryData(
                ticker)  # not include today data
            # # print(history_ticker_data)
            htd = jModel.convertToJapanCandle(history_ticker_data)
            _close = htd.Close.to_numpy()
            isDownTrend = jModel.isDownTrendV2ByRSI(_close)
            if isDownTrend is True:
                # print(ticker)
                sendTelegramMessage(ticker)
コード例 #14
0
import warnings

warnings.filterwarnings('ignore')

import os
import sys

METHOD_MODULE_PATH = os.path.abspath('../..')
sys.path.insert(1, METHOD_MODULE_PATH)
import method.algofuncs as _af
import method.JavCan as jModel

DATA_PATH = os.path.abspath('../../vn-stock-data/VNX/')
hold_tickers = ['ABB', 'ACB', 'BSR', 'FPT', 'GMD', 'OCB', 'PVS', 'PVT', 'STB', 'TPB', 'VCI', 'VHG', 'VND', 'VGT']
printedDate = False
for ticker_id2 in hold_tickers:
    ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id2 + '.csv', '2021-05-01')
    if printedDate == False:
        print(ticker_data.Date[-1])
        printedDate = True
    _1hit_data = ticker_data.tail(10)
    new_data = jModel.convertToJapanCandle(_1hit_data)
    hasSellSignal = jModel.hasCustomSellSignal(new_data.Open, new_data.Close, new_data.High, new_data.Low,
                                         new_data.Body, new_data.Height, new_data.UpShadow,
                                         new_data.LowerShadow, new_data.Date)
    if hasSellSignal is not False:
        print(ticker_id2 + ' -- ' + str(hasSellSignal))
        # print(jModel.isBlackCandlestick(new_data.Open[-3], new_data.Close[-3]))
        # print(jModel.isBlackCandlestick(new_data.Open[-2], new_data.Close[-2]))
        # print(jModel.isBlackCandlestick(new_data.Open[-1], new_data.Close[-1]))
コード例 #15
0
    ticker = ticker_data['stockSymbol']
    if len(ticker) != 3:
        continue
    _volume = ticker_data['nmTotalTradedQty']
    if type(_volume) is not int or _volume < 500000:
        continue
    # _open = ticker_data['openPrice']
    # _close = ticker_data['matchedPrice']
    # _highest = ticker_data['highest']
    # _lowest = ticker_data['lowest']
    # _height = _highest - _lowest
    # _body = abs(_close - _open)
    # _up = _upf(_close, _open, _highest)
    # _bot = _botf(_close, _open, _lowest)

    condition = jModel.isWhiteCandlestick(ticker_data['openPrice'],
                                          ticker_data['matchedPrice'])
    # today is a white candlestick
    if condition is True:
        # print(ticker)
        history_ticker_data = stockHistory.getStockHistoryData(
            ticker)  # not include today data
        # print(history_ticker_data)
        htd = jModel.convertToJapanCandle(history_ticker_data)
        _open = htd.Open.to_numpy()
        _close = htd.Close.to_numpy()
        _highest = htd.High.to_numpy()
        _lowest = htd.Low.to_numpy()
        _height = htd.Height.to_numpy()
        _body = htd.Body.to_numpy()
        _up = htd.UpShadow.to_numpy()
        _bot = htd.LowerShadow.to_numpy()
コード例 #16
0
ファイル: testHammer.py プロジェクト: zuongthaotn/algo-stocks
import sys
import numpy as np
from datetime import datetime

METHOD_MODULE_PATH = os.path.abspath('../..')
sys.path.insert(1, METHOD_MODULE_PATH)
import method.JavCan as jModel
import vn_realtime_stock_data.stockHistory as stockHistory

ticker = 'HPG'
# print(ticker)
history_ticker_data = stockHistory.getStockHistoryData(ticker)  # not include today data
# print(history_ticker_data)
# exit()
# print(history_ticker_data)
htd = jModel.convertToJapanCandle(history_ticker_data)
print(htd)
# _open = htd.Open.to_numpy()
# _close = htd.Close.to_numpy()
# _highest = htd.High.to_numpy()
# _lowest = htd.Low.to_numpy()
# _height = htd.Height.to_numpy()
# _body = htd.Body.to_numpy()
# _up = htd.UpShadow.to_numpy()
# _bot = htd.LowerShadow.to_numpy()
# _time = htd.Time.to_numpy()
#
# for idx, x in np.ndenumerate(_open):
#   # _iuc = jModel.isHammer(_body[idx], _height[idx], _up[idx], _bot[idx])
#   if _bot[idx] > 0.6 * _height[idx]:
#   # if _iuc is True:
コード例 #17
0
import method.JavCan as jModel

ticker_id = 'VRE'
DATA_PATH = os.path.abspath('../vn-stock-data/VNX/')
ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id + '.csv', '2019-01-01')



# print(ticker_data)
# print(len(ticker_data.index))
# print(ticker_data[0:5])
# print(ticker_data.size)
# exit()


d2 = jModel.convertToJapanCandle(ticker_data)
for index, row in d2.iterrows():
    # print(row['Open'])
    # isHammer = jModel.isHammer(row['Open'], row['Close'], row['Body'], row['Height'], row['UpShadow'], row['LowerShadow'])
    # if isHammer is True:
    #     print(index)
    if np.datetime64(row['Date']) == np.datetime64('2019-01-04T00:00:00.000000000'):
        isHammer = jModel.isDoji(row['Body'], row['Height'])
        print(isHammer)


# last = 0
# np_ticker_data = ticker_data.to_numpy()
# data_len = len(ticker_data.index)
# for i in range(data_len):
#     if i > 2: