Run this model with HF Jobs

Run tradefloordev/ppo-portfolio-study on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/tradefloordev/ppo-portfolio-study. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/tradefloordev/ppo-portfolio-study on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

PPO on Tradefloor/Portfolio-v0: a five-run study

Five PPO policies trained on Tradefloor/Portfolio-v0, a portfolio environment from tradefloor, and their scores on 100 markets that none of them trained on. The markets are simulated. These policies are not for real trading.

No run beat holding every stock in equal weight. Each run lost to equal weight on 79 to 88 of the 100 held-out markets. The trained policies trade 40 to 54 times their account value per episode, against 1.35 for equal weight, and the trading costs outweigh any gain.

The policies are published so the result can be checked and used as a baseline.

Results

Scored on the 100 markets in tradefloor.gym.HELD_OUT_SEEDS; the PPO policies act deterministically. Returns are per 20-day episode. Turnover is traded value over starting net worth. "vs equal weight" counts the markets where the policy finished ahead of equal weight, with an exact two-sided sign test.

policy median % mean % worst % max drawdown % turnover vs equal weight
cash 0.000 0.000 0.000 0.000 0.00 39-61, p=0.035
equal weight 1.079 0.861 -9.155 12.579 1.35 reference
random actions -6.233 -6.501 -16.869 17.667 70.45 0-100, p<1e-29
PPO seed 0 -0.807 -1.230 -12.060 12.623 40.56 12-88, p<1e-14
PPO seed 1 -1.219 -1.254 -15.509 15.562 43.58 21-79, p<1e-8
PPO seed 2 -0.637 -1.013 -14.703 14.703 42.54 20-80, p<1e-8
PPO seed 3 -1.425 -1.799 -15.232 17.633 48.37 12-88, p<1e-14
PPO seed 4 -1.635 -1.765 -14.327 18.916 53.52 12-88, p<1e-14

results.json holds every episode's figures for every policy. score.log is the table as the scoring run printed it, paired against cash.

Training

  • Environment: Tradefloor/Portfolio-v0 with its default settings (8 stocks, 20 days of 6 steps, allocation actions up to 2x leverage, log-return reward, preset pt-v22), tradefloor 0.12.0.
  • Training markets: seeds 0 to 255, pooled.
  • PPO from Stable-Baselines3 2.9.2 with the default MlpPolicy, behind VecNormalize (observations and rewards normalized, observations clipped at 10).
  • 200,704 steps per run (200,000 requested, run in whole 2,048-step rollouts), n_steps=2048, batch_size=256, learning_rate=3e-4, gamma=0.99, gae_lambda=0.95, ent_coef=0.
  • The five runs differ only in the policy seed (0 to 4). Each took about 40 minutes on an Apple silicon Mac, CPU only.
  • The design, including the test, was fixed before any run. Every run is reported.

The script is examples/rl-gymnasium/study.py. train.json in each run's folder records its settings and library versions.

Files

Each ppo-seed<k>/ holds:

  • policy.safetensors: the policy network's weights.
  • vecnormalize.json: VecNormalize's observation mean and variance.
  • train.json: the run's settings, training seeds and versions.

Nothing is pickled, so loading a run executes no code from the files.

Loading a run

import json, pathlib
import gymnasium as gym
import numpy as np
from huggingface_hub import snapshot_download
from safetensors.torch import load_file
from stable_baselines3 import PPO
import tradefloor.gym  # registers the Tradefloor ids
from tradefloor import rl

run = pathlib.Path(snapshot_download("tradefloordev/ppo-portfolio-study", allow_patterns="ppo-seed0/*")) / "ppo-seed0"
record = json.loads((run / "train.json").read_text())
stats = json.loads((run / "vecnormalize.json").read_text())

env = gym.make("Tradefloor/Portfolio-v0")
model = PPO("MlpPolicy", env, device="cpu", **record["ppo"])
model.policy.load_state_dict(load_file(str(run / "policy.safetensors")))

class Frozen:  # VecNormalize's observation statistics, read from JSON
    norm_obs = True
    clip_obs, epsilon = stats["clip_obs"], stats["epsilon"]
    obs_rms = type("RMS", (), {"mean": np.asarray(stats["mean"]), "var": np.asarray(stats["var"])})

policy = rl.from_sb3(model, deterministic=True, normalize=Frozen())
print(rl.evaluate_policy(policy, env, seeds=tradefloor.gym.HELD_OUT_SEEDS[:10]).summary())

Install with pip install "tradefloor[rl]==0.12.0" stable-baselines3 safetensors huggingface_hub.

Limitations

  • The markets are simulated by tradefloor's model, not drawn from real prices.
  • The result covers one environment, one algorithm and one training budget. A turnover penalty, a longer budget or other settings might change it; none was tried here.
  • Scores are exact under tradefloor 0.12.0. A later release with a different market model may score the same policies differently.

Datasets

Offline episodes from the same environment, including one acted by PPO seed 0, are in the Minari dataset group tradefloordev/tradefloor.

Downloads last month
-
Video Preview
loading