Qwen3.8-27B-GFT-Quant-LoRA

A LoRA adapter for Qwen/Qwen3.8-27B that writes formulaic trading alphas: one-line formulas in the style of WorldQuant's 101 Formulaic Alphas. It was trained with multi-reward reinforcement learning against a deterministic backtest verifier.

The full write-up is in Teaching a 27B Model to Write Trading Alphas. The training recipe and its ablations are in Multi-Reward RL, Part 3.

What it does

Given a research brief, the model answers with one formula in a small DSL: daily open high low close volume returns vwap, arithmetic, rank, scale and backward-looking time-series operators such as ts_std(x, d). The full grammar is in system_prompt.txt.

Brief (an unseen evaluation prompt):

Market: US-listed stocks trading on weekday sessions.
Design an alpha whose PRIMARY mechanism is: mixed-input volatility (risk measured on a price-volume composite)
Target horizon: react over roughly 47-day windows (windows near 47 are appropriate; exact values are yours to choose).
Inputs: must combine a price series with a non-price series.
Structure: difference two windows of the SAME operator (fast minus slow).
Constraint: do NOT window-jitter a textbook momentum spread and call it new
Risk preference: prefer signals whose sign flips slowly (hold for the horizon).
Model Answer Holdout score
Base model <alpha>scale(ts_delta(ts_std((close * volume) / (high - low), 21), 26))</alpha> βˆ’2.35
This adapter <alpha>rank(ts_std(volume, 47) / ts_std(close, 47))</alpha> +2.08

Results

Here is how the 50 unseen briefs were scored:

  • Holdout year: 2025-08-21 to 2026-08-21, which training and checkpoint selection never saw.
  • Book: each formula becomes a daily dollar-neutral long-short book on 46 US large caps.
  • Costs: square-root market impact on a $1M book, plus 50 bps a year of borrow cost.
Base (step 0) This adapter (step 500)
Valid formulas 45 / 50 49 / 50
Formulas with a positive holdout score 4 of 45 47 of 49
Mean holdout score per formula βˆ’1.37 +1.80
Equal-weight book of all valid answers: 1-year return βˆ’0.5% +16.2%
Same book: Sharpe βˆ’0.21 2.58
Same book: beta to the market β€” 0.09 (correlation 0.19)

In the same year, the equal-weight market of the same 46 stocks returned +27.3% (Sharpe 1.95, max drawdown βˆ’8.6%). The adapter's book had a βˆ’4.3% max drawdown.

Holdout score: a CPCV-style Sharpe on the holdout year after costs, minus an excess-turnover penalty, clipped to Β±5.

How to use

The scores above were measured exactly this way:

  • 4-bit NF4 base;
  • thinking off;
  • greedy decoding;
  • at most 128 new tokens.
import torch
from huggingface_hub import hf_hub_download
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

base_id = "Qwen/Qwen3.8-27B"
adapter_id = "g-factor-technologies/Qwen3.8-27B-GFT-Quant-LoRA"

tokenizer = AutoTokenizer.from_pretrained(base_id)
model = AutoModelForCausalLM.from_pretrained(
    base_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True, bnb_4bit_quant_type="nf4",
        bnb_4bit_use_double_quant=True, bnb_4bit_compute_dtype=torch.bfloat16),
)
model = PeftModel.from_pretrained(model, adapter_id)

system = open(hf_hub_download(adapter_id, "system_prompt.txt")).read()
brief = "Market: US-listed stocks trading on weekday sessions.\nDesign an alpha whose PRIMARY mechanism is: ..."
messages = [{"role": "system", "content": system}, {"role": "user", "content": brief}]
inputs = tokenizer.apply_chat_template(
    messages, add_generation_prompt=True, enable_thinking=False,
    return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=128, do_sample=False,
                     stop_strings=["</alpha>"], tokenizer=tokenizer)
print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))

With vLLM (BF16 base, so outputs can differ slightly from the NF4 numbers above):

vllm serve Qwen/Qwen3.8-27B --enable-lora --max-lora-rank 32 \
  --lora-modules gft-quant=g-factor-technologies/Qwen3.8-27B-GFT-Quant-LoRA

Then send the same system and user messages with "model": "gft-quant", "temperature": 0, "max_tokens": 128 and "chat_template_kwargs": {"enable_thinking": false}.

Keep thinking off. With native thinking enabled, the same adapter scored between βˆ’0.47 and βˆ’0.79 on the holdout.

Training

Base Qwen/Qwen3.8-27B at revision 1d4bf0f, loaded in 4-bit NF4 (QLoRA)
Adapter LoRA r = 32, alpha = 64, no dropout, on q, k, v, o, gate, up and down projections; FP32 adapter weights
RL GRPO-style groups of 12 answers, 4 briefs per step, 600 steps, learning rate 1e-5, KL Ξ² = 0.08, temperature 1.0
Loss and normalization CISPO loss, GDPO multi-reward normalization, REPO-R entropy control
Briefs 226 training briefs; the 50 evaluation briefs are disjoint
Rewards 12 channels: CPCV core score, PBO, turnover band, IC, complexity, format, syntax novelty, P&L novelty, factor neutrality, minimum turnover, motif guard and a JEPA world-model stress test. The article explains each one and the reward hack behind it
Data Daily OHLCV of 46 US large caps, 2012-06-29 to 2025-08-20 (train window). Price data is not included in this repository
Checkpoint Step 500 of run 1790958861, picked by train-window CPCV of the 50 evaluation answers, not by holdout
Compute One NVIDIA H100

Limitations

  • Research only. This is a research artifact, not investment advice. It has not been validated for live trading.
  • Narrow evidence. The results come from one seed, one holdout year and 46 stocks. The stocks are today's large caps followed back to 2012, so the universe has survivorship bias.
  • Verifier-specific scores. Scores depend on our verifier: universe, cost model, dollar-neutral construction and next-open fills. A different backtest will give different numbers.
  • Similar formulas. All 49 trained answers use volume and fall into 31 formula families, so they are far fewer than 49 independent bets.
  • Briefs are hints, not rules. The model often departs from a brief's structural hints when another shape scores better. In the example above it did not build "fast minus slow".
  • One task only. The model writes formulas in this DSL. It is not a general finance assistant.

Citation

@misc{gfactor2026alphagym,
  title  = {Teaching a 27B Model to Write Trading Alphas: 101 Formulas, 12 Rewards and One Unseen Year},
  author = {Romanov, Aleksei and {g factor technologies}},
  year   = {2026},
  url    = {https://www.g-ftech.com/blog/llm-alpha-gym-trading-formulas-rewards}
}

Built on Qwen3.8-27B by the Qwen team (Apache 2.0). Released by g factor technologies.

Downloads last month
34
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for g-factor-technologies/Qwen3.8-27B-GFT-Quant-LoRA

Base model

Qwen/Qwen3.8-27B
Adapter
(443)
this model

Paper for g-factor-technologies/Qwen3.8-27B-GFT-Quant-LoRA