Skip to main content

Tools for solid Numerai pipelines

Project description

NumerBlox

Solid Numerai pipelines

numerblox offers Numerai specific functionality, so you can worry less about software/data engineering and focus more on building great Numerai models!

Most of the components in this library are designed for solid weekly inference pipelines, but tools like NumerFrame, preprocessors and evaluators also greatly simplify the training process.

Questions and discussion: rocketchat.numer.ai/channel/numerblox

Documentation: crowdcent.github.io/numerblox

1. Install

pip install numerblox

2. How to use

2.1. Contents

2.1.1. Core functionality

numerblox features the following functionality:

  1. Downloading data (NumeraiClassicDownloader and KaggleDownloader)
  2. A custom data structure extending Pandas DataFrame (NumerFrame)
  3. A suite of preprocessors for Numerai Classic and Signals (feature selection, engineering and manipulation)
  4. Model objects for easy inference.
  5. A suite of postprocessors for Numerai Classic and Signals (standardization, ensembling, neutralization and penalization)
  6. Pipelines handling processing and prediction (ModelPipeline and ModelPipelineCollection)
  7. Evaluation (NumeraiClassicEvaluator and NumeraiSignalsEvaluator)
  8. Authentication (Key and load_key_from_json)
  9. Submitting (NumeraiClassicSubmitter and NumeraiSignalsSubmitter)
  10. Automated staking (NumeraiClassicStaker and NumeraiSignalsStaker)

2.1.2. Educational notebooks

Example notebooks can be found in the nbs/edu_nbs directory.

nbs/edu_nbs currently contains the following examples:

  • numerframe_tutorial.ipynb: A deep dive into what NumerFrame has to offer.
  • pipeline_construction.ipynb: How to use numerblox tools for efficient Numerai inference.
  • submitting.ipynb: How to use Submitters for safe and easy Numerai submissions.
  • google_cloud_storage.ipynb: How to use Downloaders and Submitters to interact with Google Cloud Storage (GCS).
  • load_model_from_wandb.ipynb: For Weights & Biases users. Easily pull a model from W&B for inference.

Development notebooks are also in the nbs directory. These notebooks are also used to generate the documentation.

Questions or idea discussion for educational notebooks: rocketchat.numer.ai/channel/numerblox

Full documentation: crowdcent.github.io/numerblox

2.2. Examples

Below we will illustrate a common use case for inference pipelines. To learn more in-depth about the features of this library, check out notebooks in nbs/edu_nbs.

2.2.1. Numerai Classic

# --- 0. Numerblox dependencies ---
from numerblox.download import NumeraiClassicDownloader
from numerblox.numerframe import create_numerframe
from numerblox.postprocessing import FeatureNeutralizer
from numerblox.model import SingleModel
from numerblox.model_pipeline import ModelPipeline
from numerblox.key import load_key_from_json
from numerblox.submission import NumeraiClassicSubmitter

# --- 1. Download version 2 data ---
downloader = NumeraiClassicDownloader("data")
downloader.download_inference_data("current_round")

# --- 2. Initialize NumerFrame ---
metadata = {"version": 2,
            "joblib_model_name": "test",
            "joblib_model_path": "test_assets/joblib_v2_example_model.joblib",
            "numerai_model_name": "test_model1",
            "key_path": "test_assets/test_credentials.json"}
dataf = create_numerframe(file_path="data/current_round/numerai_tournament_data.parquet",
                          metadata=metadata)

# --- 3. Define and run pipeline ---
models = [SingleModel(dataf.meta.joblib_model_path,
                      model_name=dataf.meta.joblib_model_name)]
# No preprocessing and 0.5 feature neutralization
postprocessors = [FeatureNeutralizer(pred_name=f"prediction_{dataf.meta.joblib_model_name}",
                                     proportion=0.5)]
pipeline = ModelPipeline(preprocessors=[],
                         models=models,
                         postprocessors=postprocessors)
dataf = pipeline(dataf)

# --- 4. Submit ---
# Load credentials from .json (random credentials in this example)
key = load_key_from_json(dataf.meta.key_path)
submitter = NumeraiClassicSubmitter(directory_path="sub_current_round", key=key)
# full_submission checks contents, saves as csv and submits.
submitter.full_submission(dataf=dataf,
                          cols=f"prediction_{dataf.meta.joblib_model_name}_neutralized_0.5",
                          model_name=dataf.meta.numerai_model_name,
                          version=dataf.meta.version)

# --- 5. Clean up environment (optional) ---
downloader.remove_base_directory()
submitter.remove_base_directory()
๐Ÿ’ป Directory structure before starting                                                              
โ”—โ”โ” ๐Ÿ“ test_assets                                                                                  
    โ”ฃโ”โ” ๐Ÿ“„ joblib_v2_example_model.joblib                                                           
    โ”—โ”โ” ๐Ÿ“„ test_credentials.json                                                                    
๐Ÿ’ป Directory structure after submitting                                                             
โ”ฃโ”โ” ๐Ÿ“ data                                                                                         
โ”ƒ   โ”—โ”โ” ๐Ÿ“ current_round                                                                            
โ”ƒ       โ”—โ”โ” ๐Ÿ“„ numerai_tournament_data.parquet                                                      
โ”—โ”โ” ๐Ÿ“ sub_current_round                                                                            
    โ”—โ”โ” ๐Ÿ“„ test_model1.csv                                                                          

2.2.2. Numerai Signals

# --- 0. Numerblox dependencies ---
from numerblox.download import KaggleDownloader
from numerblox.numerframe import create_numerframe
from numerblox.preprocessing import KatsuFeatureGenerator
from numerblox.model import SingleModel
from numerblox.model_pipeline import ModelPipeline
from numerblox.key import load_key_from_json
from numerblox.submission import NumeraiSignalsSubmitter

# --- 1. Download Katsu1110 yfinance dataset from Kaggle ---
kd = KaggleDownloader("data")
kd.download_inference_data("code1110/yfinance-stock-price-data-for-numerai-signals")

# --- 2. Initialize NumerFrame with metadata ---
metadata = {"numerai_model_name": "test_model1",
            "key_path": "test_assets/test_credentials.json"}
dataf = create_numerframe("data/full_data.parquet", metadata=metadata)

# --- 3. Define and run pipeline ---
models = [SingleModel("models/signals_model.cbm", model_name="cb")]
# Simple and fast feature generator based on Katsu Signals starter notebook
# https://www.kaggle.com/code1110/numeraisignals-starter-for-beginners
pipeline = ModelPipeline(preprocessors=[KatsuFeatureGenerator(windows=[20, 40, 60])],
                         models=models,
                         postprocessors=[])
dataf = pipeline(dataf)

# --- 4. Submit ---
# Load credentials from .json (random credentials in this example)
key = load_key_from_json(dataf.meta.key_path)
submitter = NumeraiSignalsSubmitter(directory_path="sub_current_round", key=key)
# full_submission checks contents, saves as csv and submits.
# cols selection must at least contain 1 ticker column and a signal column.
dataf['signal'] = dataf['prediction_cb']
submitter.full_submission(dataf=dataf,
                          cols=['bloomberg_ticker', 'signal'],
                          model_name=dataf.meta.numerai_model_name)

# --- 5. Clean up environment (optional) ---
kd.remove_base_directory()
submitter.remove_base_directory()
๐Ÿ’ป Directory structure before starting                                                              
โ”ฃโ”โ” ๐Ÿ“ test_assets                                                                                  
โ”ƒ   โ”—โ”โ” ๐Ÿ“„ test_credentials.json                                                                    
โ”—โ”โ” ๐Ÿ“ models                                                                                       
    โ”—โ”โ” ๐Ÿ“„ signals_model.cbm                                                                        
๐Ÿ’ป Directory structure after submitting                                                             
โ”ฃโ”โ” ๐Ÿ“ data                                                                                         
โ”ƒ   โ”—โ”โ” ๐Ÿ“„ full_data.parquet                                                                        
โ”—โ”โ” ๐Ÿ“ sub_current_round                                                                            
    โ”—โ”โ” ๐Ÿ“„ submission.csv                                                                           

3. Contributing

Be sure to read CONTRIBUTING.md for detailed instructions on contributing.

If you have questions or want to discuss new ideas for numerblox, check out rocketchat.numer.ai/channel/numerblox.

4. Branch structure

Every new feature should be implemented in a branch that branches from dev and has the naming convention feature/{FEATURE_DESCRIPTION}. Explicit bugfixes should be named bugfix/{FIX_DESCRIPTION}. An example structure is given below.

Branch structure                                                                                    
โ”—โ”โ” ๐Ÿ“ฆ main (release)                                                                               
    โ”—โ”โ” ๐Ÿ‘จโ€๐Ÿ’ป dev                                                                                    
        โ”ฃโ”โ” โœจ feature/ta-signals-features                                                          
        โ”ฃโ”โ” โœจ feature/news-api-downloader                                                          
        โ”ฃโ”โ” โœจ feature/staking-portfolio-management                                                 
        โ”—โ”โ” โœจ bugfix/evaluator-metrics-fix                                                         

5. Crediting sources

Some of the components in this library may be based on forum posts, notebooks or ideas made public by the Numerai community. We have done our best to ask all parties who posted a specific piece of code for their permission and credit their work in the documentation. If your code is used in this library without credits, please let us know, so we can add a link to your article/code.

If you are contributing to numerblox and are using ideas posted earlier by someone else, make sure to credit them by posting a link to their article/code in documentation.

- CrowdCent

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numerblox-0.2.3.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numerblox-0.2.3-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file numerblox-0.2.3.tar.gz.

File metadata

  • Download URL: numerblox-0.2.3.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.11

File hashes

Hashes for numerblox-0.2.3.tar.gz
Algorithm Hash digest
SHA256 0bdd0cb59f01f1e54f0961eb369a87cb0d003e91b83e5b854a7ea12d4540039e
MD5 56d42dd23c8cbf06a0a14fd08cc90f79
BLAKE2b-256 8c987e942e33b56083475dccd3b54b3b5764275fae036dd61cba3acdc9ad3957

See more details on using hashes here.

File details

Details for the file numerblox-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: numerblox-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.11

File hashes

Hashes for numerblox-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d76a195d5c468d36e5b5113a3b136f1fb53c1a61c2ef232690ecb4636a58dc63
MD5 bde8856d1d6cf610be8d4f4e74ded489
BLAKE2b-256 c44cfb7031f1dfcbc4def28bd0eace33fd9accb6a1d3ff8a23efa92f40727dee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page