Ejemplo n.º 1
0
            # price is increased
            if last_price > self.trailing_price:
                self.trailing_price = last_price

            if self.buy_price == 0 and Ticker.isFollowTrendingV2(
                    prices, volumes, opens[-1], 2.5):
                self.buy_price = last_price
                self.buy()
            if self.buy_price != 0:
                if _sr.takeProfitByPercent(
                        15, last_price,
                        self.buy_price) or last_price < self.buy_price * (
                            1 - STOPLOSS
                        ) or last_price < self.trailing_price * (1 - STOPLOSS):
                    self.position.close()
                    self.buy_price = 0
                    self.trailing_price = 0


ticker_id = 'HBC'
DATA_PATH = os.path.abspath('../../vn-stock-data/VNX/')
ticker = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id + '.csv',
                                 '2010-01-01', '2020-10-05')
bt = Backtest(ticker, FollowTheTrend, commission=.005, exclusive_orders=False)
stats = bt.run()
# bt.plot()
print(stats)
# print(stats['_trades'])
# new_file = path+"/result_"+ticker_id+".csv"
# stats['_trades'].to_csv(new_file, index=False)
Ejemplo n.º 2
0
                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()
Ejemplo n.º 3
0
import os
import sys
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

METHOD_MODULE_PATH = os.path.abspath('..')
sys.path.insert(1, METHOD_MODULE_PATH)
import method.SaleRules as _sr
import method.algofuncs as _af

DATA_PATH = os.path.abspath('../vn-stock-data/VNX/')
ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + 'KOS.csv',
                                      start_date='2020-10-01')

mmi_week = _af.MMI(ticker_data["Close"], 5)
plt.figure()
plt.subplot(211)
plt.plot(ticker_data["Close"], label='Close Price', color='black')
plt.subplot(212)
plt.plot(mmi_week, label='MMI Week')
plt.legend()
plt.show()

# plt.figure()
# plt.subplot(211)
# Vol = _af.getVolatility(ticker_data["Close"], 252)
# # Vol2 = ticker_data["High"] - ticker_data["Low"]
# plt.plot(ticker_data["Close"], label='Close Price', color='black')
# plt.plot(ticker_data["High"], label='High Price')
# plt.plot(ticker_data["Low"], label='Low Price')