Пример #1
0
def numerox_example():
    
    config = configparser.ConfigParser()
    config.read('C:\etc\properties.ini') 
    
    public = config['numerai']['public']
    secret = config['numerai']['secret']
    
    
    """
    Example of how to prepare a submission for the Numerai tournament.
    It uses Numerox which you can install with: pip install numerox
    For more information see: https://github.com/kwgoodman/numerox
    """
    
    #contest = str(165)
    #contest = str(config['numerai']['tournament'])
    week = time.strftime("%U")
    contest = str(int(week) + 140)

    directory = 'F:\\Numerai\\numerai' + contest + '\\'

    if not os.path.exists(directory):
        os.makedirs(directory)

        # download dataset from numerai, save it and then load it
        # data = nx.download(directory + 'numerai_dataset.zip')
        nx.download(directory + 'numerai_dataset.zip')

        with ZipFile(directory + 'numerai_dataset.zip', 'r') as zipObj:
            #Extract all the contents of zip file in current directory
            zipObj.extractall(directory)

    # we will use logistic regression; you will want to write your own model
    # model = nx.logistic()

    # fit model with train data and make predictions for tournament data
    #prediction = nx.production(model, data, tournament='bernie')

    # save predictions to csv file
    # prediction.to_csv('logistic.csv', verbose=True)

    mechXg.main(contest)

    # upload predictions to Numerai to enter the tournament
    # create the public_id and secret_key on the Numerai website
    #
    # nx.upload('logistic.csv', tournament='bernie', public_id, secret_key)

    names = ('bernie', 'ken', 'charles', 'frank', 'hillary') 
    #names = ('hillary',)     
    
    for name in names:

        nx.upload(directory + name + '_new_submission.csv', name, public, secret)
Пример #2
0
 def make_predictions_and_prepare_submission(self,
                                             data: nx.Data,
                                             submit: bool = False
                                             ) -> nx.Prediction:
     """
     Make predictions using the .predict() method
     and save to CSV under tmp folder.
     """
     public_id = self.params['credentials'].get('numerai_public_id')
     secret_key = self.params['credentials'].get('numerai_secret_key')
     LOGGER.info(f"Making predictions...")
     prediction: nx.Prediction = self.model.predict(data['tournament'],
                                                    self.tournament)
     prediction_filename: str = f'/tmp/{self.tournament}_predictions.csv'
     LOGGER.info(f"Saving predictions to CSV: {prediction_filename}")
     prediction.to_csv(prediction_filename)
     if submit:
         try:
             submission_id = nx.upload(filename=prediction_filename,
                                       tournament=self.tournament,
                                       public_id=public_id,
                                       secret_key=secret_key,
                                       block=False,
                                       n_tries=3)
             LOGGER.info(
                 f'Predictions submitted. Submission id: {submission_id}')
         except Exception as e:
             LOGGER.error(f'Failure to upload predictions with {e}')
             raise e
     return prediction
Пример #3
0
def predict_and_submit(tournaments, data, model_class, numerai_public,
                       numerai_secret):
    model_name = model_class.__name__
    for tournament_name in tournaments:
        saved_model_name = f'model_trained_{model_name}_{tournament_name}'
        if os.path.exists(saved_model_name):
            print("using saved model for", tournament_name)
            m = model_class.load(saved_model_name)
        else:
            print("saved model not found for", tournament_name)
            m = model_class(verbose=True)

            print("training model for", tournament_name)
            m.fit(data['train'], tournament_name)

        print(
            f"running predictions for {model_name} on tournament {tournament_name}",
            flush=True)
        # fit model with train data and make predictions for tournament data
        prediction = nx.production(m, data, tournament=tournament_name)

        # save predictions to csv file
        prediction_filename = f'/tmp/prediction_{model_name}_{tournament_name}.csv'
        prediction.to_csv(prediction_filename, verbose=True)

    # submit the prediction
    for tournament_name in tournaments:
        prediction_filename = f'/tmp/prediction_{model_name}_{tournament_name}.csv'

        submission_id = nx.upload(prediction_filename,
                                  tournament_name,
                                  numerai_public,
                                  numerai_secret,
                                  block=False,
                                  n_tries=3)
Пример #4
0
def predict_and_submit(data, model_class):
    model_name = model_class.__name__
    model_id = model_class.model_id
    logger = logging.getLogger(model_name)

    for tournament in nx.tournament_names():

        logger.info(f"Predict and submit for {tournament} using {model_class}")
        saved_model_name = f'model_trained_{model_name}_{tournament}'
        if os.path.exists(saved_model_name):
            logger.info(f'Using saved model {saved_model_name}')
            m = model_class.load(saved_model_name)
        else:
            logger.info(f'Saved model {saved_model_name} not found')
            m = model_class(verbose=True)

            try:
                logger.info(
                    f'Training model against {tournament} training data')
                m.fit(data['train'], tournament)
            except Exception as e:
                logger.error(f'Failed to train {model_class} - {e}')
                return

        # fit model with train data and make predictions for tournament data
        logger.info(f'Predicting with {model_class} on {tournament} data')
        prediction = nx.production(m, data, tournament=tournament)

        # save predictions to csv file
        prediction_filename = f'/tmp/prediction_{model_name}_{tournament}.csv'
        logger.info(f"Saving predictions to {prediction_filename}")
        prediction.to_csv(prediction_filename, verbose=True)

        try:
            # submit the prediction
            logger.info(
                f"Submitting predictions from {prediction_filename} using {model_id}"
            )
            submission_id, status = nx.upload(prediction_filename,
                                              tournament,
                                              NUMERAI_PUBLIC_ID,
                                              NUMERAI_SECRET_KEY,
                                              block=False,
                                              n_tries=N_TRIES,
                                              sleep_seconds=SLEEP_SECONDS,
                                              model_id=model_id)
            logger.info(status)
            logger.info(
                f'Successfully submitted predictions using model_id {model_id}'
            )
        except Exception as e:
            logger.error(f'Upload failed with - {e}')
def predict_and_submit():
    # Numerai API key
    # You will need to create an API key by going to https://numer.ai/account and clicking "Add" under the "Your API keys" section.
    # Select the following permissions for the key: "Upload submissions", "Make stakes", "View historical submission info", "View user info"
    public_id = os.environ["NUMERAI_PUBLIC_ID"]
    secret_key = os.environ["NUMERAI_SECRET_KEY"]

    tournaments = nx.tournament_names()
    print(tournaments)

    # download dataset from numerai
    data = nx.download('numerai_dataset.zip')

    for tournament_name in tournaments:
        saved_model_name = 'model_trained_' + tournament_name
        if os.path.exists(saved_model_name):
            print("using saved model for", tournament_name)
            m = model.LogisticModel.load(saved_model_name)
        else:
            print("saved model not found for", tournament_name)
            m = model.LogisticModel(verbose=True)

            print("training model for", tournament_name)
            m.fit(data['train'], tournament_name)

        print("running predictions for", tournament_name)
        # fit model with train data and make predictions for tournament data
        prediction = nx.production(m, data, tournament=tournament_name)

        # save predictions to csv file
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'
        prediction.to_csv(prediction_filename, verbose=True)

    # submit the prediction
    for tournament_name in tournaments:
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'

        submission_id = nx.upload(prediction_filename,
                                  tournament_name,
                                  public_id,
                                  secret_key,
                                  block=False)
Пример #6
0
    prediction.to_csv(prediction_filename, verbose=True)

# submit the prediction

# Numerai API key
# You will need to create an API key by going to https://numer.ai/account and clicking "Add" under the "Your API keys" section.
# Select the following permissions for the key: "Upload submissions", "Make stakes", "View historical submission info", "View user info"
public_id = os.environ["NUMERAI_PUBLIC_ID"]
secret_key = os.environ["NUMERAI_SECRET_KEY"]

for tournament_name in tournaments:
    prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'

    submission_id = nx.upload(prediction_filename,
                              tournament_name,
                              public_id,
                              secret_key,
                              block=False,
                              n_tries=3,
                              model_id=model.model_id)

# staking variables
# change block in nx.upload to block=True. This is because you can't stake until the submission has finished its checks, which take a few minutes
# confidence = .501 # increase this number to signify your confidence in a minimum AUC. Can't go below .501
# stake_value = .1 # the amount of NMR to stake

# napi = numerapi.NumerAPI(public_id, secret_key)

# for tournament_name in tournaments:
#   napi.stake(confidence, stake_value, nx.tournament_int(tournament_name))
    print(">> best params: ", best_params)

    # create a new LR model for the tournament
    model = logistic(best_params)
    """
    print(">> training info:")
    train = nx.backtest(model, data, tournament, verbosity=1)
    """
    print(">> validation info:")
    validation = nx.production(model, data, tournament, verbosity=1)

    print(">> saving validation info: ")
    validation.to_csv(tournament + "-T" + str(week_delta) + ".csv")
    print(">> done saving validation info")
    # Upload these results
    nx.upload(tournament + "-T" + str(week_delta) + ".csv", tournament,
              NUMERAI_PUBLIC_ID, NUMERAI_SECRET_KEY)

#------------------------------------------------------------------------------
# Notify finished running + uploaded Results, whenever it is done

#setup
import smtplib

mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login('*****@*****.**', 'My Password')

Subject = 'Numerai Results Uploaded'
Body = 'https://numer.ai/rounds'
Message = 'Subject: {}\n\n{}'.format(Subject, Body)