def initialize(context): # Portfolio assets list with open('sectors.json', 'r') as f: sectors = json.load(f)[global_vars.SECTOR_NAME] sectors = [sector.replace("/", "_") for sector in sectors] # stupid catalyst uses bittrex symbols for symbols if "BCH_BTC" in sectors: sectors.remove("BCH_BTC") sectors.append("BCC_BTC") # too new for asset in global_vars.ignored_assets: if asset in sectors: sectors.remove(asset) # uhh i think we need more than one asset if len(sectors) < 2: print("only 1 asset in bunch for sector: {}".format(global_vars.SECTOR_NAME)) exit() context.assets = symbols(*sectors) context.nassets = len(context.assets) # Set the time window that will be used to compute expected return # and asset correlations context.window = 15 # Set the number of days between each portfolio rebalancing context.rebalance_period = 5 context.i = 0
def universe(context, today): json_symbols = get_exchange_symbols('poloniex') poloniex_universe_df = pd.DataFrame.from_dict( json_symbols).transpose().astype(str) poloniex_universe_df['base_currency'] = poloniex_universe_df.apply( lambda row: row.symbol.split('_')[1], axis=1) poloniex_universe_df['market_currency'] = poloniex_universe_df.apply( lambda row: row.symbol.split('_')[0], axis=1) poloniex_universe_df = poloniex_universe_df[ poloniex_universe_df['base_currency'] == context.base_currency] poloniex_universe_df = poloniex_universe_df[ poloniex_universe_df.symbol != 'gas_btc'] # Markets currently not working on Catalyst 0.3.1 # 2017-01-01 # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'bcn_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'burst_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'dgb_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'doge_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'emc2_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'pink_btc'] # poloniex_universe_df = poloniex_universe_df[poloniex_universe_df.symbol != 'sc_btc'] print(poloniex_universe_df.head()) date = str(today).split(' ')[0] poloniex_universe_df = poloniex_universe_df[ poloniex_universe_df.start_date < date] context.coins = symbols(*poloniex_universe_df.symbol) print(len(poloniex_universe_df)) return poloniex_universe_df.symbol.tolist()
def initialize(context): # Lista de activos context.assets = ["btc_usdt"] context.symbols = symbols("btc_usdt") # Definir carácteristicas context.row_features = ["open", "high", "low", "close"] context.features = ["open", "high", "low", "close"] # Activar siguiente línea para inlcuir velas Heiken Ashi context.include_ha = True if context.include_ha: context.features.append("HAopen") context.features.append("HAhigh") context.features.append("HAlow") context.features.append("HAclose") # Activar siguiente línea para incluir Distribución de Acumulación de William context.include_wadl = False if context.include_wadl: context.features.append("WAD") context.render = True context.min_max_scaler = preprocessing.MinMaxScaler(feature_range=(-1, 1))
def initialize(context): # Portfolio assets list context.assets = symbols('USDT_BTC','USDT_ETH','USDT_LTC','USDT_DASH', 'USDT_XMR') context.nassets = len(context.assets) # Set the time window that will be used to compute expected return and asset correlations context.window = 180 # Set the number of days between each portfolio rebalancing context.rebalance_period = 30 context.i = 0
def initialize(context): log.info('=== initializing algo') context.assets = symbols('ada_usdt', 'algo_usdt', 'atom_usdt', 'bat_usdt', 'bch_usdt', 'btc_usdt', 'comp_usdt', 'dash_usdt', 'eos_usdt', 'eth_usdt', 'link_usdt', 'ltc_usdt', 'neo_usdt', 'trx_usdt', 'xlm_usdt', 'xmr_usdt', 'xrp_usdt', 'xtz_usdt', 'zil_usdt', 'zrx_usdt') context.nassets = len(context.assets) context.set_commission(maker=0.0004, taker=0.0004) context.set_slippage(slippage=0.0001)
def initialize(context): # Portfolio assets list context.assets = symbols('btc_usdt', 'eth_usdt', 'ltc_usdt', 'dash_usdt', 'xmr_usdt') context.nassets = len(context.assets) # Set the time window that will be used to compute expected return # and asset correlations context.window = 180 # Set the number of days between each portfolio rebalancing context.rebalance_period = 30 context.i = 0
def initialize(context): # Lista de activos context.assets = ["btc_usdt"] context.symbols = symbols("btc_usdt") # Definir carácteristicas context.row_features = ["open", "high", "low", "close", "volume"] context.features = ["open", "high", "low", "close", "volume"] context.render = True context.bar_period = 30 context.lookback_w = 30 context.lookforward_w = 5 context.vol_freq = 10
def initialize(context): # Lista de activos context.assets = ["btc_usdt"] context.symbols = symbols("btc_usdt") # Definir carácteristicas context.row_features = ["open", "high", "low", "close", "volume"] context.features = ["open", "high", "low", "close", "volume"] context.initial_value = context.portfolio.starting_cash context.i = 0 context.bar_period = 15 context.random_state = 42 context.n_estimators = 1000 # 400 context.max_deep = 10 context.n_jobs = 1 context.lookback_w = 30 context.lookforward_w = 5 context.model_trained = False context.training_data_size = 700000 # 700000 context.model_pickle_directory = "/home/enzo/SupervisedLearningIntraday/TrainedModels/" if os.path.isfile(context.model_pickle_directory + "meta_model.pkl"): context.model = joblib.load(context.model_pickle_directory + "model.pkl") context.meta_model = joblib.load(context.model_pickle_directory + "meta_model.pkl") context.model_trained = True print("Modelo Pre-Entrenado") context.lags = 5 context.invested = False context.cur_prices = np.zeros(context.lags + 1) context.cur_returns = np.zeros(context.lags) # Advanced parameters context.minRet = 0.01 context.cpus = multiprocessing.cpu_count() context.vol_delta = pd.Timedelta(hours=1) context.vb_delta = pd.Timedelta(hours=1) context.vol_freq = 10 # 10 context.numThreads = 24 context.d = 0.25 # este es el factor fraccional de Fractional Differentieted Features
def universe(context, lookback_date, current_date): # get all the pairs for the given exchange json_symbols = get_exchange_symbols(context.exchange) # convert into a DataFrame for easier processing df = pd.DataFrame.from_dict(json_symbols).transpose().astype(str) df['base_currency'] = df.apply(lambda row: row.symbol.split('_')[1], axis=1) df['market_currency'] = df.apply(lambda row: row.symbol.split('_')[0], axis=1) # Filter all the pairs to get only the ones for a given base_currency df = df[df['base_currency'] == context.base_currency] # Filter all pairs to ensure that pair existed in the current date range df = df[df.start_date < lookback_date] df = df[df.end_daily >= current_date] context.coins = symbols(*df.symbol) # convert all the pairs to symbols return df.symbol.tolist()
def universe(context, lookback_date, current_date): json_symbols = get_exchange_symbols( context.exchange) # get all the pairs for the exchange universe_df = pd.DataFrame.from_dict(json_symbols).transpose().astype( str) # convert into a dataframe universe_df['base_currency'] = universe_df.apply( lambda row: row.symbol.split('_')[1], axis=1) universe_df['market_currency'] = universe_df.apply( lambda row: row.symbol.split('_')[0], axis=1) # Filter all the exchange pairs to only the ones for a give base currency universe_df = universe_df[universe_df['base_currency'] == context.base_currency] # Filter all the pairs to ensure that pair existed in the current date range universe_df = universe_df[universe_df.start_date < lookback_date] universe_df = universe_df[universe_df.end_daily >= current_date] context.coins = symbols( *universe_df.symbol) # convert all the pairs to symbols return universe_df.symbol.tolist()
def initialize(context): many_assets = [] with open('sectors.json', 'r') as f: sectors = json.load(f) for sector in sectors: many_assets += sectors[sector] a_many_assets = [] # find the ones taht dont go back far enough! for asset in many_assets: asset = asset.replace('/', '_') if asset not in global_vars.ignored_assets: a_many_assets.append(asset) a_many_assets.remove("BCH_BTC") a_many_assets.append("BCC_BTC") context.assets = symbols(*a_many_assets)
def initialize(context): context.TimeSpan = 15 context.RollingWindowSize = 50 # Lista de activos context.assets = [ "btc_usdt", "eth_usdt", "ltc_usdt", "xmr_usdt", "str_usdt", "xrp_usdt" ] context.symbols = symbols("btc_usdt", "eth_usdt", "ltc_usdt", "xmr_usdt", "str_usdt", "xrp_usdt") # Definir carácteristicas context.row_features = ["open", "high", "low", "close"] context.features = ["open", "high", "low", "close"] # Activar siguiente línea para inlcuir velas Heiken Ashi context.include_ha = True if context.include_ha: context.features.append("HAopen") context.features.append("HAhigh") context.features.append("HAlow") context.features.append("HAclose") context.f = len(context.features) context.m = len(context.assets) context.n = context.RollingWindowSize context.initial_value = context.portfolio.starting_cash # Hiper-parámetros de modelo context.tau = 0.001 context.actor_learning_rate = 0.0001 context.critic_learning_rate = 0.001 context.minibatch_size = 64 context.max_episodes = 50 context.max_ep_steps = 1000 context.total_steps = context.max_episodes * context.max_ep_steps context.buffer_size = context.total_steps / 50 # 1000000 context.gamma = 0.99 context.epsilon = 0.1 context.epsilon_target = 0.01 context.epsilon_decay = (context.epsilon_target / context.epsilon)**( 1 / (int(context.total_steps * 0.8))) # Valor de portafolio de entrenamiento context.init_train_portfolio = context.initial_value context.portfolio_value_memory = [] context.portfolio_value_memory.append(context.init_train_portfolio) context.train_invested_quantity = 0.0 context.train_cash = context.init_train_portfolio context.invested_value = 0.0 context.portfolio_w_memory = [] context.init_portfolio_w = [] for i in range(len(context.assets) + 1): context.init_portfolio_w.append(0.0) context.assets_quantity_invested = [] for i in range(len(context.assets)): context.assets_quantity_invested.append(0.0) context.init_portfolio_w[0] = 1.0 context.portfolio_w_memory.append(context.init_portfolio_w) context.transaction_cost = 0.002 context.open_trade = False context.model_trained = True context.model_created = False context.model_loaded = False context.saver = None context.last_train_operation = 2 context.model_path = "/home/enzo/PycharmProjects/DDPGPorfolioOptimization/TrainedModels/model.ckpt" context.i = 0 context.bar_period = 30 context.waiting_period = 0 context.wait = 0 context.current_op = 2
def initialize(context): log.info('initializing algo') context.assets = symbols('btc_usd')