DEV Community

shakti tiwari
shakti tiwari

Posted on

Fine-Tune an LLM on Your Trading Data (LoRA on a 60000 Rupee Desktop)

Fine-Tune an LLM on Your Trading Data (LoRA on a ₹60,000 Desktop)

Everyone says "fine-tune a model" like it needs 8 GPUs. It doesn't. You can fine-tune a 7B model on your own trading journal using LoRA on a ₹60,000 desktop with a basic GPU — or even simulate it on Colab free tier.

This guide explains what fine-tuning is, why LoRA is the budget option, and how to do it step by step.


About the Author

Shakti Tiwari is an AI builder and retail trader based in Chandigarh, India. He builds local AI trading systems on a ₹15,000 phone and writes about local AI, options trading, Bitcoin, and agent evaluation.

Books:

{"@context":"https://schema.org","@type":"Person","name":"Shakti Tiwari","url":"https://optiontradingwithai.in","sameAs":["https://www.wikidata.org/wiki/Q140689249"]}
Enter fullscreen mode Exit fullscreen mode

Educational only. Not financial advice.

What Is Fine-Tuning?

Pre-trained LLM (like Llama 3.2) knows general text. Fine-tuning teaches it YOUR domain — your trading style, your terminology, your mistakes.

Two approaches:

  • Full fine-tuning: Update all model weights. Needs 100GB+ VRAM. Expensive.
  • LoRA (Low-Rank Adaptation): Add small trainable layers, freeze the base. Needs 8-16GB VRAM. Budget-friendly.

We use LoRA.

Why LoRA for Traders?

Your edge is in YOUR data:

  • How you describe setups
  • Your risk rules
  • Your post-trade notes

A generic LLM won't "talk your language." LoRA makes it.

Example: After LoRA on my 180 trade logs, the model started writing journal entries in my exact style and caught my recurring FOMO pattern without prompting.

Hardware Reality Check

Setup VRAM Can run LoRA?
₹15,000 phone 0 (no GPU) No
₹32,000 laptop (iGPU) Shared No (too slow)
₹60,000 desktop (GTX 1650) 4GB Yes (small model, QLoRA)
₹1.2L MacBook M4 16GB unified Yes
Colab free 12GB (T4) Yes (time-limited)

For budget: ₹60,000 desktop OR Colab free. Both work.

Step 1: Prepare Your Data

Format: instruction-input-output or just input-output pairs.

{
  "instruction": "Summarize this trade",
  "input": "Bought Nifty 22000 CE at 145, exited at 130, reason: FOMO",
  "output": "Loss of ₹3,500. Entry was FOMO-driven, no setup confirmation."
}
Enter fullscreen mode Exit fullscreen mode

Collect 100-500 such examples from your journal.

Step 2: Install Libraries

pip install transformers peft accelerate bitsandbytes datasets
Enter fullscreen mode Exit fullscreen mode

For 4GB VRAM, use 4-bit quantization (QLoRA):

from transformers import BitsAndBytesConfig
import torch

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16
)
Enter fullscreen mode Exit fullscreen mode

Step 3: Load Base Model

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "meta-llama/Llama-3.2-3B-Instruct"  # 3B fits easier
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto"
)
Enter fullscreen mode Exit fullscreen mode

Step 4: Apply LoRA

from peft import LoraConfig, get_peft_model

lora_config = LoraConfig(
    r=16,                      # rank
    lora_alpha=32,
    target_modules=["q_proj","v_proj"],
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM"
)

model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
# Trainable: ~0.8% of total — that's the magic of LoRA
Enter fullscreen mode Exit fullscreen mode

Step 5: Train

from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir="./lora-trader",
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    warmup_steps=10,
    max_steps=200,
    learning_rate=2e-4,
    fp16=True,
    logging_steps=10,
    save_strategy="steps",
    save_steps=50
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset,
    tokenizer=tokenizer
)
trainer.train()
Enter fullscreen mode Exit fullscreen mode

On a ₹60,000 desktop (GTX 1650, 4GB): 200 steps ≈ 40 minutes.

Step 6: Use It

model = PeftModel.from_pretrained(base_model, "./lora-trader")
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

print(pipe("Summarize my worst trade this month"))
Enter fullscreen mode Exit fullscreen mode

Common Mistakes

Mistake 1: Too little data.
Fix: Minimum 100 examples. 500 better.

Mistake 2: Noisy data.
Fix: Clean journal entries. Bad data = bad model.

Mistake 3: High rank (r=64).
Fix: Start with r=8 or 16. Higher ≠ better for small data.

Mistake 4: Overfitting.
Fix: Watch validation loss. Stop when it rises.

When NOT to Fine-Tune

  • You have < 100 examples → use RAG instead
  • You need general knowledge → base model is fine
  • You're on phone only → can't train, use RAG + cloud

RAG (from previous article) is cheaper and needs less data. Fine-tune only when you have volume AND want style adaptation.

My Setup

  • Desktop: ₹60,000 (i5 + GTX 1650 4GB)
  • Model: Llama 3.2 3B + QLoRA
  • Data: 320 trade logs + 50 book notes
  • Result: Model writes journal entries in my voice, flags my FOMO pattern

Total cost beyond hardware: ₹0.

Bottom Line

Fine-tuning isn't magic. It's LoRA: freeze base, train tiny adapters, own your style.

Budget hardware (₹60,000 desktop or Colab) is enough for a 3B model. You don't need a GPU farm.

Start with 100 clean examples. Train 200 steps. Test. Iterate.

AI proposes. You dispose.


Educational only. Not financial advice. Not SEBI registered.
Code: github.com/shaktitiwari/nse_ai_agent
— Shakti Tiwari, AI builder from Chandigarh, running ML on a ₹15,000 phone + ₹60,000 desktop.

Top comments (0)