DEV Community

Rahul Kumar
Rahul Kumar

Posted on AI-assisted

Paper to Portfolio: a local Gemma reads the old share certificate in your drawer, but never does the maths

Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady πŸ¦₯

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

What I Built

Lots of Indian families have a drawer with a few old share certificates in it: thick, cream-coloured paper, a company seal, "100 Equity Shares of Rs. 10/- each", dated sometime in the 1980s. Nobody knows what they are worth. The company on the paper usually no longer exists under that name. Since then there have been bonus issues, a stock split, maybe a merger. And if the dividends went unclaimed for seven years in a row, the shares may have been moved to the government's Investor Education and Protection Fund (IEPF).

Working that out today means weeks of digging through exchange filings, or paying a share-recovery firm.

Paper to Portfolio does it on your own laptop in about five minutes:

  1. Photograph the certificate. A local Gemma model reads the company, holder, folio, certificate number, share count, face value and date.
  2. Paste the company's corporate-announcement history, copied from the exchange website or annual reports.
  3. Gemma picks out every bonus, split, merger and rename, and must quote the sentence it relied on.
  4. Plain Python checks every quote against your text and does all the arithmetic, with exact fractions.
  5. You get the lineage timeline, the share count and value today, a plain-language explanation (English, Hindi, Marathi, Bengali or Tamil), and a claim checklist: IEPF search, RTA, KYC, transmission, demat, IEPF-5.

Shares held for 35 years without anyone touching them are the most slow-and-steady investment there is. This tool lets the tortoise collect its winnings.

Demo

The screenshots come from a real run on my laptop, and the voice-over is generated with ElevenLabs (eleven_multilingual_v2).

The demo uses a fictional specimen certificate and a made-up company, both in the repo, so anyone can reproduce it:

1989: 100 shares of Sahyadri Spinning Mills, face value Rs 10
β†’ 1994 bonus 1:1 β†’ 200
β†’ 2001 bonus 1:2 β†’ 300
β†’ 2006 split Rs 10 to Rs 2 β†’ 1,500
β†’ 2011 merged into Deccan Textiles, 3 for every 4 β†’ 1,125
β†’ 2018 renamed Deccan Fabtech
Today: 1,125 shares, 11.25x, worth Rs 4,64,062.50 at a Rs 412.50 share price

On my CPU-only laptop, reading the certificate takes 38 to 84 seconds (depending on whether the model is already loaded), and tracing plus the summary takes about 3 minutes 15 seconds. No GPU, no hurry.

Code

GitHub logo Rahullkumr / paper-to-portfolio

Hacktoberfest Week 3 DEV Challenge - Slow and Steady

Hacktoberfest 2026 Open-Source AI Challenge Week 3: Slow and Steady

Paper to Portfolio

Found an old share certificate in a drawer? Paper to Portfolio reads it with a local open-weight model, traces every bonus, split, merger and rename since the day it was printed, and tells you what it is worth today and how to claim it.

Thousands of Indian families hold physical shares bought in the 1980s and 90s. The company has usually been renamed or merged, the share count has multiplied several times, and unclaimed dividends may have been moved to the IEPF. Working that out by hand takes weeks, or a paid recovery firm. Here it takes a few slow minutes on a laptop with no GPU.

How it works

  1. Read. Gemma (gemma4:e4b, via Ollama) reads the certificate photo into structured fields: company, holder, folio, certificate number, shares, face value, issue date. You check and correct them.
  2. Extract. You paste the company's corporate-announcement history (from…

How I Built It

Stack: Python 3.12 standard library only, plus Ollama running gemma4:e4b locally. One small web page, no framework, no cloud.

The whole design comes down to one rule: let the model read and write, never let it count.

Reading: Gemma vision with a JSON schema. The certificate photo goes to Gemma through Ollama's chat API with a strict JSON schema (company, holder, folio, certificate_no, shares, face_value, issue_date). On my test certificate it got every field right on the first try. The page still shows the fields as editable boxes, because a 40-year-old photocopy will be harder.

Extracting: evidence or it didn't happen. Exchange filings are full of noise: dividends, AGMs, board meetings. Gemma gets the pasted history and returns only share-changing events. Each event has typed fields (give/per for bonus and merger ratios, from_fv/to_fv for splits, into for the new company name) and an evidence string that must be copied word for word.

Verifying: the model's output is a proposal, not a fact. ledger.verify() normalises whitespace and case, then checks that each evidence string really appears in the source text. It also rejects events with missing ratios or unreadable dates. An invented "5:1 bonus" gets thrown out and shown in red on the page. Two things caught me on the first run: Gemma echoed Indian DD-MM-YYYY dates back, and left out the ratio fields when the schema didn't require them. The fix was to make every field required (0 when it doesn't apply) and parse both date styles in code.

Computing: fractions.Fraction, not floats, not the LLM. Bonus 1:2 multiplies by 3/2. A split from Rs 10 to Rs 2 multiplies by 5. A 3-for-4 merger multiplies by 3/4. After each step the count is floored, because Indian companies pool fractional entitlements, sell them and pay cash. The fraction is kept and shown.

Explaining: Gemma gets the computed facts only. The summary prompt passes in the finished timeline and says use only these numbers. The claim checklist is fixed text written by a person, because a wrong legal step can cost a family months.

Tests cover the sample lineage end to end, fraction flooring, consolidation, events before the issue date, invented evidence, missing ratios and the transmission step. They need no model, so GitHub Actions runs them on every push.

Why Does Open Innovation Matter?

A share certificate carries a family's full name, folio number and holdings, often of someone who has died. That's exactly the kind of document people shouldn't have to upload to somebody else's server to understand. With an open-weight model running on the laptop, the certificate never leaves the house. That matters more than raw accuracy: a closed API would be quicker, but it asks families to trust a third party with the paper that proves what they own.

Open weights also made the trust design possible. Because I control the model, the prompt and the schema, I could build the tool around not trusting it: structured output, quoted evidence, code-side checks, code-side arithmetic. The model is a fast reader that works for the code. And because the whole thing is MIT-licensed and runs on a CPU, an investor-awareness group or a small-town CA can run it for people who would never pay a recovery firm.

My Agent Session

I planned and built this with Claude Code, and the full session is captured with Entire, unedited, because it explains why this code exists. The first half is idea research: I went through more than 25 ideas, and the agent searched DEV and GitHub and found almost every one already built this month (forward checkers, chat digests, file tidiers, read-later bots, trading journals). This idea was the first with no existing AI tool, only paid recovery firms. The second half is the build, including the date-format bug.

Session and checkpoints: https://entire.com/gh/Rahullkumr/paper-to-portfolio/commit/83893ddd41a6b0a02eb171d1582772a11948174d

The Lazy Payoff

By hand Paper to Portfolio
Read the certificate squint, type under 90 s
Find every bonus, split, merger, rename days in exchange archives paste once, about 3 min
Do the maths across 35 years spreadsheet plus doubt exact, with sources
Know what to do next ask around checklist

Total for the sample: under 5 minutes of laptop time and about 30 seconds of mine.

Prize Categories

  • Best Use of Gemma: gemma4:e4b locally for vision OCR, evidence-quoted extraction and multilingual explanation.
  • Best Use of Entire: the unedited agent session behind the project is linked above, including the research that shows why this idea was chosen.
  • Best Use of GitHub Copilot: GitHub Actions runs the test suite on every push.
  • Best Use of ElevenLabs: the demo narration is generated with ElevenLabs.

The sample certificate, company and holder are fictional. This is general guidance, not legal or financial advice; confirm with the company's RTA or the IEPF Authority before filing anything. Written with AI assistance and edited by me.

Top comments (0)