cryptorl package

Submodules

cryptorl.data module

cryptorl.data.add_indicators(df) DataFrame

Add technical indicators to the data (now supporting RSI, ROC, OBV)

Parameters:

df (DataFrame) – a df object of raw data

Returns:

a df object with added indicators

Return type:

DataFrame

cryptorl.data.fetch_multiple(start, end, tickers, granularity=86400) DataFrame

Fetch multiple tickers’ historical data from Coinbase

Parameters:
  • start (str) – a string of the starting date in the format of year-month-date ‘xxxx-xx-xx’

  • end (str) – a string of the ending date, same format to start

  • tickers (list of str) – a list of strings of tickers

Returns:

a df object of the fetched data

Return type:

DataFrame

cryptorl.data.fetch_single(start, end, tic, granularity=86400) DataFrame

Fetch single ticker’s historical data from Coinbase

Parameters:
  • start (str) – a string of the starting date in the format of year-month-date ‘xxxx-xx-xx’

  • end (str) – a string of the ending date, same format to start

  • tic (str) – a string of a single ticker

Returns:

a df object of the fetched data

Return type:

DataFrame

cryptorl.data.get_arrays(df)

Get the prices of tickers in the form of 2d array

Parameters:

df (DataFrame) – a df object of given data

Returns:

a list of historical price

Return type:

2D NumPy Array

cryptorl.data.prep_training_data(df, time_range)

Prepare the data for stock prediction

Parameters:
  • df (DataFrame) – a df object of raw data

  • time_range – number of dates use as model input

Returns:

a df object for model input DataFrame: a df object of label

Return type:

DataFrame

cryptorl.data.split(df, start, end) DataFrame

Split the data by given start and end date

Parameters:
  • df (DataFrame) – a df object of given data

  • start (str) – a string of the starting date in the format of year-month-date ‘xxxx-xx-xx’

  • end (str) – a string of the ending date, same format to start

Returns:

a df object with expected start and end date

Return type:

DataFrame

cryptorl.data.tickers(keyword=None)

Get valid tickers with given keyword information

Parameters:

keyword (str) – a string of desired keyword in the ticker id

Returns:

a list of tickers related to the keyword

Return type:

list

cryptorl.utils module

cryptorl.utils.cal_avg_rank(all_rmse)

Calculate the average ranking for each feature combination

Parameters:

all_rmse (list) – a list of prediction error for each ticker

Returns:

a list of tuples of (combination, average ranking), sort by average ranking in ascendant order

Return type:

list

cryptorl.utils.get_feature_combinations(additional_factors)

Get all possible combinations of features

Parameters:

additional_factors (list) – a list of features that would include in the combination

Returns:

a list of possible combinations

Return type:

list

cryptorl.env_crypto module

class cryptorl.env_crypto.CryptoEnv(init_asset)

Bases: Env

action_space: Space[ActType]
observation_space: Space[ObsType]
reset()

Rewrite the reset function inherit from gym.Env

step(action)

Rewrite the step function inherit from gym.Env

Parameters:

action (list) – an action of buy, hold, or sell

cryptorl.predict_LR module

cryptorl.predict_LR.all_lr(processed_df, additional_factors)

Use linear regression with given processed dataframe object and additional factors to predict

Parameters:
  • processed_df (DataFrame) – a DataFrame object with well processed data

  • additional_factors (list) – a list of feature combination that we want to use

Returns:

a list of prediction results

Return type:

list

cryptorl.predict_DT module

cryptorl.predict_DT.dt_feature_importance(best_model, feature_names)

Use the give decision tree model to test all feature combinations

Parameters:
  • best_model (DecisionTreeRegressor) – a DecisionTreeRegressor object

  • feature_names (list) – a list with feature combinations

Returns:

a list of of prediction results

Return type:

list

cryptorl.predict_DT.dt_pruning(processed_df)

Use decision tree with given processed dataframe object to choose the best tree depth

Parameters:

processed_df (DataFrame) – a DataFrame object with well processed data

Returns:

a sklearn tree object with the best depth

Return type:

DecisionTreeRegressor

cryptorl.predict_NN module

cryptorl.predict_NN.all_nn(processed_df, additional_factors)

Use neural network with given processed dataframe object and additional factors to predict

Parameters:
  • processed_df (DataFrame) – a DataFrame object with well processed data

  • additional_factors (list) – a list of feature combination that we want to use

Returns:

a list of prediction results

Return type:

list

Module contents