OPEN-SOURCE SCRIPT

Tribute To Peter Lynch

373
Tribute To Peter Lynch - Fund Manager Simulator

"Know what you own, and know why you own it." - Peter Lynch


WHO WAS PETER LYNCH?

Peter Lynch is one of the greatest investors who ever lived. From 1977 to 1990, he managed the Fidelity Magellan Fund and turned it from $18 million into $14 billion in assets. He averaged a 29.2% annual return for 13 straight years, making Magellan the best-performing mutual fund in the world.

What made Lynch different? He believed regular people could beat Wall Street. He bought stocks in companies he understood - he'd ask minivan owners at movie theaters what they thought of their Chrysler, he'd notice the local factory hiring more people, he'd pay attention to which donut shop had the longest line. He called this your "investor's edge" - the things you already know from your daily life that Wall Street analysts sitting in their offices can't see.

Lynch famously said: "If you can tell your stock story to a fifth grader and they understand it, you've got a good one. The more complicated the story, the more likely it is to fall apart."

He also had the stomach for downturns. During his 13 years at Magellan, the market dropped 10% or more NINE times, and Magellan fell right along with it every single time. But he never panicked. He knew that behind every stock is a company, and if the company is doing well, the stock will eventually follow.


WHAT THIS SCRIPT DOES

This is a fund manager simulator built entirely around Peter Lynch's investing philosophy. It's not a technical indicator. There are no moving averages, no RSI, no MACD. Lynch was a fundamental investor - he cared about what a company earns, how fast it's growing, how much debt it has, and whether the story makes sense.

The script classifies any stock into one of Lynch's 6 categories, scores it on a 0-100 Lynch Score, evaluates the fundamental story, and generates buy/sell signals based purely on the same criteria Lynch used at Magellan.


THE 6 STOCK CATEGORIES

Lynch believed you can't treat all stocks the same. A 50% gain on a Slow Grower is fantastic and probably time to sell. The same 50% on a Fast Grower could be just the beginning of a 10-bagger. He broke every stock into 6 categories:

1. FAST GROWERS (20%+ earnings growth)
Companies growing earnings fast, typically small to mid-sized. These are the potential 10-baggers. Lynch looked for PEG ratios below 1.0 and used his "baseball inning" concept - you want to buy these in innings 2-5, when the formula is proven but there's still a long runway ahead. Think of Walmart when it only had a few hundred stores, or Microsoft 3 years after its IPO.

2. SLOW GROWERS (3-8% earnings growth)
Large, mature companies that grow about as fast as the overall economy. You buy these for the dividend. Lynch looked for steady, rising dividends with a low payout ratio (so the dividend is safe). If the dividend yield drops or the payout ratio gets too high, it's time to move on.

3. STALWARTS (10-14% earnings growth)
Big, solid companies that aren't going to disappear but aren't going to triple overnight either. Lynch's rule: take your 30-50% gain and rotate the money into another Stalwart. These are your portfolio's defense - they hold up in recessions and won't go bankrupt.

4. CYCLICALS (tied to the economic cycle)
Companies in industries like autos, airlines, steel, and chemicals that boom and bust with the economy. Here's Lynch's counterintuitive trick: buy cyclicals when the PE is HIGH (that means earnings are at the trough and about to recover) and sell when the PE is LOW (earnings have peaked and are about to fall). This is the opposite of how PE works for every other category.

5. TURNAROUNDS (beaten down, potential recovery)
Companies in deep trouble that might recover. Lynch always checked: does this company have enough cash to survive? Is there a real plan (new management, cost cutting, selling bad divisions)? He said don't buy on hope - wait for actual evidence the turnaround is working. But when they work, the upside can be enormous.

6. ASSET PLAYS (hidden value)
Companies sitting on assets the market doesn't see or doesn't value - real estate, patents, brand names, cash on the balance sheet. Lynch's example: Disney after it opened Epcot. Growth slowed, but the company was sitting on the Disney name, all that Florida land, and a library of characters worth billions that were carried on the books for nothing.


BAR REPLAY - WHERE THIS SCRIPT REALLY SHINES

This script was built with TradingView's Bar Replay feature in mind. Bar Replay is what transforms this from a backtest into a fund manager simulator.

HOW TO USE BAR REPLAY:

1. Add the script to your chart
2. Pick any stock and classify it (Fast Grower, Stalwart, etc.)
3. Set your fundamental inputs if using Manual mode, or let Auto mode pull TradingView financial data
4. Click the Bar Replay button on your toolbar (the clock icon with a rewind arrow)
5. Pick a starting date - maybe go back 5 years, or 10, or start right before a crash
6. Press Play and watch the simulation unfold bar by bar

WHAT YOU'LL SEE IN BAR REPLAY:

- The Lynch Score updates in real time as fundamentals change each quarter
- The Story Status shifts: "Growth Accelerating" might become "Growth Slowing" as the company matures
- Buy and sell signals fire when Lynch's criteria are met
- The P&L tracker shows your position gain in real time
- The Peter Lynch portrait in the corner changes color based on how your portfolio is doing:
-- Equity rising: Lynch appears in bright GREEN against a deep BLUE background, getting more vivid as gains grow
-- Heavy drawdown: Lynch turns CRIMSON RED against a BLACK background
-- Stop loss hit: The portrait FLASHES RED as a warning
-- Neutral: Lynch appears in CYAN/TEAL against dark navy
- The daily Lynch wisdom quote rotates, keeping you in his mindset

BAR REPLAY SCENARIOS TO TRY:

- Start replay on Apple (AAPL) in 2003 as a Turnaround - watch it reclassify into a Fast Grower
- Replay Ford (F) through 2008-2012 as a Cyclical - see Lynch's high-PE-buy rule in action
- Run Coca-Cola (KO) from 1990 as a Stalwart - practice the 30-50% rotate rule
- Try any stock through the 2020 COVID crash - Lynch survived 9 crashes at Magellan, now you can experience one


SETTINGS GUIDE - EXPLAINED SIMPLY

Think of the settings like customizing a video game character before you play. Here's what each group does:

GROUP 1: STOCK TYPE
"What kind of company is this?"
Pick one of the 6 categories. This changes ALL the rules the script uses.

Baseball Inning: Where is this company in its life?
- Innings 1-3 = Young, lots of room to grow (like a kid)
- Innings 4-6 = Middle age, proving itself
- Innings 7-9 = Old, running out of gas
Early innings get a score bonus. Late innings get a penalty.

GROUP 2: FUNDAMENTAL DATA
"Where do the numbers come from?"
- Auto mode: TradingView pulls real financial data (EPS, revenue, debt) automatically. Best for stocks.
- Manual mode: You type in the numbers yourself. Use this for crypto, forex, or if Auto data looks wrong.

GROUP 3: PEG & VALUATION
"How do I know if a stock is cheap or expensive?"
PEG = Price-to-Earnings divided by Growth rate.
- PEG of 1.0 = fairly priced (PE matches growth rate)
- PEG below 1.0 = cheap (you're paying less than what the growth is worth)
- PEG above 2.0 = expensive
The Buy Threshold (default 1.0) means: "only buy if PEG is at or below this number."
The Sell Threshold (default 2.0) means: "sell if PEG goes above this number."

GROUP 4: BALANCE SHEET HEALTH
"Is this company in good financial shape?"
- Max Debt/Equity: How much debt is too much? Default 0.50 means total debt shouldn't be more than half of the company's net worth. Lynch always checked the balance sheet.
- Min Cash Ratio: Does the company have enough cash? Important for Turnarounds.
- Max Payout Ratio: Is the company paying out too much of its earnings as dividends? Above 80% means the dividend might get cut.

GROUP 5: CATEGORY RULES
"Special rules for each stock type."
These are the specific thresholds for each of the 6 categories. The defaults are based on Lynch's actual criteria from his books.

Examples:
- Fast Grower Min Growth 20%: Lynch said a Fast Grower needs at least 20% earnings growth
- Stalwart Rotate Target 40%: Lynch rotated Stalwarts after 30-50% gains
- Cyclical Trough PE 25: Buy cyclicals when PE is HIGH (counterintuitive!)

GROUP 6: STRATEGY SETTINGS
"Should the Lynch Score control the trades?"
- Score Gate OFF (default): The Lynch Score is just a meter showing conviction. Trades fire based on category rules alone.
- Score Gate ON: The Lynch Score must be above the entry threshold to buy and below the exit threshold to sell. This adds an extra filter.

GROUP 7: RISK MANAGEMENT
"How much can I lose on one trade?"
- Stop Loss: If the stock drops this % from your entry price, sell automatically. Default 15%.
- Take Profit: If the stock rises this % from your entry price, sell automatically. Default 100% (a double).

GROUP 8: DISPLAY
"What do I see on the chart?"
- Show/hide the Lynch portrait, the dashboard panel, and buy/sell signals
- Customize your bull/bear/neutral colors


THE DASHBOARD

The top-right panel shows everything Lynch would want to see at a glance:

- LYNCH SCORE: A 0-100 conviction meter with a visual bar. Built from 5 sub-scores:
-- PEG Score (0-25): Is the stock cheap relative to its growth?
-- Earnings Score (0-25): Is earnings growth meeting the target for this category?
-- Balance Sheet Score (0-20): How healthy is the financial structure?
-- Margin Score (0-15): Are profit margins good and expanding?
-- Dividend Score (0-15): Is the dividend policy appropriate for this category?

- STORY STATUS: The current fundamental narrative in plain English
-- "Growth Accelerating", "Trough - Buy Zone", "Turnaround Succeeding", etc.

- SIGNAL: The specific reason behind the current buy or sell signal

- P&L: When in a trade, shows your unrealized gain/loss and warns Stalwart holders when approaching the rotate target

- VALUATION: PEG ratio, PE ratio, and fair value comparison

- EARNINGS: EPS, EPS growth rate, and revenue growth vs. category targets

- BALANCE SHEET: Debt/equity ratio and net cash per share

- MARGINS: Profit margin trend (expanding or contracting)

- DIVIDENDS: Yield, payout ratio, and sustainability assessment

- DAILY WISDOM: A rotating quote from Peter Lynch to keep you grounded


RESEARCH & SOURCES

This script was built using the following primary sources, all studied extensively:

1. "One Up On Wall Street" by Peter Lynch with John Rothchild (1989)
https://share.google/LbJsS8HjvxVJ2yiVP
Lynch's first book laying out his complete investment philosophy - the 6 categories, PEG ratio, the "story" framework, and the idea that everyday investors have edges over professionals.

2. "Beating the Street" by Peter Lynch with John Rothchild (1993)
https://share.google/LbJsS8HjvxVJ2yiVP
Lynch's second book where he walks through his actual portfolio decisions at Magellan, explains his mutual fund strategy, and shows step-by-step how he picks stocks. 328 pages of real-world application.

3. "The Peter Lynch Playbook" compiled by Mayur Jain (@mjbaldbard)
https://share.google/VKMCMsSrFzqEc671A
A comprehensive set of notes summarizing both Lynch books plus interview snippets. Covers portfolio allocation percentages, category-specific checklists, the 2-minute drill for each stock type, risk/reward profiles, and sell criteria. This document was instrumental in translating Lynch's qualitative approach into quantifiable rules.

4. Peter Lynch's "Stock Shop" Video Consultation (Fidelity Archives)
https://youtu.be/cRMpgaBv-U4?si=PjFIiAtSfMZbLSej
A full-length video presentation where Lynch personally explains his approach to categorizing stocks, building stories, understanding PE ratios, evaluating balance sheets, and managing risk. Key quotes transcribed and used to calibrate the scoring engine and story status logic.


IMPORTANT NOTES

- This is a STRATEGY script, not an indicator. It generates actual backtestable trades.
- The script is purely fundamental. No technical analysis. Lynch didn't use charts to make decisions.
- Auto mode requires stocks with TradingView financial data. For other instruments, use Manual mode.
- The Lynch Score is a CONVICTION METER by default, not a trade gate. Enable Score Gate in settings if you want it to filter trades.
- All portrait coloring is non-repainting. Colors only update on confirmed (closed) bars.
- Start with Bar Replay. That's where the magic happens. Watch the story unfold bar by bar, just like Lynch did at his desk at Fidelity every morning.


"The key organ is the stomach, not the brain." - Peter Lynch

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.