def setUpClass(cls): # Settings cls.market_id = 1 # Bitmex cls.timeframe_id = 6 # 1d cls.count = 500 cls.time_end = t.now cls.len_ma_top = 40 cls.len_ma_bottom = 40 cls.prefix = 'reversal' # Get a bucket object from Bucket cls.bucket = Bucket(market_id=cls.market_id, timeframe_id=cls.timeframe_id) # # Update the bucket table # cls.bucket.update(count = cls.count, time_end = cls.time_end) # Get a dataframe with all the data for the market and timeframe cls.df_bucket = cls.bucket.read_all() kwargs = { 'len_ma_top': cls.len_ma_top, 'len_ma_bottom': cls.len_ma_bottom, 'prefix': cls.prefix } # Instantiate the strategy for the 1d BTCUSD candles on Bitmex cls.strategy = Strategy(df_bucket=cls.df_bucket, **kwargs)
def setUpClass(cls): # Get a bucket object from Bucket cls.b = Bucket(market_id=1, timeframe_id=1) # Get a dataframe with all the data for the market and timeframe cls.df_in = cls.b.read_all()
def setUpClass(cls): cls.prefix = 'test' # Get a bucket object from Bucket cls.b = Bucket(market_id=1, timeframe_id=1) # Get a dataframe with all the data for the market and timeframe cls.df_in = cls.b.read_all() # Calculate the wicks cls.df_height = height.get(cls.df_in) # Calculate wick_top ema cls.wick_top_sma = sma.get(df_in=cls.df_height, id='id', data='abs_top', n=40, prefix='abs_top') # Calculate wick_bottom ema cls.wick_bottom_sma = sma.get(df_in=cls.df_height, id='id', data='abs_bottom', n=40, prefix='abs_bottom') cls.crossover_wick_ema = df_x_df.get( df_in_1=cls.wick_top_sma, df_in_2=cls.wick_bottom_sma, col_1=cls.wick_top_sma.columns[1], col_2=cls.wick_bottom_sma.columns[1], prefix=cls.prefix)
def setUpClass(cls): cls.col = 'price_close' # Get a bucket object from Bucket cls.b = Bucket( market_id = 1, timeframe_id = 1) # Get a dataframe with all the data for the market and timeframe cls.df_in = cls.b.read_all() # Calculate price_close rsi cls.price_close_rsi = rsi.get( df_in = cls.df_in, id='id', data = cls.col, n = 40, prefix = cls.col) # print(price_close_rsi) cls.rsi_x_val = df_x_val.get( df_in = cls.price_close_rsi, col = cls.price_close_rsi.columns[1], val = 30, prefix = cls.price_close_rsi.columns[1])
def setUpClass(cls): ''' +------+--------+----------------+ | id | name | milliseconds | |------+--------+----------------| | 1 | 1m | 60000 | | 2 | 5m | 300000 | | 3 | 15m | 900000 | | 4 | 1h | 3600000 | | 5 | 4h | 14400000 | | 6 | 1d | 86400000 | | 7 | 7d | 604800000 | | 8 | 30d | 2592000000 | +------+--------+----------------+ ''' cls.market_id = 1 cls.timeframe_id = 6 # TESTS SHOULD BE ON ALL TIMEFRAMES AND MARKETS cls.bucket = Bucket(market_id=cls.market_id, timeframe_id=cls.timeframe_id) cls.cols = [ 'id', 'market_id', 'timeframe_id', 'time_open', 'time_close', 'time_updated', 'price_open', 'price_high', 'price_close', 'price_low', 'volume' ] # 'time_close_dt'] # Set a specific sort column cls.sort_col = cls.cols[4] # Set a specific sort direction cls.sort_dir = 'ASC' # 'DESC'
def setUpClass(cls): # Settings cls.market_id = 1 # Bitmex cls.timeframe_id = 6 # 1d cls.count = 500 cls.time_end = t.now cls.reversal_len_ma_top = 40 cls.reversal_len_ma_bottom = 40 cls.reversal_prefix = 'reversal' cls.extreme_len_ma_top = 40 cls.extreme_len_ma_bottom = 40 cls.extreme_prefix = 'extreme' cls.extreme_l1 = 1.34 cls.extreme_l2 = 1.34 cls.extreme_s1 = 2.5 cls.extreme_s2 = 1.5 cls.overtraded_len_rsi = 15 cls.overtraded_high = 75 cls.overtraded_low = 31 cls.overtraded_col = 'price_close' cls.overtraded_prefix = 'overtraded' # Get a bucket object from Bucket cls.bucket = Bucket(market_id=cls.market_id, timeframe_id=cls.timeframe_id) # # Update the bucket table # cls.bucket.update( # count = cls.count, # time_end = cls.time_end) # Get a dataframe with all the data for the market and timeframe cls.df_bucket = cls.bucket.read_all() # Instantiate the strategy for the 1d BTCUSD candles on Bitmex cls.strategy = Momentum( df_bucket=cls.df_bucket, reversal_len_ma_top=cls.reversal_len_ma_top, reversal_len_ma_bottom=cls.reversal_len_ma_bottom, reversal_prefix=cls.reversal_prefix, extreme_len_ma_top=cls.extreme_len_ma_top, extreme_len_ma_bottom=cls.extreme_len_ma_bottom, extreme_prefix=cls.extreme_prefix, extreme_l1=cls.extreme_l1, extreme_l2=cls.extreme_l2, extreme_s1=cls.extreme_s1, extreme_s2=cls.extreme_s2, overtraded_len_rsi=cls.overtraded_len_rsi, overtraded_high=cls.overtraded_high, overtraded_low=cls.overtraded_low, overtraded_col=cls.overtraded_col, overtraded_prefix=cls.overtraded_prefix)
def test_unix_to_datetime(self): market_id = 1 timeframe_id = 6 # Get bucket instance bucket = Bucket(market_id=market_id, timeframe_id=timeframe_id) # Get bucket dataframe df = bucket.read_until(time_end=t.now, count=50, sort_col='time_close', sort_dir='ASC') time1 = t.unix_to_datetime(df, 'time_close') time2 = pd.to_datetime(df['time_close'], unit='ms') self.assertCountEqual(time1['time_close_ISO'], time2)
def setUpClass(cls): # Get a bucket object from Bucket cls.b = Bucket(market_id=1, timeframe_id=1) # Get a dataframe with all the data for the market and timeframe cls.df_in = cls.b.read_all() # Calculate the heights cls.df_out = height.get(cls.df_in)
def setUpClass(cls): # Get a bucket object from Bucket cls.b = Bucket(market_id=1, timeframe_id=1) # Get a dataframe with all the data for the market and timeframe cls.df_in = cls.b.read_all() # Calculate price_close rsi cls.my_rsi = rsi.get(df_in=cls.df_in, id='id', data='price_close', n=12, prefix='price_close')
def setUpClass(cls): # Get a bucket object from Bucket cls.b = Bucket(market_id=1, timeframe_id=6) # Get dataframe with all the market and timeframe data cls.df_bucket = cls.b.read_all() # Number of candles/buckets to include in the rsi calculation len_rsi = 20 # Get an instance of the Overtraded object cls.reversal = Reversal(df_bucket=cls.df_bucket, len_ma_top=40, len_ma_bottom=40, prefix='reversal')
def setUpClass(cls): cls.len_rsi = 20 cls.high = 60 cls.low = 40 cls.col = 'price_close' cls.prefix = 'overtraded' # Get a bucket object from Bucket cls.bucket = Bucket(market_id=1, timeframe_id=1) # Get a dataframe with all the data for the market and timeframe cls.df_bucket = cls.bucket.read_all() # Get an instance of the Overtraded object cls.overtraded = Overtraded(df_bucket=cls.df_bucket, len_rsi=cls.len_rsi, high=cls.high, low=cls.low, col=cls.col, prefix=cls.prefix)
def setUpClass(cls): cls.len_ma_top = 40 cls.len_ma_bottom = 40 cls.prefix = 'extreme' cls.l1 = 3.0 cls.l2 = 1.5 cls.s1 = 3.0 cls.s2 = 1.5 cls.bucket = Bucket(market_id=1, timeframe_id=6) # cls.bucket.update() cls.df_bucket = cls.bucket.read_all() cls.extreme = Extreme(df_bucket=cls.df_bucket, len_ma_top=cls.len_ma_top, len_ma_bottom=cls.len_ma_bottom, prefix=cls.prefix, l1=cls.l1, l2=cls.l2, s1=cls.s1, s2=cls.s2)
extreme_l2 = 2 extreme_s1 = 2 extreme_s2 = 2 # #### Overtraded overtraded_len_rsi = 15 overtraded_high = 60 overtraded_low = 31 overtraded_col = 'price_close' overtraded_prefix = 'overtraded' # STRATEGY --------------------------------------------------------------- # Get a bucket instance with the right market and timeframe id's bucket = Bucket(market_id = market_id, timeframe_id = timeframe_id) # Get timeframe duration in miliseconds timeframe_ms = bucket.timeframe_ms # Update table with the candles for the timeframe bucket.update(time_begin = time_begin_unix, time_end = time_end_unix) pass # Get the dataframe with the bucket data between the begin and end dates df_bucket = bucket.read_between(time_begin = time_begin_unix, time_end = time_end_unix) # Create strategy instance using the configurations above strategy = Momentum( df_bucket = df_bucket,