コード例 #1
0
 def test_datatypes(self):
     dataset = obtain_ohlc_data('MSFT')
     period: int = 12
     ma_ohlc, sig_cols = MovingAverage(period,
                                       MAType.ema).get_signal(dataset)
     self.assertEqual(
         type(ma_ohlc.get(sig_cols)['ma_period_' + str(period)][0]),
         np.float64)
コード例 #2
0
    def test_ma_visualization(self):
        dataset = obtain_ohlc_data('MSFT')[:300]
        period: int = 7
        ma_ohlc, sig_cols = MovingAverage(dataset, period,
                                          MAType.ema).get_signal()

        plt.plot(ma_ohlc.index, ma_ohlc["Adj Close"], label="Adj Close")
        plt.plot(ma_ohlc.index, ma_ohlc["ma_period_7"], label="MA")
        plt.show()
コード例 #3
0
 def test_macd_visualization(self):
     dataset = obtain_ohlc_data('MSFT')
     macd_included_df, sig_cols = Macd(12, 26, 9).get_signal(dataset)
     # macd_included_df = (macd_included_df - macd_included_df.min()) / (macd_included_df.max() - macd_included_df.min())
     macd_included_df[['MACD', 'Signal']][:100].plot()
     plt.show()
     # macd_included_df[['Adj Close']][:100].plot()
     # plt.show()
     print(macd_included_df)
 def __init__(self, commodity: str, strategies: Dict[Strategy, float],
              risk: Dict[str, Callable[[float], float]]):
     self.ohlc_data = obtain_ohlc_data(commodity)
     self.current_trade = BHSSignal.hold
     self.current_trade_executed = True
     self.strategies = strategies
     self.strategy_signal_columns = []
     self.analytics = AnalyticsManager(commodity)
     self.risk = risk
    def test_data_driven_slope(self):
        dataset = obtain_ohlc_data('MSFT')
        df, col = Slope(dataset).get_signal()
        df = df[:20]

        plt.scatter(df.index, df[col[0]], c='r')
        plt.scatter(df.index, df[col[1]], c='g')
        plt.plot(df.index, df['Adj Close'])
        df.plot()
        plt.show()
コード例 #6
0
    def test_basic_sig_merge(self):
        ohlc_data: pd.DataFrame = obtain_ohlc_data('AAPL')
        strategies: Dict[Strategy, float] = {
            MADoubleCrossOver(1, 5, 13): 0.5,
            MADoubleCrossOver(2, 50, 200): 0.5,
        }

        ohlc_data = SignalManager(ohlc_data, strategies).get_master_signal()

        self.assertEqual(len(ohlc_data.get('master_sig')),
                         len(ohlc_data.get('open')))
    def test_scatter(self):

        df = obtain_ohlc_data('MSFT')
        df, cols = Slope(df).get_signal()

        df = df[:10]

        # Plot results
        plt.scatter(df.index, df['local_minima'], c='r')
        # plt.scatter(df.index, df['local_maxima'], c='g')
        # plt.scatter(df.index, df[cols[0]], c='b')
        df['Adj Close'].plot()
        plt.show()
コード例 #8
0
import talib
from market_data.ohlc_data import obtain_ohlc_data
import pandas as pd
from scipy.signal import lfilter

def smooth_algo(data, cnt: int = 200, smooth_intensity: int = 3):
    data = data[:cnt]
    n = smooth_intensity  # the larger n is, the smoother curve will be
    b = [1.0 / n] * n
    a = 1
    yy = lfilter(b, a, data)[n - 1:]
    return yy

symbol = "EURUSD=X"

ohlc_data = obtain_ohlc_data(symbol, include_all_indicators=True)
smoothened_data = smooth_algo(ohlc_data["Adj Close"], 4500, 2)

p_3 = smoothened_data[3:]
p_7 = smoothened_data[7:]
p_21 = smoothened_data[21:]
p_50 = smoothened_data[50:]

diff_p_3 = (p_3 - smoothened_data[:-3])[:-47]
diff_p_7 = (p_7 - smoothened_data[:-7])[:-43]
diff_p_21 = (p_21 - smoothened_data[:-21])[:-29]
diff_p_50 = (p_50 - smoothened_data[:-50])

df = pd.DataFrame()
df['P3'] = diff_p_3
df['P7'] = diff_p_7
 def get_data(self):
     return obtain_ohlc_data('EURUSD=X')["Adj Close"].to_numpy()
コード例 #10
0
from market_data.ohlc_data import obtain_ohlc_data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

dataset = obtain_ohlc_data('MSFT', include_all_indicators=True)[:]

b = dataset["Open"]

a = 9

for c in dataset.columns:
    if str(c).__contains__("CDL"):
        x = np.array(dataset["Close"])
        p = np.where(np.array(dataset[c]) == 100)[0]
        t = np.where(np.array(dataset[c]) == -100)[0]
        plt.plot(x)
        plt.plot(p, x[p], "v")
        plt.plot(t, x[t], "^")
        plt.show()
コード例 #11
0
 def test_ma_columns(self):
     dataset = obtain_ohlc_data('MSFT')
     period: int = 12
     ma_ohlc, sig_cols = MovingAverage(period,
                                       MAType.ema).get_signal(dataset)
     self.assertIn(sig_cols[0], ma_ohlc.count(axis=0).index.tolist())
コード例 #12
0
 def test_ma_count(self):
     dataset = obtain_ohlc_data('MSFT')
     ma_ohlc, sig_cols = MovingAverage(12, MAType.ema).get_signal(dataset)
     self.assertEqual(len(sig_cols), 1)
コード例 #13
0
 def test_datatypes(self):
     dataset = obtain_ohlc_data('MSFT')
     macd_included_df, sig_cols = Macd(12, 26, 9).get_signal(dataset)
     self.assertEqual(type(macd_included_df['Signal'][0]), numpy.float64)
     self.assertEqual(type(macd_included_df['MACD'][0]), numpy.float64)
コード例 #14
0
 def test_macd_columns(self):
     dataset = obtain_ohlc_data('MSFT')
     macd_included_df, sig_cols = Macd(12, 26, 9).get_signal(dataset)
     self.assertEqual(
         macd_included_df.get(sig_cols).count(axis=0).index.tolist(),
         ['MACD', 'Signal'])
コード例 #15
0
 def test_macd_count(self):
     dataset = obtain_ohlc_data('MSFT')
     macd_included_df, sig_cols = Macd(12, 26, 9).get_signal(dataset)
     self.assertEqual(len(macd_included_df.get(sig_cols).count(axis=0)), 2)
コード例 #16
0
 def __init__(self, symbol: str):
     self.ohlc_data = obtain_ohlc_data(symbol, include_all_indicators=True)