Beispiel #1
0
def main():
    # load configs
    cfg = load_config(os.path.join('./config', config_file))
    cfg.device.local_rank = args.local_rank

    # start training
    trainer = Trainer(cfg)
    trainer.train()
    return
def main():
    cfg = load_config(os.path.join('./config', config_file))
    cfg.device.local_rank = args.local_rank
    cfg.device.num = torch.cuda.device_count()
    torch.cuda.set_device(cfg.device.local_rank)
    print(cfg.device.local_rank, cfg.device.num)

    test_pipeline(cfg)

    return
def run_exchange(exchange_name, trading_pair, start_time, time_block):
    """
    Downloads traiding_pair for an exchange and inserts the result in the influx database.
    Parameters
    ----------
    exchange_name: str. Name of the exchange
    trading_pair: str. Traiding pair. Example BTC/USDT
    start_time: str
    time_block: str. Block time to read observations.

    Returns
    -------

    """
    pair_influx_name = trading_pair.replace("/", "_")
    measurement = f"Pair_{exchange_name}_{pair_influx_name}"
    config = load_config(path=config_file.config_path, env='devel')
    influx = InfluxDB(**config['influxdb'])
    influx.create_database()
    exchange = get_exchange(exchange_name)
    if check_if_pair_available(exchange, trading_pair):
        if influx.measurement_exists(measurement):
            start_time = influx.get_last_time_measurement(measurement)
            candle_df = get_candles_data(exchange,
                                         trading_pair,
                                         start_time=start_time,
                                         timeframe=time_block)
        else:
            candle_df = get_candles_data(exchange,
                                         trading_pair,
                                         start_time=start_time,
                                         timeframe=time_block)
        if not candle_df.empty:
            print(f"Upload data to influxdb measurement {measurement}")
            influx.load_dataframe(candle_df,
                                  measurement,
                                  tags='',
                                  protocol='line')
        else:
            print("Data is up to date. Continue to next pair")
    else:
        print(
            f"The pair {trading_pair} is not available. Try changing the exchange"
        )
Beispiel #4
0
    # url = build_request_url(url, limit=limit, format='csv')
    if limit == 0:
        print("Data is up to date for Fear and Greed index")
    else:
        print("Getting and inserting Fear and Greed index into influxdb")
        url_request = build_request_url(url, limit=limit)
        dict_response = get_url_data(url_request)
        if dict_response is not None:
            response_df = pd.DataFrame.from_dict(dict_response['data'])
            response_df['timestamp'] = pd.to_datetime(response_df['timestamp'],
                                                      unit='s')
            response_df['value'] = pd.to_numeric(response_df['value'])
            response_df = response_df.set_index('timestamp')
            # Upload the response_df to influxdb
            influx.load_dataframe(response_df,
                                  measurement,
                                  tag_columns=['value_classification'],
                                  protocol='line')


start_date = "2010-01-01"
history_format = True
measurement = f"Fear_Greed_Index"
config = load_config(path=config_file.config_path, env='devel')
influx = InfluxDB(**config['influxdb'])
influx.create_database()

if __name__ == '__main__':
    for url in ['https://api.alternative.me/fng/']:
        run_fear_greed(url, measurement, history_format, start_date)
Beispiel #5
0
import src.core.es as es
from src.core.noisetable import NoiseTable
from src.core.policy import Policy
from src.gym import gym_runner
from src.gym.training_result import TrainingResult, RewardResult
from src.nn.nn import FeedForward
from src.nn.obstat import ObStat
from src.nn.optimizers import Adam
from src.utils import utils
from src.utils.rankers import CenteredRanker

if __name__ == '__main__':
    comm: MPI.Comm = MPI.COMM_WORLD

    cfg_file = utils.parse_args()
    cfg = utils.load_config(cfg_file)

    env: gym.Env = gym.make(cfg.env.name)

    # seeding; this must be done before creating the neural network so that params are deterministic across processes
    rs, my_seed, global_seed = utils.seed(comm, cfg.general.seed, env)
    all_seeds = comm.alltoall(
        [my_seed] *
        comm.size)  # simply for saving/viewing the seeds used on each proc
    print(f'seeds:{all_seeds}')

    # initializing obstat, policy, optimizer, noise and ranker
    nn = FeedForward(cfg.policy.layer_sizes, torch.nn.Tanh(), env,
                     cfg.policy.ac_std, cfg.policy.ob_clip)
    policy: Policy = Policy(nn, cfg.noise.std,
                            Adam(len(Policy.get_flat(nn)), cfg.policy.lr))
Beispiel #6
0
            obj_weight[idx], policies_best_rewards[idx], time_since_best[
                idx] = nsra(cfg, rew, obj_weight[idx],
                            policies_best_rewards[idx], time_since_best[idx])
        elif cfg.nsr.progressive:
            obj_weight[
                idx] = 1 if gen > cfg.nsr.end_progression_gen else gen / cfg.nsr.end_progression_gen

        # Saving policy if it obtained a better reward or distance
        if (rew > best_rew or dist > best_dist) and comm.rank == 0:
            best_rew = max(rew, best_rew)
            best_dist = max(dist, best_dist)

            # Only need to save the archive, policy is saved by DefaultMpiReportedSet
            archive_path = path.join('saved', full_name, 'archives')
            if not path.exists(archive_path):
                os.makedirs(archive_path)
            np.save(path.join(archive_path, f'{gen}.np'), archive)

        reporter.end_gen()

    mlflow.end_run()  # ending the outer mlflow run


if __name__ == '__main__':
    gym.logger.set_level(40)

    config_file = utils.parse_args()
    config = utils.load_config(config_file)

    main(config)