coinsignal 1.4.0__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of coinsignal might be problematic. Click here for more details.

coinsignal/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ from . import _ext
2
+ from . import data
3
+ from . import feature
4
+ from . import label
5
+ from . import model
6
+ from . import parallel
7
+ from . import sampler
8
+ from . import tools
9
+
10
+ __version__ = '1.4.0'
11
+
12
+ __all__ = ['data', 'feature', 'label', 'model', 'parallel', 'sampler', 'tools']
coinsignal/_ext.pyd ADDED
Binary file
coinsignal/data.py ADDED
@@ -0,0 +1,32 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements data reading and transformation functions:
7
+ # • Reading raw market data from CSV files
8
+ # • Handling static and dynamic symbol selection
9
+ # • Transforming symbol-based data maps into feature maps
10
+ # --------------------------------------------------------------------------------
11
+
12
+
13
+ import _ext.data as _data
14
+
15
+
16
+ DEFAULT_DATA_PARAMS_DICT = {
17
+ 'static_symbols': [],
18
+ 'dynamic_symbols': {
19
+ 'rule': '',
20
+ 'count': 0
21
+ },
22
+ 'sources': []
23
+ }
24
+
25
+
26
+ def read_data_to_features_map(data_dir, date, look_back_days, look_ahead_days, data_params_dict):
27
+ features_map, read_data_errors = _data.read_data_to_features_map(data_dir, date, look_back_days, look_ahead_days, data_params_dict)
28
+ return features_map, read_data_errors
29
+
30
+ def transform_features_map_to_full_features_df(features_map):
31
+ full_features_df = _data.transform_features_map_to_full_features_df(features_map)
32
+ return full_features_df
coinsignal/feature.py ADDED
@@ -0,0 +1,35 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements feature engineering functions:
7
+ # • Adding various features based on trade and reference exchange-market pairs
8
+ # --------------------------------------------------------------------------------
9
+
10
+
11
+ import _ext.feature as _feature
12
+
13
+
14
+ DEFAULT_FEATURE_PARAMS_DICT = {
15
+ 'time': [],
16
+ 'macd': [],
17
+ 'rsi': [],
18
+ 'price_move_range': [],
19
+ 'price_trend': [],
20
+ 'price_volume_corr': [],
21
+ 'ohlcv': [],
22
+ 'volatility': [],
23
+ 'high_low_time': [],
24
+ 'volume': [],
25
+ 'basis': [],
26
+ 'fixedstart': [],
27
+ 'funding_rate': [],
28
+ 'funding_time': [],
29
+ 'index': [],
30
+ }
31
+
32
+
33
+ def add_features(features_map, feature_params_dict):
34
+ features_map = _feature.add_features(features_map, feature_params_dict)
35
+ return features_map
coinsignal/label.py ADDED
@@ -0,0 +1,36 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements return (label) calculation functions:
7
+ # • Calculating return values for multiple horizons and decay multipliers
8
+ # • Handling time, duration, and range return types
9
+ # • Supporting funding rate adjustment and discrete return calculation
10
+ # --------------------------------------------------------------------------------
11
+
12
+
13
+ import _ext.label as _label
14
+
15
+
16
+ DEFAULT_RETURN_PARAMS_DICT = {
17
+ 'pred_horizons': [600],
18
+ 'decay_multipliers': [0.5, 0.8, 1, 1.5, 2, 3, 5, 10],
19
+ 'return_type': 'time',
20
+ 'range_merge_step': 1,
21
+ 'n_multi': 1,
22
+ 'multi_limits': [1, 1],
23
+ 'half_life': 0,
24
+ 'duration_vlimits': None,
25
+ 'duration_qlimits': [0, 1],
26
+ 'duration_handling': '',
27
+ 'is_horizon_adjusted': False,
28
+ 'is_funding_adjusted': False,
29
+ 'is_discrete': False,
30
+ 'y_multiplier': 10000
31
+ }
32
+
33
+
34
+ def calculate_return(features_map, return_params_dict):
35
+ features_map = _label.calculate_return(features_map, return_params_dict)
36
+ return features_map
coinsignal/model.py ADDED
@@ -0,0 +1,74 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements the main model training and evaluation pipeline:
7
+ # • Handling data splitting, scaling, auxiliary model processing, cross-validation,
8
+ # • Training and evaluating models with various metrics
9
+ # --------------------------------------------------------------------------------
10
+
11
+
12
+ import _ext.model as _model
13
+
14
+
15
+ DEFAULT_MODEL_PARAMS_DICT = {
16
+ 'group_count': 5,
17
+ 'train_ratio': 0.8,
18
+ 'valid_sub_ratio': 0.25,
19
+ 'test_isolate_time': 0,
20
+ 'is_random_start': False,
21
+ 'is_cv': True,
22
+ 'cv_split_count': 4,
23
+ 'cv_eval_train_metric': True,
24
+ 'cv_selection_metric': 'mse',
25
+ 'num_boost_round': 1000,
26
+ 'log_evaluation_period': 50,
27
+ 'evaluate_rounds': [400, 700, 1000],
28
+ 'X_scaler_sub_params': {
29
+ 'name': '',
30
+ 'vlimits': None,
31
+ 'qlimits': [0, 1],
32
+ 'inner_scale': 1,
33
+ 'outer_scale': 1
34
+ },
35
+ 'y_scaler_sub_params': {
36
+ 'name': '',
37
+ 'vlimits': None,
38
+ 'qlimits': [0, 1],
39
+ 'inner_scale': 1,
40
+ 'outer_scale': 1
41
+ },
42
+ 'auxiliary_model_sub_params': {
43
+ 'name': '',
44
+ 'model_dir': '',
45
+ 'vlimits': None,
46
+ 'qlimits': [0, 1],
47
+ 'is_in_training': False
48
+ },
49
+ 'loss_sub_params': {
50
+ 'name': '',
51
+ 'dof': 10,
52
+ 'scale': 1,
53
+ 'fee': 0.0001
54
+ },
55
+ 'training_sub_params': {
56
+ 'boosting_type': 'gbdt',
57
+ 'num_leaves': 25,
58
+ 'max_depth': 5,
59
+ 'learning_rate': 0.005,
60
+ 'reg_alpha': 1,
61
+ 'reg_lambda': 1,
62
+ 'min_gain_to_split': 0.1,
63
+ 'extra_trees': True,
64
+ 'objective': 'regression',
65
+ 'metric': '',
66
+ 'num_class': 1,
67
+ 'verbose': -1
68
+ }
69
+ }
70
+
71
+
72
+ def run_model(full_features_df, model_params_dict):
73
+ model_evaluations = _model.run_model(full_features_df, model_params_dict)
74
+ return model_evaluations
coinsignal/parallel.py ADDED
@@ -0,0 +1,21 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements parallel processing for feature preparation:
7
+ # • Parallelizing data reading, feature and label calculations, sampling
8
+ # • Progress tracking for parallel processing across multiple dates
9
+ # --------------------------------------------------------------------------------
10
+
11
+
12
+ import _ext.parallel as _parallel
13
+
14
+
15
+ def prepare_sub_full_features_df(data_dir, date, look_back_days, look_ahead_days, constants_dict, data_params_dict, feature_params_dict, return_params_dict, sampler_params_dict, N, n_completed, progress_update_event):
16
+ df, errors = _parallel.prepare_sub_full_features_df(data_dir, date, look_back_days, look_ahead_days, constants_dict, data_params_dict, feature_params_dict, return_params_dict, sampler_params_dict, N, n_completed, progress_update_event)
17
+ return df, errors
18
+
19
+ def prepare_full_features_df(data_dir, start_date, end_date, look_back_days, look_ahead_days, constants_dict, data_params_dict, feature_params_dict, return_params_dict, sampler_params_dict):
20
+ full_features_df, read_data_errors = _parallel.prepare_full_features_df(prepare_sub_full_features_df, data_dir, start_date, end_date, look_back_days, look_ahead_days, constants_dict, data_params_dict, feature_params_dict, return_params_dict, sampler_params_dict)
21
+ return full_features_df, read_data_errors
coinsignal/sampler.py ADDED
@@ -0,0 +1,30 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module implements data sampling functions:
7
+ # • Sampling data on time using time intervals
8
+ # • Sampling data on move using smoothed price change
9
+ # • Sampling data on return using weighted random sampling
10
+ # --------------------------------------------------------------------------------
11
+
12
+
13
+ import _ext.sampler as _sampler
14
+
15
+
16
+ DEFAULT_SAMPLER_PARAMS_DICT = {
17
+ 'sampling_time': 0,
18
+ 'is_time_random': False,
19
+ 'sampling_bp': 0,
20
+ 'rolling_step': 0,
21
+ 'is_sampling_on_ret': False,
22
+ 'fraction': 1,
23
+ 'weight_limit': 1,
24
+ 'is_sign_balanced': False,
25
+ }
26
+
27
+
28
+ def sample_data(features_map, sampler_params_dict):
29
+ features_map = _sampler.sample_data(features_map, sampler_params_dict)
30
+ return features_map
coinsignal/tools.py ADDED
@@ -0,0 +1,114 @@
1
+ # --------------------------------------------------------------------------------
2
+ # Copyright (c) 2025 Zehao Yang
3
+ #
4
+ # Author: Zehao Yang
5
+ #
6
+ # This module provides utility functions and helper classes:
7
+ # • I/O utilities for logging and progress tracking
8
+ # • Configuration loading and parameter updating
9
+ # • Rolling statistics calculations and various data processing helpers
10
+ # • Plotting functions for model performance visualization
11
+ # --------------------------------------------------------------------------------
12
+
13
+
14
+ import os
15
+ import sys
16
+ import yaml
17
+ import hashlib
18
+ import numpy as np
19
+ from datetime import datetime
20
+ import _ext.tools as _tools
21
+
22
+
23
+ class RegressionIO:
24
+ def __init__(self, log_file):
25
+ self.sys_stdout = sys.stdout
26
+ self.ios = [sys.stdout, open(log_file, 'a', encoding='utf-8')]
27
+
28
+ def write(self, text):
29
+ current_time = get_current_time()
30
+ if text not in ['\n', '\r']:
31
+ text = f'[{current_time}] {text}'
32
+ for io in self.ios:
33
+ io.write(text)
34
+
35
+ def flush(self):
36
+ for io in self.ios:
37
+ io.flush()
38
+
39
+ def close(self):
40
+ for io in self.ios[1:]:
41
+ io.close()
42
+
43
+ def __enter__(self):
44
+ sys.stdout = self
45
+ return self
46
+
47
+ def __exit__(self, exc_type, exc_val, exc_tb):
48
+ sys.stdout = self.sys_stdout
49
+ self.close()
50
+ return False
51
+
52
+
53
+ def get_current_dir(current_file):
54
+ current_dir = os.path.dirname(os.path.abspath(current_file))
55
+ return current_dir
56
+
57
+ def get_current_time():
58
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
59
+ return current_time
60
+
61
+ def write_log(log_file, log):
62
+ with open(log_file, 'w', encoding='utf-8') as f:
63
+ f.write(log)
64
+
65
+ def load_config(current_dir):
66
+ with open(f'{current_dir}/config.yaml', 'r', encoding='utf-8') as f:
67
+ config = yaml.safe_load(f)
68
+ config['start_date'] = str(config['start_date'])
69
+ config['end_date'] = str(config['end_date'])
70
+ return config
71
+
72
+ def initialize_random_seed(random_seed):
73
+ if random_seed is None:
74
+ random_seed = int(hashlib.md5(f'{datetime.now().timestamp()}_{os.urandom(8).hex()}'.encode()).hexdigest()[:8], 16)
75
+ np.random.seed(random_seed)
76
+ return random_seed
77
+
78
+ def update_params_dict(params_dict, default_params_dict):
79
+ new_params_dict = {}
80
+ for key in default_params_dict:
81
+ if isinstance(default_params_dict[key], dict):
82
+ new_params_dict[key] = update_params_dict(params_dict.get(key, {}), default_params_dict[key])
83
+ else:
84
+ new_params_dict[key] = params_dict.get(key, default_params_dict[key])
85
+ return new_params_dict
86
+
87
+ def make_results_dirs(output_dir, model_name, horizons):
88
+ model_dir = f'{output_dir}/{model_name}'
89
+ os.makedirs(model_dir, exist_ok=True)
90
+ os.makedirs(f'{model_dir}/results', exist_ok=True)
91
+ for horizon in horizons:
92
+ ret_col = f'ret-{horizon}'
93
+ os.makedirs(f'{model_dir}/results/{ret_col}', exist_ok=True)
94
+ os.makedirs(f'{model_dir}/results/{ret_col}/models', exist_ok=True)
95
+ os.makedirs(f'{model_dir}/results/{ret_col}/plots', exist_ok=True)
96
+
97
+ def copy_scripts(current_dir, output_dir, model_name, random_seed, scripts_folder='scripts'):
98
+ model_dir = f'{output_dir}/{model_name}'
99
+ os.makedirs(f'{model_dir}/{scripts_folder}', exist_ok=True)
100
+ file_and_folders = [f for f in os.listdir(current_dir) if not f.startswith('.')]
101
+ for f in file_and_folders:
102
+ if os.path.isfile(f'{current_dir}/{f}'):
103
+ with open(f'{current_dir}/{f}', 'r', encoding='utf-8') as file:
104
+ text = file.read()
105
+ if f == 'config.yaml':
106
+ row = [row for row in text.split('\n') if row.startswith('random_seed:')][0]
107
+ text = text.replace(row, f'random_seed: {random_seed}')
108
+ with open(f'{model_dir}/{scripts_folder}/{f}', 'w', encoding='utf-8') as file:
109
+ file.write(text)
110
+ else:
111
+ copy_scripts(f'{current_dir}/{f}', output_dir, model_name, random_seed, f'{scripts_folder}/{f}')
112
+
113
+ def summarize_and_save_results(output_dir, model_name, model_evaluations):
114
+ _tools.summarize_and_save_results(output_dir, model_name, model_evaluations)
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: coinsignal
3
+ Version: 1.4.0
4
+ Summary: coin data analysis and return predicting framework
5
+ Author: Zehao Yang
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/plain
8
+ Requires-Dist: numpy>=1.20.0
9
+ Requires-Dist: pandas>=1.3.0
10
+ Requires-Dist: lightgbm>=3.3.0
11
+ Requires-Dist: scikit-learn>=1.0.0
12
+ Requires-Dist: matplotlib>=3.3.0
13
+ Requires-Dist: pyyaml>=5.4.0
14
+ Requires-Dist: joblib>=1.0.0
15
+ Requires-Dist: cython>=0.29.0
16
+ Dynamic: author
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ coin data analysis and return predicting framework
@@ -0,0 +1,14 @@
1
+ coinsignal-1.4.0.dist-info/METADATA,sha256=3Azy1Ge380FQFqxKzqDGKFjl_DFyWhdpiPzOYPfj2As,649
2
+ coinsignal-1.4.0.dist-info/RECORD,sha256=SX3a2IhGKhfnEpa-avEVQ7V4zmwapNooKvRDu3B-43U,1021
3
+ coinsignal-1.4.0.dist-info/WHEEL,sha256=8UP9x9puWI0P1V_d7K2oMTBqfeLNm21CTzZ_Ptr0NXU,101
4
+ coinsignal-1.4.0.dist-info/top_level.txt,sha256=8xBBVxKSVz2DM3nreUe-A7OGl7vCbK-3njdPu-JtUjw,11
5
+ coinsignal/__init__.py,sha256=LV0A5txgjrFPJyQw6gGayDwbvRXN0rfo3gPqjTUUwzE,281
6
+ coinsignal/_ext.pyd,sha256=dJ9djqwYpcjOLGIJQAkteSjnTdYLAwFBRalwGojPaok,908800
7
+ coinsignal/data.py,sha256=7KPRna6ELPnKqu5c9ExI67c9iTV-OZ2TGh8CMNxau5c,1108
8
+ coinsignal/feature.py,sha256=Mczca9hZN9Xf38ePg-aZh5pdY7KKS4GQCkkvjM252rs,931
9
+ coinsignal/label.py,sha256=iHKZTcHxFUwE9-RX6Znr8WTFbzqcLxnYmUBSXvanBsQ,1164
10
+ coinsignal/model.py,sha256=ASsg2CDycKMHhPlOoaLjrPsNSUNaeeNmoW7Wtj5-ceU,2054
11
+ coinsignal/parallel.py,sha256=SQ4bBr4ppW2CvEzyagaMiqMVicYpYso40EFuJMT1nGE,1480
12
+ coinsignal/sampler.py,sha256=D7HPaHZx9ZW4JWcQSu5cnX7eFXmy_bC3-J54AjLctcE,894
13
+ coinsignal/tools.py,sha256=_92SQXz-OyD5p1ryZ463dGYMAD28do1_LR5GmzPhRDs,4322
14
+ coinsignal-1.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-win_amd64
5
+
@@ -0,0 +1 @@
1
+ coinsignal