<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://diogoseca.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://diogoseca.com/" rel="alternate" type="text/html" /><updated>2026-11-23T23:25:58+00:00</updated><id>https://diogoseca.com/feed.xml</id><title type="html">Diogo Seca</title><subtitle>Diogo Seca is a fractional CTO who takes AI-built prototypes and early products to production and automates the repetitive operations around them. Fixed scope, tested, shipped. Based in Porto.</subtitle><author><name>Diogo Seca</name></author><entry><title type="html">Production readiness review for an AI-built app: what I check before real customers arrive</title><link href="https://diogoseca.com/production-readiness-review/" rel="alternate" type="text/html" title="Production readiness review for an AI-built app: what I check before real customers arrive" /><published>2026-11-17T00:00:00+00:00</published><updated>2026-11-17T00:00:00+00:00</updated><id>https://diogoseca.com/production-readiness-review</id><content type="html" xml:base="https://diogoseca.com/production-readiness-review/"><![CDATA[<p>A production readiness review tells you whether a small product can take real customers. I use it for six checks: a deploy that can break a sign-up or a payment, a rollback you can do in minutes, an alarm before a customer emails, a backup you can restore, a named owner for the keys, and a bill that cannot run all night. The long version is how a site reliability team agrees to carry the pager for someone else’s service. You built the app in Lovable, Replit, Bolt, v0, or Cursor. You do not have that team.</p>

<p>I am not scoring how the code was written.</p>

<h2 id="what-is-a-production-readiness-review-and-why-is-the-long-version-too-much">What is a production readiness review, and why is the long version too much?</h2>

<p>Google’s site reliability book describes a Production Readiness Review as the usual first step when an SRE team takes on a service. Reviewers learn the service, compare it with their checklist, and the team accepts production only after that. In Google’s account of that model, onboarding one service took two or three SREs and typically two or three quarters of a year.</p>

<p>The production readiness checklist I use has six lines:</p>

<ol>
  <li>A deploy that finishes an in-flight sign-up or payment once, and that you can undo.</li>
  <li>An alert that reaches a person before a customer emails.</li>
  <li>A backup someone has restored, not only taken.</li>
  <li>A named owner, and a second person, for every account and key.</li>
  <li>A cap on AI and cloud spend that can stop a loop.</li>
  <li>A way to keep shipping if the builder’s publish is stuck.</li>
</ol>

<p>I do not want the ceremony that comes with the long version.</p>

<h2 id="can-a-deploy-break-a-sign-up-or-a-payment-already-in-flight">Can a deploy break a sign-up or a payment already in flight?</h2>

<p>Zero downtime deployment is the name for a release that does not drop work already in flight. At this size, that means two things: a sign-up or payment already started still finishes once, and a bad version can be replaced by the previous one before the next customer feels it.</p>

<p>On Lovable, the pages a visitor sees are a snapshot. The live site keeps the last version you published until you publish again. Accepting a draft is a different event. Lovable says a draft’s changes to the database structure, file storage settings, and backend functions take effect in the live app immediately. The new screens wait for publish. You can break sign-up or checkout while the page still looks the same.</p>

<p>Stripe accepts an idempotency key on create and update: an id you attach so a retry counts as the same attempt. On API v1, Stripe saves the first response that actually starts, including a 500, and returns it for the same key. A key can be removed after at least 24 hours, and the parameters have to match. That covers a dropped connection. An old copy of the app can still create a new charge under the old rules, because that charge has a new key.</p>

<p>One marketplace launch sat for more than two weeks on that question: during a deploy, can the old instances keep processing Stripe payments after the new safeguards ship. Until you can say which version may take money while both are up, and what happens to a payment that started before the safeguard, the launch is not ready. A half-finished sign-up is the same ticket: the person is in the database, and the mail never went.</p>

<p>Rollback has to be a step you have timed. On Vercel, Instant Rollback points production domains at a previous deployment, usually within seconds. Hobby goes back only one production deployment. Pro and Enterprise can use any deployment already aliased to production. You get that older build, not environment variables changed afterwards, and not the database. New pushes then stay off production until you promote a deployment again.</p>

<p>On Lovable, revert restores the code and redeploys the edge functions, the server-side functions. It does not roll the database back or undo structure changes a draft already applied. History marks the version customers currently see. Very old versions can be previewed and not restored. Unpublish takes the URL offline, current version included. If the only way back is a chat message that says “undo it”, time that message.</p>

<h2 id="how-do-you-know-it-is-broken-before-a-customer-emails">How do you know it is broken before a customer emails?</h2>

<p>The homepage can look fine while checkout is dead. I want two messages, both to a person.</p>

<p>First, an uptime check that does not run on the app’s host. Something else requests the public URL and tells you when it fails. If the host fell over, mail from that host may never leave. There is no rota. The pager is your phone, or one named person’s.</p>

<p>Second, the paths that take money or create an account. A page can load and still refuse every card, or fail to send the sign-up mail. Those failures show in the payment account and in the app’s errors. I would rather get that note at 22:00.</p>

<h2 id="have-you-restored-a-backup-or-only-taken-one">Have you restored a backup, or only taken one?</h2>

<p>A backup nobody has restored is a rumour about a file. This check is done when a restore has been run once, on a copy if you already have customers, and someone has signed in and recognised the data.</p>

<p>Lovable backs up its built-in database once a day and keeps up to roughly 14 days. A restore writes that backup into the same project and cannot be undone. Later rows and the database structure go back with it, so the app may no longer match, and the database is down for a few minutes. Storage files are not included. Scheduled jobs and email sending are not reliably restored. Anyone with edit access can press it. Export first if you need today’s data. The export is a file, not a restore point, and deleting the database deletes an export left in project storage.</p>

<p>On a Supabase project you connected yourself, Lovable does not run the backups. Pro, Team, and Enterprise get a daily backup for 7, 14, and up to 30 days. The project is inaccessible during a restore. Storage files are not in the backup. Free projects are told to export and keep the dump off-site. Paid projects with physical backups can restore into a new project, which keeps the test off the live database. That clone starts any scheduled jobs it copied, so a quiet test can email a customer. Leave those jobs off, or use an export you control.</p>

<h2 id="who-holds-the-keys">Who holds the keys?</h2>

<p>For each account I write the owner, the second person, and how you get in next month.</p>

<p>The domain and DNS. The host. The payment account, in the company’s name, with two people who can issue a refund. The email that sends password resets and receipts, because sign-up is unfinished if that mail never leaves. The database: Lovable’s built-in backend is billed as workspace credits, and Lovable manages backups and the instance. A Supabase project you connected is billed by Supabase, and those controls sit in the Supabase dashboard. The API keys. OpenAI shows a service-account secret once, and you cannot view it again there. The company should be able to replace a key without finding the person who saved it.</p>

<p>The ordinary failure is a personal login, away the week you need a refund or a DNS change. Keep those accounts in a password manager the company owns.</p>

<h2 id="what-stops-a-loop-from-spending-the-budget-overnight">What stops a loop from spending the budget overnight?</h2>

<p>A job that calls a model, or retries forever on failure, does not get tired. On one product a loop kept running and burned usage credits, with nobody watching. I want a cap that stops spend, and an alert that fires earlier. The alert leaves the loop running.</p>

<p>On the OpenAI API, a monthly spend limit can watch the bill without blocking requests. “Enforce a hard limit” fails requests after tracked spend hits the number. Enforcement is not instant, so spend can run a little past it. Alerts do not stop traffic. You can set this on the organisation and on a project. With the hard limit off, the number was a chart.</p>

<p>On Vercel, Spend Management is on Pro and on Enterprise Flexible Commitment. A budget does not stop usage on its own. Pausing production, on a team or project budget, stops those sites when spend hits the amount. Checks run every few minutes, so spend can continue briefly past the line, and the pause does not stop AI Gateway, v0, or storage charges. Visitors see an error. Set the number under the spend that would wreck the month.</p>

<p>On Lovable, running out of credits or hitting a credit limit can pause the project, database included. You cannot export until you resume it. A cap that saves the card can also block the backup. Send the alert to a person.</p>

<h2 id="what-do-you-do-if-the-builder-cannot-publish">What do you do if the builder cannot publish?</h2>

<p>A founder’s app got stuck mid-publish during a platform incident, and an urgent customer update could not go out. On Lovable, the calm case is that the live site keeps the last published snapshot until a publish finishes. That does not ship a stuck update, and it says nothing about a day the platform itself is down.</p>

<p>Before that day, three things should sit with the company. The code in a git repository you can open without the builder. Lovable’s backup notes say to keep it in version control, such as GitHub, and to move it with Git sync. A database export and the storage files, kept outside the project: a database restore is not a full copy of the app, and leaving means setting up sign-in, secrets, and email again. And a note on being found if the spare host is not Lovable. I covered that in <a href="https://diogoseca.com/lovable-seo/">Lovable SEO</a>: rendering and the canonical domain do not follow the app on their own.</p>

<p>With those, a stuck publish is a delay. Without them, the status page is your plan.</p>

<h2 id="what-should-the-review-hand-you">What should the review hand you?</h2>

<p>A ranked list you can read without me in the room. A payment that can be taken twice sits above a tidy name. Under it, a short fix plan: the first changes, in order, and the check that shows each one worked. Name the URL requested from outside, the phone that is told, and the person who can put the previous version back.</p>

<p>If you are about to take paying customers, or you already have a few, I do this as a Production Readiness Audit. You get the ranked risks, a remediation plan, and a recorded walkthrough. The scope is the diagnosis and the plan. Here is <a href="https://diogoseca.com/hire/">how that works</a>. There is more about me on the <a href="https://diogoseca.com/">homepage</a>, including the <a href="https://diogoseca.com/#work">work</a>.</p>

<section class="sources" id="sources">
<h2>Sources</h2>
<ol>
<li><span>Google, <a href="https://sre.google/sre-book/evolving-sre-engagement-model/">The Evolving SRE Engagement Model</a>: what a Production Readiness Review is, and the lead time of that model.</span></li>
<li><span>Stripe, <a href="https://docs.stripe.com/api/idempotent_requests">Idempotent requests</a>: keys on create and update, saved responses including 500s, removal after at least 24 hours.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/publish">Publish your Lovable project</a>: the published snapshot, what accepting a draft changes immediately, and unpublish.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/projects/history">Revert and restore your project with version history</a>: revert restores code and edge functions, not database data.</span></li>
<li><span>Vercel, <a href="https://vercel.com/docs/instant-rollback">Performing an Instant Rollback on a Deployment</a>: eligible deployments, timing, and what a rollback leaves untouched.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/database-backups">Back up, restore, and export your project's database</a>: daily retention, what a restore omits, and exports.</span></li>
<li><span>Supabase, <a href="https://supabase.com/docs/guides/platform/backups">Database Backups</a>: retention by plan, free-project exports, and storage left out.</span></li>
<li><span>Supabase, <a href="https://supabase.com/docs/guides/platform/clone-project">Restore to a new project</a>: paid plans with physical backups, and jobs that start on the clone.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/integrations/supabase">Connect to Supabase</a>: who manages backups on the built-in backend and on your own project.</span></li>
<li><span>OpenAI Help Center, <a href="https://help.openai.com/en/articles/9186755-managing-projects-in-the-api-platform">Managing projects in the API platform</a>: spend limits, alerts, and service-account secrets shown once.</span></li>
<li><span>Vercel, <a href="https://vercel.com/docs/spend-management">Spend Management</a>: budgets, pausing, and what a pause does not stop.</span></li>
</ol>
</section>]]></content><author><name>Diogo Seca</name></author><category term="Production" /><category term="AI" /><summary type="html"><![CDATA[A production readiness review checks whether a small AI-built app can take paying customers: deploys, rollback, alerts, backups, keys, and spend.]]></summary></entry><entry><title type="html">Fractional CTO services for AI-built products: what you should actually get</title><link href="https://diogoseca.com/fractional-cto-services/" rel="alternate" type="text/html" title="Fractional CTO services for AI-built products: what you should actually get" /><published>2026-11-10T00:00:00+00:00</published><updated>2026-11-10T00:00:00+00:00</updated><id>https://diogoseca.com/fractional-cto-services</id><content type="html" xml:base="https://diogoseca.com/fractional-cto-services/"><![CDATA[<p>Fractional CTO services give you senior technical ownership for part of the week. For a product you built yourself with Lovable, Bolt, Replit, v0 or Cursor, that means launch decisions, a production setup, and a written plan for who fixes what. Production means a paying customer can use the product, and a named person can repair it when it breaks. You can have that without a full-time hire.</p>

<h2 id="what-are-fractional-cto-services">What are fractional CTO services?</h2>

<p>A fractional CTO is an experienced CTO who works part-time and owns the technical decisions and the outcomes. You are hiring judgement, and a result you can point at, for part of the month.</p>

<p>A freelance developer delivers tasks you have already defined. An agency sells a build. A full-time CTO is a salary and a long commitment, which is more than an early product usually needs. An interim CTO covers a gap, often while a full-time hire is found, and then leaves.</p>

<p>The same part-time role is also called CTO as a service, or a part-time CTO. Judge it by the outcomes you can check.</p>

<h2 id="why-the-usual-service-list-doesnt-fit-an-ai-built-product">Why the usual service list doesn’t fit an AI-built product</h2>

<p>Most fractional CTO services assume there is already an engineering team. The offer is to lead that team, set up a process, and mentor developers. If you built the product yourself, that team may not exist. You have the AI tool, and maybe one freelancer.</p>

<p>What you need is a safe launch, one owner for the technical decisions, and the freedom to keep building at the speed you already have.</p>

<p>A safe launch means a paying customer sees a finished product. A published site can still show the builder’s demo controls: buttons, sample records, or hints that were only there so someone could click through. Remove them before anyone pays. The customer should see the product.</p>

<p>One owner means a named person who can decide and who can fix. Keeping your speed means you stay in the tool you used to build. Lovable, Bolt, Replit, v0, or Cursor can stay. The tool is how you build. The fractional CTO owns the decisions around the live product.</p>

<h2 id="what-you-should-get-in-the-first-30-days">What you should get in the first 30 days</h2>

<p>The question under this stage is a plain one. Who fixes it when it breaks?</p>

<p>Ask for four things you can read.</p>

<ol>
  <li>
    <p><strong>A written picture of what is live, and what it depends on.</strong> Hosting, the domain, payments, and the email the product sends, with the name of a person who can log in to each. Hosting is where the app runs. The domain is the address customers type. If one person is the only name on every row, a lost password or a week away can stop the business. The picture should be short enough to read in one sitting.</p>
  </li>
  <li>
    <p><strong>The two or three risks that could hurt a paying customer, ranked.</strong> I put a broken sign-up first, then a payment that takes the money and does not deliver, then a host, domain, or payments login that only one person can open. Rank by the harm to a customer, and by how soon a customer will hit it. A long list of tidy-ups can wait.</p>
  </li>
  <li>
    <p><strong>A launch or fix plan with dates.</strong> Each line names something a customer will be able to do, and the day you are aiming for. A useful line: a new customer can sign up, pay, and come back the next day.</p>
  </li>
  <li>
    <p><strong>The name of the person who fixes a break, and the accounts they can open.</strong> I built HowRisky.ai end to end on my own. It is paused now. There was no second person to fix it. That is a normal way to start. Once paying customers depend on a product, write down a second person who can open the accounts. If the only route is a support ticket with the company behind the builder, you and the customer are both waiting on a queue.</p>
  </li>
</ol>

<h2 id="what-a-good-month-looks-like-after-that">What a good month looks like after that</h2>

<p>A good month after that is shipping with you.</p>

<p>The roadmap is the list of what you might build. We put it in order from what a customer is waiting on. The rest can wait.</p>

<p>A release is a change that reaches customers. We decide how a release goes live, and how you step back if sign-up or payment breaks. You should know which version customers are using.</p>

<p>When the choice is to hire a developer or keep building with the AI tool, I will write the recommendation in a few sentences: what you gain, what you take on, and what I would do. The aim is to keep your speed.</p>

<p>Customers have to be able to find the product, including when they ask an AI assistant. If you built it in Lovable, I have written up <a href="/lovable-seo/">what still keeps the app out of Google and ChatGPT</a>.</p>

<p>If an investor or a partner asks how the product is built, and what happens when it fails, you should be able to answer in plain words. I can join that conversation when it helps.</p>

<p>Keep building in the tool you already use. I will work with Lovable, Bolt, Replit, v0, or Cursor. The work is the launch, the accounts, the releases, and the decisions you want a second person for.</p>

<h2 id="what-to-skip-and-what-you-shouldnt-pay-for-yet">What to skip (and what you shouldn’t pay for yet)</h2>

<p>Some of the work on offer spends the months you needed for customers.</p>

<p>Skip a long architecture document. Here, architecture means a map of every piece and how it might grow later. You need the short picture of what is live. A long map, written for a team that is not hired yet, does not get a customer.</p>

<p>Skip a rewrite “to do it properly”. A rewrite throws away the product you have and builds another one. You lose the speed that got you this far. Repair the path a paying customer uses: what they see, what they can do, and whether they get what they paid for.</p>

<p>Skip hiring a team before customers are paying. A team is a monthly cost and a management job. While you are still finding who pays, a fractional CTO, or one freelance developer, can ship the next thing.</p>

<p>Skip an enterprise process. I mean approval chains and a meeting rhythm copied from a large company. Those assume a department. You are still the person who talks to customers.</p>

<p>Each of these spends money and weeks before you know whether the product earns it.</p>

<h2 id="fractional-cto-technical-cofounder-or-a-freelance-developer">Fractional CTO, technical cofounder or a freelance developer?</h2>

<p>Some founders who are not engineers start by looking for a technical cofounder, because it is the route they have heard of. There are three fits. Choose from what you want to share, and from what you need done.</p>

<p>A technical cofounder joins the company. They usually take equity, which is a share of the company, and they take on a long commitment. This fits when you want a partner who will own the product for years, and you are willing to share the company to get that.</p>

<p>A freelance developer delivers a task you can point at. A page, a payment step, a bug whose cause you already know. This fits when the decision is made and you need someone to build it. The work ends when the task ends.</p>

<p>A fractional CTO is paid for part-time ownership of the decisions and the outcomes. The engagement has a boundary. This fits when you want a senior person for the launch and the months after it, paid in cash for an agreed period.</p>

<p>Compare cash with equity, over the time you actually need the help. A cofounder can ask for little cash and a meaningful share. Fractional CTO services are a cash cost for an agreed period. Which is cheaper depends on that share, and on how long the help has to last.</p>

<p>If you want a partner for the life of the company, talk to cofounders. If you want a defined task built, hire a freelancer. If you want someone to own the technical result while you keep building, hire a fractional CTO.</p>

<h2 id="how-fractional-cto-services-are-usually-priced">How fractional CTO services are usually priced</h2>

<p>Founders ask what a fractional CTO costs, often as an hourly rate or as monthly rates. Ask what arrives in the month before you compare figures. A rate on its own leaves out the work. The offers I have open, and what each one includes, are on <a href="/hire/">how I work</a>.</p>

<p>The common shapes are a monthly retainer for a set number of days or hours, hourly work where the bill follows the tasks, and a fixed first project followed by a retainer if you want to continue.</p>

<p>A bounded first project is the cheapest way to find out if it works. You see how decisions get made, and whether the product moved, before a longer retainer. Keep that first attempt small enough to afford, and clear enough that you learn whether the fit is real. I wrote about that in <a href="/based-aphorisms-5-you-cant-learn-what-you-never-try/">you can’t learn what you never try</a>.</p>

<h2 id="signs-you-need-one-now-and-signs-you-dont-yet">Signs you need one now, and signs you don’t yet</h2>

<p>Hire when one of these is true.</p>

<p>Paying customers are arriving, or a date is set for them to arrive. You are the only person who understands the setup. A partner or an investor is asking technical questions, and the honest answers are still in your head. Something broke, and nobody owned the fix.</p>

<p>Fractional CTO services for startups fit that case in particular. The product exists, the founders built it with an AI tool, and there is no engineering team to hand it to.</p>

<p>Wait if you are still finding out whether anyone wants the idea, and you have no users. Wait if the next step is one task a freelance developer can finish. A part-time CTO is extra cost until a product decision needs an owner.</p>

<h2 id="how-to-choose-a-fractional-cto-for-an-ai-built-product">How to choose a fractional CTO for an AI-built product</h2>

<p>When you hire a fractional CTO, ask these before you start.</p>

<p><strong>Have they shipped a product and run it while people used it?</strong> Ask for that, on a real host. Shipping and then running it is the work I do.</p>

<p><strong>Will they work with the AI tool you used?</strong> Ask them to keep Lovable, Bolt, Replit, v0, or Cursor in the workflow. That tool is how you keep shipping quickly.</p>

<p><strong>What will they hand you in 30 days?</strong> The written picture of what is live, the ranked risks, the plan with dates, and the name of who fixes a break. If you cannot check the answer, keep looking.</p>

<p><strong>How many clients do they take on?</strong> I take a small number of engagements each quarter, so each client gets senior attention.</p>

<p><strong>At the end, who owns the accounts, the domain, and the code?</strong> You should. Ask them to say so before you start, so you can keep going if you stop.</p>

<p>If you built the product yourself and it is about to meet paying customers, send me the link and a few lines about where it is. I take AI-built products to production and stay on as a part-time CTO when that helps. Here is <a href="/hire/">how I work</a>. There is more about me on the <a href="/">homepage</a>.</p>]]></content><author><name>Diogo Seca</name></author><category term="AI" /><category term="Production" /><category term="Fractional CTO" /><category term="Startups" /><summary type="html"><![CDATA[Fractional CTO services for founders who built with AI: what you should get each month, what to skip, and how to tell if you need one yet.]]></summary></entry><entry><title type="html">Lovable SEO: what keeps apps off Google and ChatGPT</title><link href="https://diogoseca.com/lovable-seo/" rel="alternate" type="text/html" title="Lovable SEO: what keeps apps off Google and ChatGPT" /><published>2026-11-05T00:00:00+00:00</published><updated>2026-11-22T00:00:00+00:00</updated><id>https://diogoseca.com/lovable-seo</id><content type="html" xml:base="https://diogoseca.com/lovable-seo/"><![CDATA[<p>Yes. A Lovable app can rank on Google and be cited in ChatGPT. Since 13 May 2026, Lovable has handled most of the rendering that used to leave crawlers with an empty page. Lovable SEO now comes down to four things you control:</p>

<ol>
  <li><strong>The stack.</strong> TanStack Start sends full HTML to everyone. The older React and Vite stack relies on pre-rendering for verified crawlers.</li>
  <li><strong>The host.</strong> That pre-rendering is part of Lovable hosting. Moving the app means checking the HTML again.</li>
  <li><strong>The domain.</strong> One primary custom domain, named in the canonical tags and the sitemap.</li>
  <li><strong>The public pages.</strong> What the product does, who it is for, and the price, in the text a crawler receives.</li>
</ol>

<p>You do not need a rewrite, and Lovable says a project it hosts does not need an external pre-rendering service.</p>

<p>I last checked this against the sources listed at the end on 22 November 2026.</p>

<h2 id="does-lovable-have-seo-built-in">Does Lovable have SEO built in?</h2>

<p>Yes, for the foundations. Lovable’s docs say a published app returns readable HTML to search engines and AI crawlers. HTML is the page as text, before a browser draws it. A crawler is a program that fetches pages for a search engine or an assistant. If its first response is empty, it has little to keep.</p>

<p>New projects created from 13 May 2026 use TanStack Start. New Enterprise projects followed on 22 June 2026. TanStack Start uses server-side rendering (SSR): the server builds the finished page, so every visitor and every tool gets the same HTML on every request.</p>

<p>Older projects use React and Vite. When a verified crawler asks for a published public URL, Lovable pre-renders the page and returns the HTML. The list includes Google and Bing, the AI search crawlers of ChatGPT, Perplexity, Claude and Gemini, social preview bots, and verified SEO tools. Tools outside that list see very little, unless they ask for a Markdown copy, which Lovable serves on both stacks.</p>

<p>Lovable also has an SEO and AI search review. You run it from the SEO &amp; AI tab in Analytics (More, then Analytics, in the project toolbar). It checks the sitemap, <code class="language-plaintext highlighter-rouge">robots.txt</code>, metadata, Open Graph tags, structured data, headings, alt text, canonical tags, indexing, and whether AI crawlers get a Markdown copy. A canonical tag names the address you want treated as the real copy of a page. Lovable’s docs also say ranking still depends on content quality, search intent, links from other sites, and competition.</p>

<h2 id="which-lovable-stack-is-your-app-on">Which Lovable stack is your app on?</h2>

<p>Ask in the project chat: “What stack is this project on?”</p>

<p>On TanStack Start, a buyer, a link preview, and a search crawler see the same full page.</p>

<p>On React and Vite, the pre-rendered snapshot usually includes content that loads with the page. Content that loads late may be missing. A pricing page can be stored without the price. Lovable pre-renders for social preview bots too, but its upgrade page still lists reliable link previews as a gain of TanStack Start. Each page also needs its own Open Graph tags: the title, description and image a shared link shows. An SEO scanner outside Lovable’s verified list gets the bare single-page app, so it may call the page empty while Google receives the rendered copy. Treat the scanner as a hint.</p>

<p>You can upgrade in place. Lovable says most upgrades cost 10 to 35 credits, depending on the size of the project. The live site keeps the old version until you publish, and you can restore the earlier version from history if the result is wrong. I would upgrade whenever search or link previews matter.</p>

<h2 id="how-do-you-check-what-google-sees-and-what-should-be-public">How do you check what Google sees, and what should be public?</h2>

<p>Run this on the pages that sell: home, pricing, and the page that says who it is for.</p>

<ol>
  <li>Publish, then verify the site in Google Search Console. Lovable can verify it and submit the sitemap for you from the SEO &amp; AI tab.</li>
  <li>Open URL Inspection and paste one full address. You get the copy Google stored and a live test.</li>
  <li>Click <strong>View crawled page</strong> and read the HTML as a customer. Look for the price, who it is for, and the offer. If those sentences are missing, Google may not have them.</li>
  <li>Compare the canonical you declared with the one Google selected. Fix any mismatch first.</li>
</ol>

<p>Google’s JavaScript guide says content has to be in the rendered HTML before Google can index it, and rendering can wait in a queue. SSR and pre-rendering put the words in the first response, which also helps bots that never run JavaScript. “URL is on Google” means the page may appear. It does not mean it ranks.</p>

<p>Those selling pages have to be public and complete. Say what the product does, who it is for, and the price or how pricing works. Give one use case. Answer the objection buyers already raise. Put it in the visible text, not in a panel that fills in after a database call.</p>

<p>Dashboards and customer data stay behind the login. Google’s JavaScript guide suggests a 401 status code for pages behind a login. ChatGPT can only cite what it can read.</p>

<h2 id="what-changes-when-you-move-your-lovable-app-off-lovable-hosting">What changes when you move your Lovable app off Lovable hosting?</h2>

<p>Lovable describes pre-rendering as part of its hosting, and its guide to hosting elsewhere does not mention it. Assume it stays behind, and treat the move as a fresh launch for search.</p>

<p>Lovable’s deployment guide splits the move by stack:</p>

<ul>
  <li><strong>React and Vite</strong> leaves as static files. The browser builds the page. I would upgrade to TanStack Start before you leave, or make sure the new host returns real HTML on the first response some other way.</li>
  <li><strong>TanStack Start</strong> needs a host that runs the server part. The guide names Vercel, Netlify, and Cloudflare Pages, and also covers a container or your own server. A host that receives only the static files does not run server-side rendering.</li>
</ul>

<p>The guide says to deploy to a temporary URL first and compare it with the version on Lovable: open a nested route directly, sign in and out, and run the reads and writes the app depends on. For search, also open the page source and confirm the words are in the HTML. The page source shows what a crawler that does not run JavaScript receives. The browser’s inspector does not.</p>

<p>When the new host checks out, point the custom domain at it. Your <code class="language-plaintext highlighter-rouge">lovable.app</code> address stays with Lovable and keeps serving the last version you published there, until you unpublish it. Then confirm that old addresses redirect, canonical tags name the new primary domain, and the sitemap lists that domain, not the Lovable host.</p>

<h2 id="which-address-is-your-real-site">Which address is your real site?</h2>

<p>Use one primary custom domain. Lovable lets you connect several. With a primary set, the others redirect to it with a temporary HTTP 302, because you can change the primary later. Lovable hosting does not offer a permanent 301 between connected domains. If you unset the primary, all connected domains serve the project equally. The same pages then live at several addresses, and your canonical tags have to say which one counts.</p>

<p>Put the primary domain in the canonical tags and the sitemap. Lovable’s review flags canonicals that point at the homepage when they should not, and sitemaps that point at another host.</p>

<p>Custom domains are on paid plans. A <code class="language-plaintext highlighter-rouge">lovable.app</code> address is fine for a demo. Search presence belongs on a domain you control. Once it is live, verify it in Search Console and submit the sitemap. If you change the primary, verify the new one and run the review again.</p>

<p>Some addresses never appear in search: branded workspace URLs (app name, then workspace, then <code class="language-plaintext highlighter-rouge">lovable.app</code>), unpublished projects, and projects whose access is limited to the workspace or named people.</p>

<h2 id="what-makes-chatgpt-perplexity-or-googles-ai-answers-cite-a-page">What makes ChatGPT, Perplexity or Google’s AI answers cite a page?</h2>

<p>No file buys a citation. The work is to make a public page worth quoting.</p>

<p>Google says AI Overviews and AI Mode use the same foundations as ordinary search. A page has to be indexed and allowed to show a snippet. No new file or special markup is required. If you add structured data, it should match the visible text.</p>

<p>OpenAI runs separate crawlers with independent settings. OAI-SearchBot places a site in ChatGPT search answers. Block it in <code class="language-plaintext highlighter-rouge">robots.txt</code> and the site will not be shown there, except as a navigational link. GPTBot collects content that may be used for training. You can allow search and block training. ChatGPT-User is a visit a person starts, and OpenAI says it is not used to decide what appears in search.</p>

<p>PerplexityBot builds Perplexity’s search results. Perplexity-User fetches a page when someone asks a question and generally ignores <code class="language-plaintext highlighter-rouge">robots.txt</code>. Allow the search bot. A <code class="language-plaintext highlighter-rouge">robots.txt</code> change takes about a day to apply at OpenAI, and up to a day at Perplexity.</p>

<p>Lovable says <code class="language-plaintext highlighter-rouge">llms.txt</code> is not required. I would spend the time on the page instead: a direct answer to a buyer’s question near the top, facts in the visible text, structured data that matches them, and links from other sites. None of it forces a citation.</p>

<h2 id="what-does-lovables-seo-review-not-tell-you">What does Lovable’s SEO review not tell you?</h2>

<p>Lovable says the review does not fully evaluate content quality, search intent, backlinks, competitor strength, or whether the topic is worth targeting. It no longer runs Lighthouse, so it reports no page speed score. For speed, use PageSpeed Insights on the published URL. The review also does not run again on its own when you publish. A green review means the checks it knows how to run pass.</p>

<p>That is Goodhart’s law, which I wrote about in <a href="/based-aphorisms-nothing-more-practical-than-a-good-theory/">nothing more practical than a good theory</a>. A measure that becomes the goal stops telling you what you cared about. The goal is a buyer finding the page and recognising the offer.</p>

<p>On my own site, <code class="language-plaintext highlighter-rouge">scripts/check_seo.py</code> blocks any change where a page has more than one H1, no meta description, a canonical that does not match the sitemap, or more than one structured-data block. After a merge, the site notifies participating search engines through IndexNow. The script stops a broken page shipping. It does not know whether the page is worth reading. Lovable’s review has the same boundary.</p>

<p>I take AI-built prototypes, Lovable apps included, to production for a fixed price, from €2,500. If your Lovable app is about to go live, or you are moving it off Lovable hosting, <a href="/hire/#quote">ask for a quote</a>. Here is <a href="/hire/">how I work</a>. There is more about me on the <a href="/">homepage</a>.</p>

<section class="sources" id="sources">
<h2>Sources</h2>
<ol>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/seo-aeo">Optimize your app for SEO and AI search</a>: where the review lives, what it checks and does not fully evaluate, server-side rendering from 13 May 2026 (22 June 2026 on Enterprise), pre-rendering for verified crawlers, llms.txt, and which URLs never appear in search.</span></li>
<li><span>Lovable, <a href="https://lovable.dev/blog/building-is-just-the-beginning-introducing-discoverability">Building is just the beginning: Introducing Discoverability</a> (13 May 2026): complete HTML for new apps and pre-rendering for existing apps from that date.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/upgrade-to-tanstack-start">Upgrade a project to TanStack Start</a>: what server-side rendering changes, reliable link previews, the 10 to 35 credit range, reverting from version history, and tools outside the verified list.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/custom-domain">Set up a custom domain</a>: one primary domain, temporary redirects from the others, and verifying the domain again after a change.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/features/hosting">How Lovable hosts your app</a>: Lovable hosting serves rendered pages, and outside scanners can report an older app as empty.</span></li>
<li><span>Lovable, <a href="https://docs.lovable.dev/tips-tricks/external-deployment-hosting">Deploying and hosting outside Lovable</a>: what each stack needs from a new host, testing on a temporary URL, and what happens to the lovable.app address.</span></li>
<li><span>Google Search Central, <a href="https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics">Understand the JavaScript SEO basics</a>: rendering can wait in a queue, content has to be in the rendered HTML, and a 401 status code for pages behind a login.</span></li>
<li><span>Google Search Central, <a href="https://developers.google.com/search/docs/appearance/ai-features">AI features and your website</a>: AI Overviews and AI Mode use the same foundations as Search, with no extra file or markup required.</span></li>
<li><span>Google Search Console Help, <a href="https://support.google.com/webmasters/answer/9012289">URL Inspection tool</a>: the indexed copy, the live test, the HTML Google received, and the canonical Google selected.</span></li>
<li><span>OpenAI, <a href="https://developers.openai.com/api/docs/bots">Overview of OpenAI crawlers</a>: OAI-SearchBot for ChatGPT search, GPTBot for training, ChatGPT-User for a person's request, and about 24 hours for a robots.txt change to reach search.</span></li>
<li><span>Perplexity, <a href="https://docs.perplexity.ai/docs/resources/perplexity-crawlers">Perplexity Crawlers</a>: PerplexityBot for search results, Perplexity-User for a person's request, and up to 24 hours for a change to apply.</span></li>
</ol>
</section>]]></content><author><name>Diogo Seca</name></author><category term="AI" /><category term="Production" /><category term="SEO" /><category term="Lovable" /><summary type="html"><![CDATA[Lovable apps can rank on Google and be cited by ChatGPT. Lovable handles most rendering. What's left is your stack, host, domain and the pages buyers read.]]></summary></entry><entry><title type="html">Based Aphorisms 2: The Numbers Can Be Right and You Can Still Be Wrong</title><link href="https://diogoseca.com/based-aphorisms-2-the-numbers-can-be-right-and-you-can-still-be-wrong/" rel="alternate" type="text/html" title="Based Aphorisms 2: The Numbers Can Be Right and You Can Still Be Wrong" /><published>2026-10-22T23:00:00+00:00</published><updated>2026-10-22T23:00:00+00:00</updated><id>https://diogoseca.com/based-aphorisms-2-the-numbers-can-be-right-and-you-can-still-be-wrong</id><content type="html" xml:base="https://diogoseca.com/based-aphorisms-2-the-numbers-can-be-right-and-you-can-still-be-wrong/"><![CDATA[<p><em>Probability has an excellent sense of humour. Usually at our expense.</em></p>

<p>Suppose you’re tested for a rare condition. The result comes back positive. The test has 99% sensitivity and 99% specificity. How worried should you be?</p>

<p>Most people hear those percentages and picture a 99% chance of having the condition. That would be a spectacularly bad interpretation.</p>

<p>Imagine the condition affects one in 10,000 people. Test 100,000 people, for simplicity. About 10 actually have it; a 99%-sensitive test correctly flags roughly 9.9 of them. Of the other 99,990 people, a 99%-specific test incorrectly flags roughly 999.9.</p>

<p>Among the roughly 1,010 positive results, only about 10 correspond to real cases. The positive predictive value is <code class="language-plaintext highlighter-rouge">9.9 / (9.9 + 999.9) ≈ 0.98%</code>, before any further information about the individual is considered. These fractional counts are expectations in a hypothetical population, not a prediction that every real sample will contain exactly this mix.</p>

<p>Nothing is broken. The test performed exactly as specified. The mistake was ours: we forgot to ask how common the condition was in the first place.</p>

<p><strong>“Before asking how good the test is, ask how common the thing is.”</strong> That’s base-rate reasoning, one of the most practical applications of conditional probability. It’s also a good introduction to a larger, occasionally humiliating idea: the numbers can be correct while the story we tell about them is wrong.</p>

<h2 id="probability-isnt-the-same-as-a-verdict">Probability isn’t the same as a verdict</h2>

<p>The rare-condition example is a version of Bayes’ theorem: what you conclude from new evidence depends on what was plausible before it arrived, and on the chances of seeing that evidence under competing explanations.</p>

<p>It is also why scientific findings need context. If researchers test enormous numbers of highly speculative hypotheses, even statistically significant results may include many false positives. John Ioannidis explored these mechanisms in <a href="https://journals.plos.org/plosmedicine/article?id=10.1371%2Fjournal.pmed.0020124">a much-discussed 2005 model</a>. His conclusion that <em>most</em> published findings are false is not itself a universal theorem or an empirically established percentage; <a href="https://journals.plos.org/plosmedicine/article?id=10.1371%2Fjournal.pmed.0040168">Goodman and Greenland questioned that stronger interpretation</a>. But the basic base-rate mathematics survives the disagreement.</p>

<p>This leads to the advice <strong>“Never be certain of anything you could be wrong about.”</strong> Statisticians know it as <em>Cromwell’s rule</em>: don’t assign a contingent, learnable proposition a probability of exactly zero or one without extraordinary justification.</p>

<p>Why? If your prior probability for a hypothesis is exactly zero, ordinary Bayesian updating cannot lift it above zero, no matter how striking the evidence. A numerical certainty about the empirical world can become a refusal to learn. Logical impossibilities are a different matter; they don’t need a polite sliver of probability just in case.</p>

<p>Yet refusing certainty doesn’t mean treating every possibility as equally likely. It means leaving room to update in proportion to evidence.</p>

<p>And what if the evidence never appears?</p>

<p>You’ve probably heard <strong>“Absence of evidence is not evidence of absence.”</strong> Sometimes that’s right. Sometimes it’s a dreadful excuse.</p>

<p>If you’ve barely looked for your keys, failing to find them tells you little. If you’ve thoroughly searched every plausible place, the same failure becomes informative. Formally, a negative result counts against a hypothesis when that negative result is <em>less likely</em> if the hypothesis is true than if it’s false.</p>

<p>So a more useful version is <strong>“Absence of evidence can be evidence of absence—if you would have expected to find it.”</strong> The strength of the evidence depends on the search procedure, not on the rhetorical confidence of the person doing the searching.</p>

<h2 id="extreme-days-and-miraculous-coincidences">Extreme days and miraculous coincidences</h2>

<p>There’s another way our intuitions fail. We think events are meaningful because they are unusual, without accounting for how many chances there were for something unusual to happen.</p>

<p>Take <strong>“Extreme results are usually followed by ordinary ones.”</strong> Francis Galton described <em>regression toward the mean</em> while studying inherited height, in <a href="https://doi.org/10.2307/2841583">work published in 1886</a>.</p>

<p>Imagine a salesperson whose performance is a mixture of ability and luck. On an extraordinarily good month, the result probably includes some unusually good luck. If luck does not repeat, the next month will tend to be closer to the person’s usual level, even if nothing about their ability or effort changes.</p>

<p>That’s why managers can convince themselves that scolding someone after a terrible month works, or that praising someone after an excellent month backfires. In both cases, ordinary statistical reversion may be doing much of the work.</p>

<p>Regression to the mean isn’t magic, and it doesn’t govern every time series. It arises when repeated measurements are imperfectly correlated. If a process has no random variation—or if an extreme outcome permanently changes the underlying system—the simple story may fail.</p>

<p>Now scale the number of opportunities in the opposite direction.</p>

<p><strong>“With enough chances, the miraculous becomes ordinary.”</strong> Persi Diaconis and Frederick Mosteller studied the mathematics of coincidence in <a href="https://doi.org/10.1080/01621459.1989.10478847">their 1989 paper</a>. The <em>law of truly large numbers</em> is a persuasive probabilistic principle, not a promise that every imaginable event must occur.</p>

<p>Suppose an event has an independent one-in-a-million chance on each attempt. After a million attempts, the chance of at least one occurrence is about 63%. After ten million attempts, it’s about 99.995%.</p>

<p>The arithmetic is simply:</p>

<p><code class="language-plaintext highlighter-rouge">P(at least one) = 1 − (1 − p)^n</code></p>

<p>Of course independence is an assumption, and real-life coincidences rarely offer a neat fixed probability. But the mechanism matters. Millions of people live through millions of moments. Some will experience coincidences that feel astronomically unlikely when considered <em>after</em> they happen.</p>

<p>The trap is choosing the astonishing event first, then forgetting the enormous universe of other events that could have astonished us instead.</p>

<h2 id="your-friends-are-not-a-random-sample-of-people">Your friends are not a random sample of people</h2>

<p>Speaking of misleading perspectives, here’s an especially cruel mathematical observation: <strong>“Your friends have more friends than you do.”</strong></p>

<p>Not necessarily <em>each</em> friend. And not necessarily you personally. But the average across a social network has a systematic bias.</p>

<p>Scott Feld showed this in <a href="https://doi.org/10.1086/229693">his 1991 paper on the friendship paradox</a>. People with many connections turn up in lots of other people’s friend lists. People with very few connections appear in fewer. So if you sample people <em>through their friendships</em>, highly connected people are overrepresented.</p>

<p>For an undirected network with positive average degree, choose a friendship uniformly at random, then choose one of its two endpoints with equal probability. The mean degree of the person sampled this way is:</p>

<p><code class="language-plaintext highlighter-rouge">E[degree of a friend] = E[degree²] / E[degree]</code></p>

<p>This is at least as large as the average degree of a uniformly selected person, and is strictly larger when degrees vary. Sampling a random person first and then one of their friends is a different procedure; the formula above does not generally describe it. That is a mathematical statement about sampling in a network; the impression that everyone else has a better social life is the psychological extrapolation.</p>

<p>The same size-biasing logic helps explain why a crowded place can seem more representative than it is, or why your online feed makes particular experiences seem universal. You’re not looking through a neutral window. You’re looking through a sampling mechanism.</p>

<p>And sometimes the mechanism doesn’t merely exaggerate a pattern. It can reverse one.</p>

<h2 id="two-statistics-can-tell-opposite-stories-without-either-lying">Two statistics can tell opposite stories without either lying</h2>

<p>In the autumn of 1973, graduate admissions at the University of California, Berkeley appeared to show a striking pattern: a higher proportion of men were admitted than women.</p>

<p>Looking more closely at admissions by department told a different story. Women were disproportionately applying to departments with lower acceptance rates for <em>everyone</em>. Once departmental differences were considered, the university-wide figures did not support the simple conclusion that admissions committees were systematically discriminating against women.</p>

<p>This is the famous Berkeley case examined by <a href="https://doi.org/10.1126/science.187.4175.398">Bickel, Hammel and O’Connell in 1975</a>.</p>

<p><strong>“The whole can tell the opposite story of its parts.”</strong> Simpson’s paradox describes situations in which an aggregate association changes, or even reverses, when data is partitioned into relevant groups.</p>

<p>This does <em>not</em> mean that the answer is always to break data into smaller buckets. Conditioning on the wrong variable can create its own distortions. And explaining a statistical pattern by department does not settle every question about earlier inequalities that influenced which departments people applied to.</p>

<p>It means the causal question comes first: <em>What are we trying to compare, and what determined which group each observation entered?</em></p>

<p>There’s an even sneakier cousin.</p>

<p>Imagine a company recruits candidates who are exceptionally good at programming <strong>or</strong> exceptionally good at communication. In the general population, suppose those two skills are independent. But among candidates who pass that initial filter, someone weak at programming must usually be strong at communication to make the cut—and vice versa.</p>

<p>Suddenly the two skills appear negatively related, even though no such relationship existed in the population. You’ve created a correlation simply by selecting on a shared outcome.</p>

<p>This is <strong>“If you only see a filtered group, you’ll find links that don’t exist,”</strong> the intuition behind <em>Berkson’s paradox</em>. Joseph Berkson described the problem in <a href="https://doi.org/10.2307/3002000">hospital samples in 1946</a>. In modern causal language, conditioning on a collider can induce an association between otherwise independent causes. The direction and size depend on how selection works; negative correlation isn’t guaranteed by every filter.</p>

<p>A dataset can be accurate, complete <em>for the people it includes</em>, and still be misleading about everyone outside it.</p>

<h2 id="ask-how-the-numbers-got-there">Ask how the numbers got there</h2>

<p>All these ideas lead to a fairly humbling conclusion. A number does not come with its interpretation attached.</p>

<p>Before deciding what a probability, average, correlation, or significant result means, we need to know where the observations came from, which observations were missing, what population we’re talking about, and how the measurement was produced.</p>

<p>This is why I find the mathematics so comforting, in a strange sort of way. It doesn’t eliminate uncertainty or guarantee that I’ll reach the right conclusion. It shows me exactly where intuition is liable to take an expensive shortcut.</p>

<p>The next time a statistic seems to settle an argument, I’ll probably ask one more question before believing it.</p>]]></content><author><name>Diogo Seca</name></author><category term="Probability" /><category term="Statistics" /><category term="Decision Making" /><category term="Logic" /><summary type="html"><![CDATA[Why a 99%-sensitive test can mislead you, why friends seem more popular, and how selection bias turns correct data into wrong conclusions.]]></summary></entry><entry><title type="html">Based Aphorisms 3: The Average Doesn’t Happen to You</title><link href="https://diogoseca.com/based-aphorisms-3-the-average-doesnt-happen-to-you/" rel="alternate" type="text/html" title="Based Aphorisms 3: The Average Doesn’t Happen to You" /><published>2026-10-22T23:00:00+00:00</published><updated>2026-10-22T23:00:00+00:00</updated><id>https://diogoseca.com/based-aphorisms-3-the-average-doesnt-happen-to-you</id><content type="html" xml:base="https://diogoseca.com/based-aphorisms-3-the-average-doesnt-happen-to-you/"><![CDATA[<p><em>Why positive expectations, hard work, and clever optimisation aren’t enough.</em></p>

<p>Imagine I offer you a game. Every round, an independent toss of a fair coin determines what happens to your money. Heads: you gain 60%. Tails: you lose 50%.</p>

<p>A quick calculation gives an expected return of 5% per round. A positive expected return! Some people would call that a good investment.</p>

<p>Let’s play twice. Start with €100. Win the first round and you’re at €160. Lose the second and you’re at €80. Lose first, then win, and you’re still at €80.</p>

<p>The order doesn’t rescue you. A win and a loss leave you 20% poorer.</p>

<p>Over repeated independent rounds, the expected <em>wealth across many possible trajectories</em> grows by a factor of 1.05 per round. Yet the typical compounded trajectory heads in the other direction. Its long-run growth factor per round is the geometric mean:</p>

<p><code class="language-plaintext highlighter-rouge">√(1.60 × 0.50) ≈ 0.894</code></p>

<p>The expected log-growth rate is <code class="language-plaintext highlighter-rouge">0.5 ln(1.60) + 0.5 ln(0.50) ≈ −0.1116</code> per round, equivalent to a long-run compounded loss of about 10.6% per round. This is why a strategy can look attractive on an expectation spreadsheet while behaving terribly for someone who has to keep playing it.</p>

<p><strong>“Avoid ruin above all. The average doesn’t happen to you.”</strong></p>

<p>It’s a useful aphorism, not a literal statement that averages never describe individual experience. The underlying distinction is between averages over an ensemble of possible outcomes and growth along a sequence of multiplicative outcomes. Those need not agree. The mathematical issues are developed in <a href="https://doi.org/10.1038/s41567-019-0732-0">Peters’ work on ergodicity economics</a>.</p>

<p>The game, as described, never takes your balance to exactly zero in a finite number of rounds. So saying it <em>guarantees bankruptcy</em> would be wrong. But repeated full-stake play drives typical wealth toward zero, and real people have bills, collateral requirements, and thresholds below which a theoretical recovery is no longer useful.</p>

<p>That changes how I think about risk.</p>

<h2 id="a-profitable-opportunity-can-still-be-a-terrible-position">A profitable opportunity can still be a terrible position</h2>

<p>The first question isn’t simply whether the payoff has a positive expectation. It’s how much to expose to that payoff, for how long, and what happens if the bad outcomes arrive early.</p>

<p>John Kelly approached a version of this problem in <a href="https://doi.org/10.1002/j.1538-7305.1956.tb03809.x">his 1956 paper on information and capital growth</a>. Instead of maximising expected wealth after one round, his criterion maximises expected logarithmic growth for repeated bets under specified conditions.</p>

<p>For our 50/50 game, if I can bet any fraction <code class="language-plaintext highlighter-rouge">f</code> of my wealth, the two multipliers become <code class="language-plaintext highlighter-rouge">1 + 0.60f</code> and <code class="language-plaintext highlighter-rouge">1 − 0.50f</code>. Maximising their expected logarithm gives <code class="language-plaintext highlighter-rouge">f = 1/6</code>, or about 16.7% of wealth per round—not 100%.</p>

<p>That’s a rather different answer from <em>the average payoff is positive, so take the bet</em>.</p>

<p>Kelly sizing relies on knowing the outcome probabilities and payoffs, and on valuing long-run log growth. Those assumptions can fail spectacularly in real markets. But the underlying insight travels well: a good opportunity and a good <em>position size</em> are not the same thing.</p>

<p>When the consequences are irreversible, preserving the ability to try again may matter more than maximizing what looks best on average.</p>

<h2 id="yesterdays-bill-is-not-tomorrows-reason">Yesterday’s bill is not tomorrow’s reason</h2>

<p>Suppose you’ve spent six months building a product. You’re tired, the market has moved, and the evidence suggests a different direction would be better.</p>

<p>You can hear the internal argument already: <em>But I’ve put six months into this.</em></p>

<p>Unfortunately, the calendar isn’t impressed.</p>

<p><strong>“Sunk costs aren’t costs. They’re history.”</strong> As a slogan, that overstates it: sunk costs were real costs when you paid them. The precise decision-theoretic claim is narrower. If a past expense cannot be recovered, and is identical across the options available today, it should not by itself influence which option you choose now.</p>

<p>The time spent may have taught you something about the market, your competence, or the product’s prospects. That information can legitimately affect your forecast of future costs and benefits. What cannot justify continuing is the bare fact that you already paid.</p>

<p>Try a thought experiment. A stranger offers you the exact same project, in its present state, with no history attached. Would you commit your next month to it?</p>

<p>If the answer is no, your previous effort is not an argument for saying yes.</p>

<p>This is a normative principle of rational choice under a specified objective, not a psychological theorem proving what people actually do. The interesting psychology is why we’re so tempted to throw more time after time we’ve already spent.</p>

<h2 id="doing-more-at-once-is-often-doing-things-more-slowly">Doing more at once is often doing things more slowly</h2>

<p>Founders and engineers have another favourite trick: start more work when work isn’t moving quickly enough.</p>

<p>Five features are in progress, so we launch another three. Three clients are waiting, so we open ten more conversations. Everyone is busy; surely progress will follow.</p>

<p>A queueing result called <strong>Little’s law</strong> offers a useful reality check:</p>

<p><code class="language-plaintext highlighter-rouge">Average work in progress = Throughput × Average time in system</code></p>

<p>Or, in the usual notation, <code class="language-plaintext highlighter-rouge">L = λW</code>.</p>

<p>Imagine a team that completes five tasks per week and has twenty tasks in its system on average. Under stable operating conditions, a task spends an average of four weeks in that system.</p>

<p>Now suppose the team starts enough additional work to sustain forty tasks in progress, but throughput stays at five per week. Average time in the system rises to eight weeks.</p>

<p>That’s not a motivational speech against multitasking. It’s a relationship among averages in a stable system, proved by <a href="https://doi.org/10.1287/opre.9.3.383">John Little in 1961</a>. Adding work might improve throughput in an underutilised system, so the law doesn’t prove that <em>starting more tasks always makes everything slower</em>. It does prove that, at unchanged throughput, higher average work in progress means higher average time in the system.</p>

<p>For a team drowning in half-finished projects, this is a helpful distinction. The goal isn’t to look maximally occupied. It’s to improve the flow of completed work.</p>

<p>And once you start asking what really limits a system, a more philosophical question appears: why should the optimisation method you happen to prefer be the right one for this problem?</p>

<h2 id="there-is-no-magic-algorithm-that-wins-everywhere">There is no magic algorithm that wins everywhere</h2>

<p>Machine learning makes it extraordinarily easy to become attached to a method. You see a successful model, copy the architecture, tune the parameters, and hope the success transfers.</p>

<p>But optimisation has an unfriendly result: <strong>“There’s no best method for every problem.”</strong></p>

<p>The <a href="https://doi.org/10.1109/4235.585893">No Free Lunch theorems of Wolpert and Macready</a> show that, for their black-box optimisation setting and the relevant uniform averaging over possible objective functions, improvements on some problem classes are offset by poorer performance on others. Without restricting what the world might look like, no search algorithm enjoys a universal advantage.</p>

<p>The assumptions are crucial. We do <em>not</em> encounter objective functions sampled uniformly from every mathematically possible function. Real-world problems have exploitable regularities, and algorithms can absolutely be better or worse for the distributions we care about.</p>

<p>In fact, that’s the point. Useful performance comes from assumptions, inductive biases, and domain knowledge that fit the problem.</p>

<p>The same is true of human decision strategies. A checklist that is excellent for a routine operational decision may be hopeless for navigating a new market. A strategy designed for repeated independent bets may be inappropriate for an irreversible personal choice.</p>

<p>There is no shame in having a favourite tool. The mistake is forgetting what makes it work.</p>

<h2 id="optimise-for-the-life-youre-actually-living">Optimise for the life you’re actually living</h2>

<p>These four ideas share a theme that took me longer than I’d like to admit to appreciate.</p>

<p>Expected value describes a distribution, not necessarily the life of someone moving through it. Sunk costs describe what has happened, not what should happen next. A large backlog describes activity, not necessarily progress. And an excellent algorithm is excellent only relative to a class of problems.</p>

<p>Each asks us to identify the <em>actual</em> objective, the <em>actual</em> constraints, and the consequences of getting the assumptions wrong.</p>

<p>An impressive average is not enough if your path to it is one you cannot survive. Neither is a busy calendar, a past investment, or a fashionable method.</p>

<p>Practical wisdom is often less about finding a number to maximise than about noticing what must remain possible after you’ve made your choice.</p>]]></content><author><name>Diogo Seca</name></author><category term="Probability" /><category term="Statistics" /><category term="Decision Making" /><category term="Logic" /><summary type="html"><![CDATA[Why positive expected returns can shrink wealth, why sunk costs mislead us, and what queueing theory and optimisation say about real decisions.]]></summary></entry><entry><title type="html">Based Aphorisms 4: The Assumptions Hiding Behind Good Advice</title><link href="https://diogoseca.com/based-aphorisms-4-the-assumptions-hiding-behind-good-advice/" rel="alternate" type="text/html" title="Based Aphorisms 4: The Assumptions Hiding Behind Good Advice" /><published>2026-10-22T23:00:00+00:00</published><updated>2026-10-22T23:00:00+00:00</updated><id>https://diogoseca.com/based-aphorisms-4-the-assumptions-hiding-behind-good-advice</id><content type="html" xml:base="https://diogoseca.com/based-aphorisms-4-the-assumptions-hiding-behind-good-advice/"><![CDATA[<p><em>Some principles tell you what follows. Others tell you what to be careful about.</em></p>

<p>Imagine you’ve just taken over an old software system. It’s full of strange restrictions, redundant-looking checks, and a deployment process that appears designed by someone with a personal grudge against convenience.</p>

<p>Your first impulse is obvious: clean it up.</p>

<p>Then someone tells you that a particular validation rule exists because, seven years ago, a billing bug sent thousands of duplicate invoices. The rule is ugly, yes. So was the incident it prevents.</p>

<p>That doesn’t mean the rule should stay. It means you needed to know what problem it solved before deciding to remove it.</p>

<p><strong>“Before removing a fence, find out why it was put there.”</strong> G. K. Chesterton made the point in <a href="https://catholiclibrary.org/library/view?chunk.id=00000011&amp;docId=%2FContemporary-EN%2FXCT.165.html"><em>The Thing</em> (1929)</a>, using a literal fence across a road.</p>

<p>It’s one of my favourite bits of practical wisdom, partly because it doesn’t demand obedience to tradition. It demands understanding before demolition.</p>

<p>But there’s a catch. Chesterton’s fence is a <em>heuristic</em>. It isn’t a theorem. A rule might have survived because it helps, because nobody has bothered removing it, or because it benefits someone powerful enough to keep it there. The fence’s existence gives us a reason to investigate, not a proof that we should preserve it.</p>

<p>That difference—between an argument and the assumptions that make it work—is where much of the interesting thinking begins.</p>

<h2 id="the-simplest-explanation-is-not-always-the-right-one">The simplest explanation is not always the right one</h2>

<p>Suppose our old system occasionally fails at the same time every day. One explanation is straightforward: a scheduled job exhausts a resource. Another involves a complicated interaction among several services, their caches, and a race condition triggered by a deployment schedule.</p>

<p>Which would you test first?</p>

<p><strong>“Of two equally good explanations, prefer the simpler one.”</strong> Occam’s razor is a good place to start, provided we pay attention to <em>equally good</em>.</p>

<p>There is a mathematical connection to Bayesian model comparison. A flexible model can accommodate many possible datasets. Its probability is spread across those possibilities; a more constrained model that assigns substantial probability to what we actually observe can compare favourably. This is often called the <em>Occam factor</em>. The details depend on the likelihoods and priors, and a complex model can absolutely win when the evidence supports it. <a href="https://doi.org/10.3758/BF03210778">Myung and Pitt (1997)</a> discuss a Bayesian formalisation of the trade-off.</p>

<p>So the slogan is a <em>model-selection heuristic with formal relatives</em>, not a theorem saying nature always prefers fewer parameters. If the complex explanation predicts the failures and the simple one doesn’t, simplicity is no excuse to ignore the evidence.</p>

<p>The same caution applies when we try to infer a thing’s future from how long it’s already lasted.</p>

<h2 id="old-enough-to-be-trusted">Old enough to be trusted?</h2>

<p>A book that has been read for two centuries feels as though it might still be read in fifty years. A social-media trend that began this morning does not inspire the same confidence.</p>

<p>This intuition is often called the <strong>Lindy effect</strong>: <strong>“The longer something has lasted, the longer it may be expected to last.”</strong></p>

<p>J. Richard Gott presented a striking statistical argument in <a href="https://doi.org/10.1038/363315a0"><em>Nature</em> in 1993</a>. If the moment at which you observe a phenomenon is uniformly distributed across its total lifetime, you are as likely to catch it in the middle half of its life as outside it. Under that sampling model, the interval from one-third to three times the elapsed lifetime covers the true remaining lifetime in half of repeated observations. That is a statement about the procedure’s coverage, not a 50% posterior probability for a particular object from its age alone.</p>

<p>It’s a delightful piece of reasoning. It is also a conditional statement about a particular observation model, not a universal forecast of survival. <a href="https://arxiv.org/abs/astro-ph/0001414">Carlton Caves’ critique</a> examines why the observation model matters. Knowing an object’s age can convey very different information depending on its failure process, selection mechanism, and the prior information available. The age of a centuries-old idea and the age of a worn mechanical part are not interchangeable clues.</p>

<p>The more modest practical lesson is still interesting: longevity can be evidence worth considering, particularly when surviving for a long time required repeated tests against the world. But sometimes things survive through inertia, monopoly, or sheer luck.</p>

<p>Now Chesterton’s fence looks slightly different. Perhaps it lasted because it solved something important. Perhaps it lasted because nobody wanted the meeting required to remove it. Both are live hypotheses.</p>

<p>Good advice should tell us where to look, not exempt us from looking.</p>

<h2 id="a-chart-cant-tell-you-what-to-value">A chart can’t tell you what to value</h2>

<p>Let’s return to the old system. Suppose removing that complicated check saves the team ten hours per month, but raises the probability of a rare and costly billing failure.</p>

<p>A sufficiently good model might quantify the trade-off. It could estimate the engineering hours saved, the expected number of incidents, the distribution of potential losses, and the likely effect on customers.</p>

<p>But it cannot, from those facts alone, tell us which trade-off we ought to accept.</p>

<p><strong>“You can’t get an ought from an is.”</strong> David Hume’s famous observation points to a gap between descriptions of the world and prescriptions for what we should do. The <a href="https://plato.stanford.edu/entries/hume-moral/">Stanford Encyclopedia of Philosophy</a> notes that the exact interpretation of Hume’s argument remains contested, but its widely used logical form is clear: purely descriptive premises do not by themselves yield a normative conclusion without some value-laden bridge.</p>

<p>If we <em>also</em> assume that reducing expected financial loss is our only objective, we can optimise for it. If we place special value on preventing catastrophic harm to a small number of customers, we may choose differently. The mathematics can illuminate the consequences of those values, not select the values from nowhere.</p>

<p>This is easy to forget when a dashboard produces a beautiful single-number score. Choosing what to maximise is a decision of its own.</p>

<p>Sometimes, even after people agree on how choices should be represented, it turns out their wishes cannot all be reconciled.</p>

<h2 id="you-may-have-to-give-up-a-reasonable-sounding-requirement">You may have to give up a reasonable-sounding requirement</h2>

<p>Suppose a team must rank three proposed projects. Every person has their own ranking. You want a rule that turns those rankings into one consistent team ranking.</p>

<p>Naturally, you’d like the rule to respect unanimous preferences. You’d like it not to change its comparison between projects A and B merely because opinions about project C changed. You don’t want one person to dictate the result. And you’d like the procedure to work for every possible combination of individual rankings.</p>

<p>All fairly reasonable.</p>

<p>Kenneth Arrow proved that, with three or more alternatives and the standard requirement that society’s rankings form a coherent ordering, <strong>no aggregation rule satisfies all those conditions simultaneously</strong>. That’s <a href="https://doi.org/10.1086/256963">Arrow’s impossibility theorem</a>, carefully explained in the <a href="https://plato.stanford.edu/entries/arrows-theorem/">Stanford Encyclopedia of Philosophy</a>.</p>

<p>The aphorism <strong>“No voting system is fair to everyone”</strong> is catchy but too broad. Arrow did not prove that every imaginable decision procedure is unfair under every definition of fairness. He proved an incompatibility among a specific collection of axioms for aggregating ranked preferences. Change the requirements or the problem’s structure and different mechanisms become available.</p>

<p>The theorem is more useful with its assumptions visible. It tells us that we cannot get everything on our wish list at once, so we need to discuss which requirement to relax and why.</p>

<p>That’s a very different kind of help from a slogan that simply declares politics hopeless.</p>

<h2 id="the-real-work-begins-after-the-aphorism">The real work begins after the aphorism</h2>

<p>These principles don’t all have the same epistemic status. Arrow’s result is a formal impossibility theorem. Hume’s problem is a philosophical challenge about justification. Occam’s razor has mathematical interpretations but no unconditional guarantee that the simpler story is true. The Lindy effect depends heavily on how lifetimes and observations are modelled. Chesterton’s fence is a wise question to ask before making changes, not a law of nature.</p>

<p>Treating them all as <em>proven wisdom</em> would miss what makes each interesting.</p>

<p>The purpose of an aphorism isn’t to replace thought with a convenient sentence. At its best, it tells us which thought is worth having next.</p>

<p>What’s the simplest explanation that actually predicts the data? What did this old rule once protect? Why has this idea survived? Which values are shaping our recommendation? Which desirable properties are impossible to satisfy simultaneously?</p>

<p>A short saying can get you to the right question. The rest is still your responsibility.</p>]]></content><author><name>Diogo Seca</name></author><category term="Probability" /><category term="Statistics" /><category term="Decision Making" /><category term="Logic" /><summary type="html"><![CDATA[From Occam's razor and the Lindy effect to Chesterton's fence, Hume and Arrow: when good advice works, and where its assumptions fail.]]></summary></entry><entry><title type="html">Based Aphorisms 5: You Can’t Learn What You Never Try</title><link href="https://diogoseca.com/based-aphorisms-5-you-cant-learn-what-you-never-try/" rel="alternate" type="text/html" title="Based Aphorisms 5: You Can’t Learn What You Never Try" /><published>2026-10-22T23:00:00+00:00</published><updated>2026-10-22T23:00:00+00:00</updated><id>https://diogoseca.com/based-aphorisms-5-you-cant-learn-what-you-never-try</id><content type="html" xml:base="https://diogoseca.com/based-aphorisms-5-you-cant-learn-what-you-never-try/"><![CDATA[<p><em>Some answers only become available after you make a move.</em></p>

<p>Imagine I’m building a small software service. New users arrive, open the dashboard, and leave without finishing their first task. I suspect the introduction is too long. A colleague thinks it needs more explanation.</p>

<p>We can discuss this for an impressively long time. We can draw diagrams, inspect competitors, and find articles supporting both positions. Eventually we have two polished explanations and exactly the same decision to make.</p>

<p>I want to replace the introduction with a short, worked example. The familiar question is whether the change will help. But there’s another question hiding inside it: what would trying it teach us, and would that knowledge be worth the cost?</p>

<p>That’s where I want to finish this series. Once we’ve examined our theories, numbers, objectives, and assumptions, we still have to choose something. Sometimes the choice itself produces the evidence we’ll need next.</p>

<h2 id="the-familiar-option-has-an-unfair-advantage">The familiar option has an unfair advantage</h2>

<p>Suppose the current introduction has years of results behind it. The proposed example has a sketch and some encouraging comments. Choosing the established version looks sensible because its performance is easier to estimate.</p>

<p>But <strong>the best option you’ve tried isn’t necessarily the best option available</strong>. That’s my shorthand for a practical problem, not a theorem that novelty deserves a chance every time.</p>

<p>The mathematical version appears in <em>multi-armed bandit</em> problems. A decision maker repeatedly chooses between options with uncertain rewards. Exploitation uses what currently looks best; exploration gathers information that may improve later choices. <a href="https://arxiv.org/abs/1707.02038">Russo and colleagues’ tutorial on Thompson sampling</a> explains both the trade-off and an algorithm for managing it.</p>

<p>An exploratory choice can have a lower expected immediate payoff and still be worthwhile because of what it teaches. That possibility depends on having future decisions in which the information matters. The time horizon, uncertainty, and costs all affect the answer.</p>

<p>Our software example resembles a bandit problem, but resemblance doesn’t give us its mathematical guarantees. Users change, effects may arrive late, and today’s introduction can affect tomorrow’s behaviour. We would need a model that captures those features before importing an algorithm’s formal claims.</p>

<p>Still, the question helps. If I keep rejecting the new introduction because I know less about it, I may preserve the very ignorance I’m using to justify the rejection.</p>

<h2 id="a-change-is-not-yet-an-experiment">A change is not yet an experiment</h2>

<p>Let’s say I publish the worked example on Monday. Completions rise. Naturally, I congratulate myself.</p>

<p>Then I learn that a newsletter recommended the service on Tuesday. The new visitors already understood what it did. Perhaps the introduction helped. Perhaps the visitors needed less help. My before-and-after comparison cannot separate those explanations on its own.</p>

<p><strong>An experiment needs a comparison that could have proved you wrong.</strong> Another formulation of mine; the precise issue underneath it is causal identification.</p>

<p>I’d like to know what would happen to comparable users under each introduction. I cannot observe both outcomes for the same person under the same circumstances. But I can randomly assign eligible new users to the existing introduction or the worked example during the same period.</p>

<p>Under a properly implemented random assignment, treatment assignment is independent of users’ potential outcomes. That supports estimating an average causal effect; it doesn’t guarantee identical groups in a finite sample. <a href="https://miguelhernan.org/whatifbook">Hernán and Robins develop this reasoning in the opening chapters of <em>Causal Inference: What If</em></a>.</p>

<p>The details still matter. Users must receive the intended version, outcomes must be recorded reliably, and one person’s assigned introduction shouldn’t change another person’s result in ways the analysis ignores. Randomisation doesn’t repair a broken event counter or make a tiny sample precise.</p>

<p>Before starting, I’d specify what completion means, the period over which I’ll measure it, and an analysis plan appropriate to the sample and stopping rule. I’d also check for harms such as more support requests. These are practical design choices, not formal guarantees. <a href="https://www.exp-platform.com/Documents/GuideControlledExperiments.pdf">Kohavi, Henne, and Sommerfield’s guide to online experiments</a> makes clear how much trustworthy testing depends on implementation, sample size, and evaluation criteria.</p>

<p>Now the two explanations face a test that neither of us gets to rewrite after seeing the answer.</p>

<h2 id="the-answer-needs-somewhere-to-go">The answer needs somewhere to go</h2>

<p>Even a well-designed experiment can answer a question that isn’t worth asking yet.</p>

<p>Suppose a complicated introduction redesign would cost €6,000. For a deliberately simple calculation, assume there are only two possibilities: it will produce €10,000 in additional benefit over the coming year, or none. I currently assign each possibility a probability of one half. Assume those amounts include every relevant consequence and that I maximise expected euros.</p>

<p>Building immediately has an expected net value of <code class="language-plaintext highlighter-rouge">0.5 × €10,000 − €6,000 = −€1,000</code>. Doing nothing has a value of zero, so I would wait.</p>

<p>If I could learn the outcome perfectly before deciding, I’d build only in the favourable case. My expected net value would then be <code class="language-plaintext highlighter-rouge">0.5 × (€10,000 − €6,000) = €2,000</code>.</p>

<p>Perfect information is therefore worth €2,000 in this toy decision. A realistic, imperfect test cannot be worth more as information alone, under those same assumptions. Its cost and delay can make it worth much less.</p>

<p>That’s the distinction I take from <a href="https://doi.org/10.1109/TSSC.1966.300074">Ronald Howard’s <em>Information Value Theory</em></a>: the importance of uncertainty depends on its consequences for a decision, not simply on how much uncertainty exists.</p>

<p>My version is <strong>before buying an answer, name the decision it could change</strong>.</p>

<p>If every possible test result leaves the same action optimal, the test has no expected decision value within that model. It may still satisfy curiosity, reassure someone, or inform a later choice. Those are legitimate benefits; they belong in the objective if we care about them.</p>

<p>I like this because it interrupts a very respectable form of procrastination. Another survey, another dashboard, another analysis can feel productive while leaving the next action untouched.</p>

<h2 id="make-the-attempt-small-enough-to-learn-from">Make the attempt small enough to learn from</h2>

<p>Our imaginary team doesn’t need to build the €6,000 redesign to investigate whether examples help. It might first test a single worked example inside the existing introduction.</p>

<p>That smaller trial won’t answer every question about the full redesign. Its evidence concerns the intervention actually tested. But it could make the larger decision clearer at an acceptable cost.</p>

<p><strong>Make the next attempt small enough to afford and clear enough to teach.</strong> That’s a heuristic. Some questions require expensive studies; some interventions cannot be meaningfully reduced. A cheap test of the wrong thing isn’t a bargain.</p>

<p>The title needs a qualification too. We learn plenty from other people’s experiments, observation, and reasoning. Nobody needs to touch every hot stove personally. The difficulty arises when the available evidence cannot distinguish the options in front of us, and waiting produces no useful new evidence.</p>

<p>At that point, I want to know what I can try, what the result would mean, and what I’d do differently afterwards.</p>

<p>The worked example might fail. The colleague who wanted more explanation might be right. Either result would give us something our polished arguments couldn’t: a reason to make the next decision differently.</p>]]></content><author><name>Diogo Seca</name></author><category term="Probability" /><category term="Decision Making" /><category term="Experiments" /><summary type="html"><![CDATA[When should you experiment, what can a trial actually teach you, and how much is an answer worth? A practical argument for learning through decisions.]]></summary></entry><entry><title type="html">Based Aphorisms: Nothing More Practical Than a Good Theory</title><link href="https://diogoseca.com/based-aphorisms-nothing-more-practical-than-a-good-theory/" rel="alternate" type="text/html" title="Based Aphorisms: Nothing More Practical Than a Good Theory" /><published>2026-10-22T23:00:00+00:00</published><updated>2026-10-22T23:00:00+00:00</updated><id>https://diogoseca.com/based-aphorisms-nothing-more-practical-than-a-good-theory</id><content type="html" xml:base="https://diogoseca.com/based-aphorisms-nothing-more-practical-than-a-good-theory/"><![CDATA[<p><em>The useful mathematics hiding inside everyday wisdom.</em></p>

<p>There’s an old saying that every story has three sides: yours, mine, and the truth.</p>

<p>I’ve always liked it. Two people can watch the same event, come away with incompatible accounts, and be completely sincere. The saying gives that uncomfortable fact a nice little ending: somewhere beyond their disagreement sits the truth, waiting patiently for a third person to report it.</p>

<p>But who is that person? And what makes their account more reliable?</p>

<p>That’s the question that sent me back to a collection of aphorisms I’d been gathering. Some sounded like advice your grandfather might give. Others sounded like things a statistician would say after a third coffee. A few turned out to be compact versions of genuinely powerful ideas from mathematics, science, and philosophy.</p>

<p>I began to suspect that the appeal of a good aphorism isn’t just that it’s memorable. It’s that, sometimes, a whole way of thinking has been compressed into a sentence.</p>

<p>There’s a famous maxim, often associated with psychologist Kurt Lewin, that nothing is as practical as a good theory. The phrasing is older than Lewin, as <a href="https://faculty.lsu.edu/bedeian/files/a-note-on-the-aphorism-there-is-nothing-as-practical-as-a-good-theory.pdf">Arthur Bedeian’s history of the quotation</a> shows, but the thought is worth keeping. A useful theory changes the questions we ask <em>before</em> we make a decision.</p>

<p>That’s what this series is about.</p>

<p>One distinction matters from the start. A <strong>mathematical theorem</strong> follows from stated assumptions. A <strong>scientific model</strong> must also earn its usefulness against observations. A <strong>philosophical principle</strong> can clarify reasoning without being a theorem, and a <strong>heuristic</strong> may be helpful without being universally true. Confusing these categories is an excellent way to turn sound advice into sophisticated nonsense.</p>

<h2 id="we-dont-see-the-world-we-see-a-model-of-it">We don’t see the world. We see a model of it.</h2>

<p>George Box’s line, <strong>“All models are wrong, but some are useful,”</strong> is easy to misread as an invitation to tolerate sloppy thinking. It isn’t.</p>

<p>A map leaves out almost everything about a city. It can still get you to the station. In fact, including every pipe, crack in the pavement, and passing pigeon would make it a worse navigation tool. A model earns its keep by discarding the right information for the decision at hand.</p>

<p>The real question is not whether the map is identical to the territory. It’s whether the missing details matter for what you’re trying to do.</p>

<p>A financial forecast that ignores a rare event might be good enough for next month’s budget and terrible for deciding whether a company can survive the next decade. A machine-learning model might be excellent on its test distribution and fail when the world changes. A language model can give a fluent account of an event without having the evidence required to distinguish a good explanation from a plausible invention.</p>

<p>None of that is proved by Box’s sentence. It’s an attitude toward modelling, developed in his <a href="https://doi.org/10.1016/B978-0-12-438150-6.50018-2">1979 discussion of scientific model building</a>. The practical habit it suggests is simple: ask <em>what was left out, and does it matter here?</em></p>

<p>Even a model that seems to have failed doesn’t tell us, by itself, where the failure lies.</p>

<p>Suppose an experiment produces the wrong result. The hypothesis could be false. Or the instrument could be miscalibrated. Or a background assumption could be false. Or the experiment could have measured something subtly different from what we thought.</p>

<p>This is the insight behind <strong>“No hypothesis is ever tested alone,”</strong> associated with Pierre Duhem and W. V. O. Quine. Predictions depend on a whole bundle of assumptions, not one isolated proposition. As the <a href="https://plato.stanford.edu/entries/duhem/">Stanford Encyclopedia of Philosophy explains</a>, an unexpected observation tells us that something in the bundle needs attention; it doesn’t identify the guilty premise automatically.</p>

<p>It’s a philosophical thesis about how testing works, not a mathematical licence to rescue any favourite theory forever. You can always invent an excuse for a failed prediction. The hard part is finding an explanation that survives independent scrutiny.</p>

<p>Maybe our third storyteller isn’t standing outside the disagreement after all. Maybe they’re simply holding a different map.</p>

<h2 id="evidence-should-change-our-minds-but-not-equally">Evidence should change our minds, but not equally</h2>

<p>Now imagine someone tells you a coin landed heads ten times in a row. Odd, but possible. If the same person tells you they can predict the next thousand flips of a fair coin, you ought to demand rather better evidence.</p>

<p><strong>“Extraordinary claims require extraordinary evidence”</strong> has a rigorous mathematical relative in Bayes’ theorem.</p>

<p>In odds form, it reads:</p>

<p><code class="language-plaintext highlighter-rouge">Posterior odds = Prior odds × Likelihood ratio</code></p>

<p>The prior odds reflect what you believed before seeing the new observation. The likelihood ratio tells you how much better that observation is explained by one hypothesis than another.</p>

<p>If a claim begins with very low prior odds, modest evidence might not move it very far. The point is not that unfamiliar ideas must be wrong. It’s that evidence should be evaluated in relation to what it would look like under competing explanations.</p>

<p>This is a conditional probability identity, not a theorem assigning objective prior probabilities to every claim in your life. People can reasonably dispute the priors and the likelihood model. What Bayes gives us is the accounting system for those disagreements.</p>

<p>And sometimes the most important evidence is the evidence that never arrives.</p>

<h2 id="the-bombers-that-didnt-come-home">The bombers that didn’t come home</h2>

<p>During the Second World War, statisticians studying damage to returning aircraft faced a deceptively straightforward question: where should the planes be reinforced?</p>

<p>The visible evidence consisted of aircraft that had been hit and survived. You might naturally put more armour where the surviving planes had the most damage. But Abraham Wald’s analysis turned attention toward something absent from the data: the planes that never returned.</p>

<p>A damaged area that appeared rarely among survivors could be particularly dangerous precisely because aircraft hit there were less likely to make it home. The relevant mathematical work is documented by <a href="https://doi.org/10.1080/01621459.1984.10478038">Mangel and Samaniego’s account of Wald’s aircraft-survivability analysis</a>.</p>

<p><strong>“Look at the planes that didn’t come back.”</strong> It’s a memorable way of recognising <em>survivorship bias</em>.</p>

<p>The same mistake appears when we examine only successful founders to discover the habits that produce successful companies, or only profitable investors to identify strategies worth copying. Unless we account for the attempts that failed, success stories may tell us remarkably little about the probability of success.</p>

<p>This isn’t merely a warning about misleading anecdotes. It is a property of selecting observations based on an outcome: the data we can see is conditional on survival.</p>

<p>A useful theory changes the direction of our attention. Instead of asking only what the available data says, we ask <em>what process determined which data was available?</em></p>

<h2 id="the-awkward-business-of-acting-on-what-we-measure">The awkward business of acting on what we measure</h2>

<p>So far, we’ve been trying to observe reality. But what if our observations begin changing the very thing we’re observing?</p>

<p>Imagine rewarding a software team for the number of tickets it closes. At first, the number may be a reasonable proxy for completed work. Then people adapt. Large jobs get split into smaller tickets. Easily closed tasks become attractive. Important but ambiguous problems become harder to justify.</p>

<p>The dashboard improves. Whether the product improves is another question.</p>

<p><strong>“When a measure becomes a target, it ceases to be a good measure.”</strong> That’s the popular formulation of Goodhart’s law, from <a href="https://gwern.net/doc/statistics/decision/1997-strathern.pdf">Marilyn Strathern’s discussion of audit culture</a>. It is a powerful <em>warning</em>, not a theorem saying every targeted metric instantly becomes useless. The mechanism is that people and institutions adapt to incentives; the connection to the <a href="https://doi.org/10.1016/S0167-2231(76)80003-6">Lucas critique</a> is illuminating, though the two ideas are not identical.</p>

<p>A model of passive observers may stop working when those observers become strategic participants.</p>

<p>And even with an honest metric, improving the most visible part of a system may barely improve the whole.</p>

<p>Suppose a computation spends 90% of its time in a component you can accelerate without limit, while the other 10% remains unchanged. You might expect infinite improvement. You won’t get it.</p>

<p>Amdahl’s law gives the bound:</p>

<p><code class="language-plaintext highlighter-rouge">Speedup = 1 / ((1 − p) + p / s)</code></p>

<p>Here <code class="language-plaintext highlighter-rouge">p</code> is the fraction you can accelerate and <code class="language-plaintext highlighter-rouge">s</code> is how much faster that portion becomes. With <code class="language-plaintext highlighter-rouge">p = 0.90</code>, even <code class="language-plaintext highlighter-rouge">s → infinity</code> leaves you with a maximum tenfold speedup.</p>

<p>The saying <strong>“Speeding up what isn’t the bottleneck changes nothing”</strong> is slightly too dramatic. It can change <em>something</em>. What the <a href="https://doi.org/10.1145/1465482.1465560">mathematical bound</a> proves is that a fixed, unimproved fraction limits total speedup. The managerial lesson—work on what constrains the whole system—is an application, not the theorem itself.</p>

<p>I like that distinction. It makes the advice more useful, not less. It tells me what I need to measure before deciding where to invest my effort.</p>

<h2 id="sometimes-the-easiest-way-forward-is-backward">Sometimes the easiest way forward is backward</h2>

<p>There is one more saying I keep returning to: <strong>“Invert, always invert.”</strong> Charlie Munger often credited the mathematician Carl Jacobi with the idea, although the exact historical wording is less secure than the retellings suggest; the <a href="https://old.maa.org/press/periodicals/convergence/quotations-in-context-jacobi">Mathematical Association of America has examined that attribution</a>.</p>

<p>Want to build a reliable service? First ask how you would make it fail: a single unmonitored dependency, no recovery plan, silent data corruption, credentials living forever. Now work backward.</p>

<p>Want a better scientific argument? Ask what observation would embarrass your preferred explanation. Want a better decision? Ask what would make it regrettable, and whether you can remove that risk.</p>

<p>Inversion isn’t a universal mathematical law. It’s a problem-solving heuristic. But it has a pleasing connection to everything that came before it: examine the assumptions, look for the missing observations, test the alternatives, and find what actually constrains the outcome.</p>

<p>That’s a lot of intellectual machinery packed into three words.</p>

<p>Maybe that’s what makes a theory genuinely practical. Not that it provides the last word, or that it turns judgment into arithmetic, but that it lets you notice something consequential you would otherwise have missed.</p>

<p>And once you’ve noticed it, you can’t quite return to thinking the old way.</p>]]></content><author><name>Diogo Seca</name></author><category term="Probability" /><category term="Statistics" /><category term="Decision Making" /><category term="Logic" /><summary type="html"><![CDATA[What do Bayes, survivorship bias, Goodhart's law and Amdahl's law have in common? They show why good theories make better everyday decisions.]]></summary></entry><entry><title type="html">12x Developer: Using the 1% Compound Rule to Grow 1100%</title><link href="https://diogoseca.com/12x-developer-using-the-1-percent-compound-rule-to-grow-1100-percent/" rel="alternate" type="text/html" title="12x Developer: Using the 1% Compound Rule to Grow 1100%" /><published>2025-12-09T00:00:00+00:00</published><updated>2025-12-09T00:00:00+00:00</updated><id>https://diogoseca.com/12x-developer-using-the-1-percent-compound-rule-to-grow-1100-percent</id><content type="html" xml:base="https://diogoseca.com/12x-developer-using-the-1-percent-compound-rule-to-grow-1100-percent/"><![CDATA[<p>Most productivity advice for developers is useless. “Focus deeply.” “Automate tasks.” “Learn continuously.” Thanks, I hadn’t thought of that.</p>

<p>We all love the myth of the “10x developer”, the engineer who outpaces ten others. Chasing that directly mostly produces burnout. The less glamorous route is to get 1% better each working day. A work year is about 250 working days, and 1.01^250 ≈ 12.03, so you end the year roughly 12× where you started. That’s a gain of about +1,100%, not +1,200% (a multiple of 12 means you added 11 of yourself). If you insist on improving on weekends and Christmas too, 1.01^365 ≈ 37.8×, which is the number you’ll see in <em>Atomic Habits</em> <a href="#sources">[1]</a>.</p>

<p>Before anyone emails me: no, productivity doesn’t actually compound like a savings account. Skills plateau, some gains don’t stack, and the same arithmetic works in reverse (0.99^250 ≈ 0.08). The point of the model isn’t the exact multiple. It’s that small, boring habits kept up for a long time beat heroic bursts, and small bad habits quietly do the opposite.</p>

<p>After years of trial and error, from nootropics to meditation to a $15 kitchen timer, my conclusion is that developer productivity has surprisingly little to do with coding technique and a lot to do with sleep, attention, and protecting your time. Here’s what worked for me.</p>

<h2 id="1-count-your-pomodori">1. Count Your Pomodori</h2>

<p>How many hours of genuinely productive work do you get done per day?</p>

<p>Not hours at your desk. Not hours with your IDE open. Focused work that produces something.</p>

<p>For most people the honest answer is two or three. A UK survey of nearly 2,000 office workers put it at about 2 hours and 53 minutes out of an 8-hour day <a href="#sources">[2]</a>. It’s a self-reported survey, not a lab study, but it matches what most of us would admit after a drink.</p>

<p>The Pomodoro Technique is a way to make those few hours count. Whether you like 25-minute sprints or 90-minute deep work blocks, the principle is the same: work in focused bursts, take real breaks, repeat.</p>

<p>The part people skip is taking breaks <em>before</em> you’re fried. When the timer ends, stop, even if you’re in flow. Stand up, get water, look at something more than a metre away. Before the next round, ask: “What’s the highest-impact thing I can do in the next block?” Then set the timer and go.</p>

<p>Use a physical timer. Twisting a dial and hearing it tick keeps you honest, and there’s no app to open, which means no “while I’m here, let me just check…”. A cheap kitchen timer is the single best productivity tool I’ve bought.</p>

<p>Over time, count focus sessions, not hours. Five properly focused 30-minute sessions beat eight hours of half-distracted “work”. Interruptions are expensive: in Gloria Mark’s observational studies, people took on average about 23 minutes to get back to an interrupted task <a href="#sources">[3]</a>. Not all of that is lost time, but enough of it is.</p>

<h2 id="2-the-biology-you-cant-ignore">2. The Biology You Can’t Ignore</h2>

<h3 id="sleep">Sleep</h3>

<p>When you’re stuck on a tough problem, the worst thing you can do is brute-force it at 2 AM. The problem usually isn’t effort. It’s that you’re tired.</p>

<p>Sleep consolidates what you learned during the day, and it seems to help with insight too. In a well-known experiment, participants who slept between sessions were more than twice as likely to discover a hidden shortcut in a task (59% vs 23%) as those who stayed awake <a href="#sources">[4]</a>. Everyone has gone to bed annoyed at a bug and woken up knowing exactly where it is. There’s at least some science behind that.</p>

<p>Something I learned late: when you feel drained and unmotivated and just can’t push further, a nap or an early night often fixes it better than another coffee. Sleep deprivation measurably disrupts the brain’s dopamine system <a href="#sources">[5]</a>, so “I have no willpower today” is sometimes just “I slept five hours”. Give yourself permission to recharge.</p>

<p>Don’t skimp on sleep. Everything else in this article works better on top of it.</p>

<h3 id="caffeine--l-theanine">Caffeine + L-Theanine</h3>

<p>I’m not anti-caffeine. If there’s one “performance enhancer” I’d recommend, it’s caffeine paired with L-theanine, an amino acid found in tea.</p>

<p>Caffeine blocks adenosine receptors, so you feel less tired, but on its own it can bring jitters and anxiety. L-theanine takes the edge off, and the combination has been shown to improve attention-switching and accuracy more than caffeine alone in small trials <a href="#sources">[6]</a>. A common ratio is 1:2, for example 100 mg caffeine with 200 mg L-theanine.</p>

<p>Timing matters more than dose. Caffeine’s half-life is around 5 hours (it varies a lot between people), so a 4pm coffee is still about a quarter-strength at midnight. In one study, caffeine taken even 6 hours before bed cut total sleep by more than an hour, and participants didn’t notice <a href="#sources">[7]</a>. Huberman suggests stopping 8–10 hours before bed <a href="#sources">[8]</a>, which for most people means nothing after early afternoon. He also suggests delaying your first coffee by 90 minutes after waking. The evidence for that one is thin, so try it and see if it does anything for you.</p>

<p>Also drink water and eat lunch. Even mild dehydration has been linked to worse mood and concentration <a href="#sources">[9]</a>, and the “forgot to eat, shipped the feature” session feels heroic until 4pm, when it doesn’t.</p>

<h3 id="exercise-and-morning-light">Exercise and Morning Light</h3>

<p>Not novel, but it works: regular exercise, even brisk walking, and morning daylight will do more for your energy and focus than any nootropic or gadget. Aerobic exercise improves mood and cognition, and in one year-long trial walking three times a week increased hippocampal volume by about 2% in older adults, roughly reversing a year or two of age-related shrinkage <a href="#sources">[10]</a>.</p>

<p>Getting outside for 10 minutes in the morning helps anchor your circadian rhythm, which helps you sleep, which, as we covered, helps everything.</p>

<p>On supplements: if you live far from the equator or work indoors all day, there’s a decent chance you’re low in vitamin D. Get it tested, and if you’re deficient, supplementing is cheap and low-risk <a href="#sources">[11]</a>. Just don’t expect miracles if your levels are already fine. A large trial of over 25,000 adults found supplementing didn’t reduce cancer or cardiovascular events in a general population <a href="#sources">[12]</a>. Omega-3s are similar: worth it if you never eat fish, unconvincing as a brain booster otherwise. There’s no magic pill for motivation or IQ.</p>

<h2 id="3-dopamine-the-molecule-of-more">3. Dopamine: The Molecule of More</h2>

<p>Dopamine is the neurotransmitter of motivation and wanting. Some call it the “molecule of more” because it drives the pursuit of the next reward rather than enjoyment of the current one <a href="#sources">[13]</a>.</p>

<p>Social media notifications, a new episode, a donut, a whisky: they all deliver a hit that is far more immediate than writing code or reading docs. Feed yourself enough of those and ordinary work starts to feel dull by comparison.</p>

<h3 id="avoid-dopamine-stacking">Avoid Dopamine Stacking</h3>

<p>“Dopamine stacking” is piling multiple stimuli on at once: coding while checking Twitter, blasting music, and working through coffee and sweets. It might get you through a grind, but in my experience it raises the bar for what feels stimulating, and plain work gets harder.</p>

<p>Music is the sneaky one. If you always work to intense music with lyrics, you may find you can’t work without it. I still listen to lo-fi or instrumental stuff, but I try not to make every task depend on it. Save the big playlist for the genuinely tedious jobs.</p>

<p>Doom-scrolling is the same, only worse: spikes of outrage and novelty followed by a hangover that makes focused work less appealing. The more the work itself becomes the reward (“I want to see this test go green”), the less you need to borrow motivation from elsewhere.</p>

<h3 id="rituals-and-cues">Rituals and Cues</h3>

<p>Your brain is good at learning associations. If you always use the same playlist, the same tea, or the same tidy desk for deep work, those cues start to signal “it’s go time” and you settle in faster. This is plain habit formation, and it’s cheap to set up.</p>

<p>It works in reverse too. If you watch Netflix at your desk, your desk starts to mean Netflix. Keep your work spot for work where you can.</p>

<h2 id="4-the-mental-game">4. The Mental Game</h2>

<h3 id="meditation">Meditation</h3>

<p>I used to think meditation was new-age fluff. Then I tried it and found it’s mostly attention training: sit, focus on your breath, notice when your mind wanders, bring it back. Ten minutes a day is enough to notice a difference.</p>

<p>The bigger benefit for me is noticing a feeling without obeying it. Developers deal with a lot of impostor syndrome, anxiety, and frustration. Meditation is practice for feeling anxious and still writing the code, or feeling frustrated and still debugging methodically.</p>

<p>You may have read that meditation grows grey matter. The early studies were small, and a larger randomised trial found no measurable structural brain changes after an 8-week course <a href="#sources">[14]</a>. I’d do it for the attention training and leave the brain-scan claims alone.</p>

<h3 id="emotions-come-in-waves">Emotions Come in Waves</h3>

<p>However stoic you think you are, your mood will go up and down. Productivity isn’t about never feeling down. It’s about not letting the down days sink the week.</p>

<p>When I’m in a funk or panicking about a deadline, I sometimes literally tell myself: “Fine, I’m anxious. I’m going to chip away at this for 15 minutes anyway.” Giving yourself permission to feel bad while working often makes the feeling pass faster.</p>

<p>Also expect the crash after a big push. If you’ve been sprinting on adrenaline to finish a feature before a demo, you’ll probably feel flat afterwards. Plan a lighter day rather than pretending peak output is sustainable.</p>

<h3 id="trust-the-process">Trust the Process</h3>

<p>The more you panic about being stuck, the longer you tend to stay stuck. Acute stress impairs the prefrontal cortex, the part you need for working memory and reasoning <a href="#sources">[15]</a>, so panic is the worst state to debug in.</p>

<p>It helps to keep a short mental list of hard bugs you’ve solved before. Not as self-help, but as evidence: “This is tricky, but I’ve done tricky before. Break it down.”</p>

<p>When you’re truly stuck, step away. Walk, shower, cook, or sleep on it. I’ve lost count of how many times the answer turned up while I was making dinner.</p>

<p>Rubber duck debugging (explaining the code line by line to an actual rubber duck) and a second pair of eyes, human or AI, work for the same reason: explaining the problem clearly often reveals the answer.</p>

<h2 id="5-learn-the-craft-not-just-the-hot-tools">5. Learn the Craft, Not Just the Hot Tools</h2>

<p>This is career advice more than daily productivity, but it pays off massively over time. The best developers I know keep learning, and not just whatever framework is trending on Hacker News this week.</p>

<p>Studying algorithms, data structures, design patterns, and complexity can feel unproductive. It gives you a toolkit that makes you faster at everything: you recognise problems you’ve seen before and stop reinventing wheels.</p>

<p>Learn why popular frameworks and architectures exist, what problems they solved, and what they traded away. That’s how you judge new tools instead of chasing silver bullets.</p>

<p>And widen the net a bit: some ops, raw SQL if you only know ORMs, some functional programming if you only know OOP. Each new paradigm gives you another way around a wall.</p>

<p>Sharpen the axe. It saves hours on dead ends and avoids the big refactor later, which is the real productivity killer.</p>

<h2 id="6-use-tools-including-ai-but-keep-thinking">6. Use Tools, Including AI, But Keep Thinking</h2>

<p>Good tools boost your output a lot. Use them for the dull parts, not to skip understanding the problem.</p>

<p>AI coding assistants are great for boilerplate in a framework you don’t know well, regexes, format conversions, test scaffolding, and the “how do I do X in Y again” questions that used to mean another StackOverflow tab.</p>

<p>But read what they produce. You’re still responsible for the code you ship, however it was written. If an assistant writes a complex SQL query, check that it does what you meant. If you don’t understand the output, that’s a red flag. Blind copy-pasting is how subtle bugs and security holes get in.</p>

<p>The other trap is over-automation. We love automating things, and usually that’s good. But don’t spend 4 hours automating a 5-minute monthly task. I’ve been guilty of this, tweaking dotfiles for an afternoon to save two shell commands. It’s fun, but be honest about whether it’s productive.</p>

<p>My rule of thumb: if it’s repetitive and you’ll keep doing it, automate it. If it’s rare, just do it. You can automate later if it becomes a pain.</p>

<h2 id="7-protect-your-time">7. Protect Your Time</h2>

<p>This might be the most important one. Your most valuable asset as a developer is long, uninterrupted stretches of time to think and build.</p>

<p>That means setting boundaries. Two big offenders:</p>

<p><strong>Meetings.</strong> Everyone has sat in a meeting that should have been an email. Atlassian’s widely shared estimate is that about half of meeting time is wasted <a href="#sources">[16]</a>. Where you have a say, propose shorter meetings or async updates. If one drags, ask, “Can we agree next steps and get back to work?” People are usually relieved someone said it.</p>

<p>If you freelance, negotiate fewer meetings upfront: “To get the most done for you, I keep meetings to a weekly check-in and handle the rest over Slack or email.” Most clients are happy to pay for output rather than calendar time.</p>

<p><strong>Notifications.</strong> Constant pings kill deep work. Close Slack or Teams for an hour if your culture allows, or at least mute the non-urgent channels. The cost isn’t the 30 seconds to read the message. It’s getting back into the problem afterwards.</p>

<p>Block “Focus” time in your calendar and treat it like a meeting with your code. Plenty of teams have rules like no meetings before noon. If yours doesn’t, you can often run that policy for yourself.</p>

<p>As your career progresses, protecting your time, for work and for life outside it, becomes most of the game. That might mean saying no, or pushing back on a deadline by explaining the trade-offs. You can usually turn time into money. Turning money back into time is a lot harder.</p>

<h2 id="8-nootropics-and-hacks-proceed-with-caution">8. Nootropics and “Hacks”: Proceed with Caution</h2>

<p>I’ve tried a fair few so-called nootropics: racetams, modafinil, assorted supplement stacks from Silicon Valley startups. The unsexy lesson is that homeostasis usually wins. If something gives you a big boost, your body tends to adapt, you need it to feel normal, and when you stop you dip below where you started.</p>

<p>I once ran a stack that made me feel like a genius for a month. The next month I was foggy without it. When I mixed that regimen with ordinary social drinking, I had odd memory lapses, like forgetting where I’d parked the car. That was my cue to stop.</p>

<p>Caffeine is the one that reliably works, as long as you manage the timing. Everything else comes with trade-offs. Everyone’s brain chemistry is different and I won’t tell you not to experiment, but be sceptical. Sleep, exercise, food, and stress management move the needle most. If those aren’t in place, no pill will save you. If they are, you probably won’t feel the need.</p>

<p>Nicotine deserves a special mention. Yes, it’s a stimulant, and some famous scientists and writers swore by it. It’s also very addictive and easily becomes a crutch with a nasty health bill attached. The same goes for heavy drinking or anything else that wrecks your sleep and the next day.</p>

<p>Your body and brain are the hardware. Treat them accordingly.</p>

<hr />

<h2 id="the-compound-effect">The Compound Effect</h2>

<p>None of this is dramatic on any single day. A 1% improvement is invisible by Friday. The hard part is staying consistent long enough for it to add up. Once it does, it feels like momentum, and things get easier.</p>

<p>If I had to pick the habits that made the biggest difference for me, they’d be <strong>good sleep, regular exercise, focused work sessions, and continuous learning</strong>. None of them is a secret, which is exactly why most people skip them.</p>

<p>And keep it fun. The point of productivity isn’t to become a churn-and-burn coding robot. It’s to cut out the unnecessary grind so you enjoy the work and still have energy left for the people and things you care about outside it.</p>

<hr />

<p><strong>Got a productivity habit that made a real difference for you? Tell me. I’m still working on my own 1% a day.</strong></p>

<hr />

<h2 id="sources">Sources</h2>

<ol>
  <li>
    <p>Clear, J. (2018). <em>Atomic Habits</em>. Avery. Chapter 1 uses the 1.01^365 ≈ 37.78 illustration.</p>
  </li>
  <li>
    <p>World Economic Forum / Business Insider – “The case for the 3-hour workday” (2017). Cites a UK survey of 1,989 office workers reporting an average of 2h53m of productive work in an 8-hour day.</p>
  </li>
  <li>
    <p>Mark, G., González, V. M., &amp; Harris, J. (2005). No task left behind? Examining the nature of fragmented work. <em>CHI ‘05</em>, 321–330. <a href="https://doi.org/10.1145/1054972.1055017">doi:10.1145/1054972.1055017</a></p>
  </li>
  <li>
    <p>Wagner, U., Gais, S., Haider, H., Verleger, R., &amp; Born, J. (2004). Sleep inspires insight. <em>Nature</em>, 427, 352–355. <a href="https://doi.org/10.1038/nature02223">doi:10.1038/nature02223</a></p>
  </li>
  <li>
    <p>Volkow, N. D., et al. (2012). Evidence that sleep deprivation downregulates dopamine D2R in ventral striatum in the human brain. <em>Journal of Neuroscience</em>, 32(19), 6711–6717. <a href="https://doi.org/10.1523/JNEUROSCI.0045-12.2012">doi:10.1523/JNEUROSCI.0045-12.2012</a></p>
  </li>
  <li>
    <p>Owen, G. N., Parnell, H., De Bruin, E. A., &amp; Rycroft, J. A. (2008). The combined effects of L-theanine and caffeine on cognitive performance and mood. <em>Nutritional Neuroscience</em>, 11(4), 193–198. <a href="https://doi.org/10.1179/147683008X301513">doi:10.1179/147683008X301513</a></p>
  </li>
  <li>
    <p>Drake, C., Roehrs, T., Shambroom, J., &amp; Roth, T. (2013). Caffeine effects on sleep taken 0, 3, or 6 hours before going to bed. <em>Journal of Clinical Sleep Medicine</em>, 9(11), 1195–1200. <a href="https://doi.org/10.5664/jcsm.3170">doi:10.5664/jcsm.3170</a></p>
  </li>
  <li>
    <p>Huberman, A. (Huberman Lab Newsletter) – “Use Caffeine for Mental &amp; Physical Performance” (2024). Recommends avoiding caffeine 8–10 hours before bedtime.</p>
  </li>
  <li>
    <p>Ganio, M. S., et al. (2011). Mild dehydration impairs cognitive performance and mood of men. <em>British Journal of Nutrition</em>, 106(10), 1535–1543. <a href="https://doi.org/10.1017/S0007114511002005">doi:10.1017/S0007114511002005</a></p>
  </li>
  <li>
    <p>Erickson, K. I., et al. (2011). Exercise training increases size of hippocampus and improves memory. <em>PNAS</em>, 108(7), 3017–3022. <a href="https://doi.org/10.1073/pnas.1015950108">doi:10.1073/pnas.1015950108</a></p>
  </li>
  <li>
    <p>Harvard Health Publishing – Komaroff, A. L., “Will vitamin D supplements keep me younger?” <em>Harvard Health Letter</em>. Discusses who benefits from vitamin D supplementation.</p>
  </li>
  <li>
    <p>Manson, J. E., et al. (2019). Vitamin D supplements and prevention of cancer and cardiovascular disease. <em>New England Journal of Medicine</em>, 380, 33–44. <a href="https://doi.org/10.1056/NEJMoa1809944">doi:10.1056/NEJMoa1809944</a></p>
  </li>
  <li>
    <p>Lieberman, D. Z., &amp; Long, M. E. (2018). <em>The Molecule of More</em>. BenBella Books.</p>
  </li>
  <li>
    <p>Kral, T. R. A., et al. (2022). Absence of structural brain changes from mindfulness-based stress reduction: Two combined randomized controlled trials. <em>Science Advances</em>, 8(20), eabk3316. <a href="https://doi.org/10.1126/sciadv.abk3316">doi:10.1126/sciadv.abk3316</a></p>
  </li>
  <li>
    <p>Arnsten, A. F. T. (2009). Stress signalling pathways that impair prefrontal cortex structure and function. <em>Nature Reviews Neuroscience</em>, 10, 410–422. <a href="https://doi.org/10.1038/nrn2648">doi:10.1038/nrn2648</a></p>
  </li>
  <li>
    <p>Atlassian – “You waste a lot of time at work” (infographic), widely cited in employee productivity roundups.</p>
  </li>
</ol>]]></content><author><name>Diogo Seca</name></author><category term="Software Engineering" /><category term="Productivity" /><summary type="html"><![CDATA[Forget the generic productivity advice. After years of experimenting with everything from nootropics to hardware timers, here's what actually moved the needle for me – and most of it has nothing to do with code.]]></summary></entry><entry><title type="html">Are you still diversifying using the Markowitz model? Welcome to the 21st century.</title><link href="https://diogoseca.com/Are-you-still-diversifying-using-the-Markowitz-model-Welcome-to-the-21st-century/" rel="alternate" type="text/html" title="Are you still diversifying using the Markowitz model? Welcome to the 21st century." /><published>2020-07-15T00:00:00+00:00</published><updated>2020-07-15T00:00:00+00:00</updated><id>https://diogoseca.com/Are-you-still-diversifying-using-the-Markowitz-model-Welcome-to-the-21st-century</id><content type="html" xml:base="https://diogoseca.com/Are-you-still-diversifying-using-the-Markowitz-model-Welcome-to-the-21st-century/"><![CDATA[<p>This article is Part 1 of a series of articles on Diversification.</p>

<p>Most retail traders aka “dumb money” don’t diversify.</p>

<p>Contrastingly, professional portfolio managers diversify:</p>

<ol>
  <li>across markets;</li>
  <li>across sectors;</li>
  <li>across asset types;</li>
  <li>across investment strategies.</li>
</ol>

<p>Professional portfolio managers are more afraid of the occasional downswings and crashes than retails traders are. And rightly so. The best managers monitor their exposure and seek to re-balance it to according to their perceived optimum portfolio weights. They understand that diversification is key to minimizing risk.</p>

<p>The most popular, most used model for calculating the optimal portfolio weights is the Markowitz model and the Efficient Frontier.<br />
<strong>This is now considered ancient technology.</strong></p>

<p>There are 2 main issues with the Markowitz Model:</p>
<ol>
  <li>
    <p><strong>Markowitz is always overfitting the training data.</strong>.</p>

    <p>Markowitz’s result was an optimization process for the weights that would have been profitable in the past. Markowitz model is not learning a set of rules for predicting the future. Instead, this model can be summed up as “Has this portfolio worked well in the past 10 years? Then it is sure to work well for the next 10!”. You can change the 10 year for whatever timestep you like - you’ll still be overfitting.</p>
  </li>
  <li>
    <p><strong>It finds the weights that maximize Sharpe ratio. Sharpe ratio sucks.</strong></p>

    <blockquote>
      <p>“What?! But everybody is using Sharpe ratio!”</p>
    </blockquote>

    <p>Using Sharpe for showcasing portfolio metrics to clients is ok; using it for daily quant work is not ok. Sharpe ratio’s denominator is the standard deviation of returns, which is a good measure of variability, not a good measure of risk. Sharpe ratio penalizes large positive swings, penalizes accelerating returns, and fails to penalize deaccelerating returns. For experimental evidence, see: https://www.crystalbull.com/sharpe-ratio-better-with-log-returns/</p>
  </li>
</ol>

<h2 id="enter-machine-learning">Enter Machine Learning.</h2>

<p>There are several ways we can frame the problem of portfolio optimization as a Machine Learning problem:</p>

<ol>
  <li>
    <p><strong>Reinforcement Learning</strong>: learning the optimal increase/decrease in portfolio weights.</p>
  </li>
  <li>
    <p><strong>Supervised Learning</strong>: learning the optimal portfolio weights for the next N days/months/years.</p>
  </li>
  <li>
    <p><strong>Unsupervised Learning</strong>: learning clusters of assets, according to their price and fundamentals similarity.</p>
  </li>
</ol>

<p>Today, I will focus on the latter problem. Learning groups of assets can identify how to diversify according to historical data.</p>

<p>We will be starting with the following dataset:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ..
</code></pre></div></div>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">pandas</span> <span class="k">as</span> <span class="n">pd</span>

<span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="p">.</span><span class="nf">read_csv</span><span class="p">(</span><span class="sh">"</span><span class="s">data/stocks.csv</span><span class="sh">"</span><span class="p">)</span>
<span class="n">data</span>
</code></pre></div></div>

<div style="overflow-x: scroll; width: 900px;">
<style scoped="">
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>year</th>
      <th>ticker</th>
      <th>returns_yoy</th>
      <th>returns_mean</th>
      <th>returns_std</th>
      <th>returns_kurt</th>
      <th>returns_skew</th>
      <th>current_assets_chg</th>
      <th>total_assets_chg</th>
      <th>current_liabilities_chg</th>
      <th>...</th>
      <th>gross_profit_chg</th>
      <th>operating_income_chg</th>
      <th>ebit_chg</th>
      <th>ebitda_chg</th>
      <th>net_income_chg</th>
      <th>cash_flow_chg</th>
      <th>gics_sector</th>
      <th>gics_industry_group</th>
      <th>gics_industry</th>
      <th>gics_sub_industry</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1984</td>
      <td>ABT</td>
      <td>-0.023327</td>
      <td>-0.000081</td>
      <td>0.015751</td>
      <td>1.137280</td>
      <td>0.150682</td>
      <td>0.199012</td>
      <td>0.123607</td>
      <td>0.192155</td>
      <td>...</td>
      <td>0.091034</td>
      <td>0.119551</td>
      <td>0.119551</td>
      <td>0.142322</td>
      <td>0.158099</td>
      <td>0.185255</td>
      <td>Health Care</td>
      <td>Health Care Equipment &amp; Services</td>
      <td>Health Care Equipment &amp; Supplies</td>
      <td>Health Care Equipment</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1984</td>
      <td>ADM</td>
      <td>-0.026099</td>
      <td>-0.000104</td>
      <td>0.020297</td>
      <td>3.388723</td>
      <td>0.910988</td>
      <td>-0.010240</td>
      <td>0.016783</td>
      <td>-0.442166</td>
      <td>...</td>
      <td>0.090505</td>
      <td>0.239521</td>
      <td>0.239521</td>
      <td>0.184024</td>
      <td>0.068358</td>
      <td>0.085822</td>
      <td>Consumer Staples</td>
      <td>Food, Beverage &amp; Tobacco</td>
      <td>Food Products</td>
      <td>Agricultural Products</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1984</td>
      <td>AIR</td>
      <td>0.632523</td>
      <td>0.002427</td>
      <td>0.021781</td>
      <td>4.852271</td>
      <td>1.239041</td>
      <td>0.328328</td>
      <td>0.233089</td>
      <td>-0.053046</td>
      <td>...</td>
      <td>0.165023</td>
      <td>0.072245</td>
      <td>0.072245</td>
      <td>0.087333</td>
      <td>0.605367</td>
      <td>0.327884</td>
      <td>Industrials</td>
      <td>Capital Goods</td>
      <td>Aerospace &amp; Defense</td>
      <td>Aerospace &amp; Defense</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1984</td>
      <td>AP</td>
      <td>0.254065</td>
      <td>0.001079</td>
      <td>0.015319</td>
      <td>6.334656</td>
      <td>1.158865</td>
      <td>0.473669</td>
      <td>0.463316</td>
      <td>0.484195</td>
      <td>...</td>
      <td>0.723608</td>
      <td>-1.143189</td>
      <td>-4.665928</td>
      <td>4.393316</td>
      <td>-4.411381</td>
      <td>2.389767</td>
      <td>Materials</td>
      <td>Materials</td>
      <td>Metals &amp; Mining</td>
      <td>Steel</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1984</td>
      <td>APA</td>
      <td>0.354090</td>
      <td>0.001460</td>
      <td>0.023034</td>
      <td>1.213794</td>
      <td>0.306496</td>
      <td>-0.103468</td>
      <td>-0.083883</td>
      <td>0.176250</td>
      <td>...</td>
      <td>-0.125055</td>
      <td>-0.006917</td>
      <td>-0.058889</td>
      <td>0.037832</td>
      <td>-0.028582</td>
      <td>0.121321</td>
      <td>Energy</td>
      <td>Energy</td>
      <td>Oil, Gas &amp; Consumable Fuels</td>
      <td>Oil &amp; Gas Exploration &amp; Production</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>16034</th>
      <td>2018</td>
      <td>XYL</td>
      <td>0.438349</td>
      <td>0.001772</td>
      <td>0.010812</td>
      <td>2.641754</td>
      <td>-0.159363</td>
      <td>0.011106</td>
      <td>0.052770</td>
      <td>0.262727</td>
      <td>...</td>
      <td>0.094543</td>
      <td>0.197802</td>
      <td>0.163511</td>
      <td>0.149693</td>
      <td>0.658610</td>
      <td>0.327869</td>
      <td>Industrials</td>
      <td>Capital Goods</td>
      <td>Machinery</td>
      <td>Industrial Machinery</td>
    </tr>
    <tr>
      <th>16035</th>
      <td>2018</td>
      <td>YUM</td>
      <td>0.304004</td>
      <td>0.001204</td>
      <td>0.010132</td>
      <td>8.515445</td>
      <td>0.365575</td>
      <td>-0.518548</td>
      <td>-0.222369</td>
      <td>-0.139550</td>
      <td>...</td>
      <td>0.074187</td>
      <td>-0.168417</td>
      <td>0.040901</td>
      <td>-0.024227</td>
      <td>0.150746</td>
      <td>-0.204243</td>
      <td>Consumer Discretionary</td>
      <td>Consumer Services</td>
      <td>Hotels, Restaurants &amp; Leisure</td>
      <td>Restaurants</td>
    </tr>
    <tr>
      <th>16036</th>
      <td>2018</td>
      <td>ZBH</td>
      <td>-0.105038</td>
      <td>-0.000394</td>
      <td>0.013195</td>
      <td>3.860412</td>
      <td>-0.492598</td>
      <td>-0.030100</td>
      <td>-0.072546</td>
      <td>-0.219370</td>
      <td>...</td>
      <td>-0.006197</td>
      <td>-0.958179</td>
      <td>-0.260979</td>
      <td>-0.170304</td>
      <td>-1.209064</td>
      <td>-0.605724</td>
      <td>Health Care</td>
      <td>Health Care Equipment &amp; Services</td>
      <td>Health Care Equipment &amp; Supplies</td>
      <td>Health Care Equipment</td>
    </tr>
    <tr>
      <th>16037</th>
      <td>2018</td>
      <td>ZEN</td>
      <td>0.534857</td>
      <td>0.002201</td>
      <td>0.022210</td>
      <td>3.768737</td>
      <td>0.040686</td>
      <td>0.664630</td>
      <td>1.093239</td>
      <td>0.494517</td>
      <td>...</td>
      <td>0.379028</td>
      <td>0.299418</td>
      <td>0.299418</td>
      <td>0.366408</td>
      <td>0.283363</td>
      <td>0.346874</td>
      <td>Information Technology</td>
      <td>Software &amp; Services</td>
      <td>Software</td>
      <td>Application Software</td>
    </tr>
    <tr>
      <th>16038</th>
      <td>2018</td>
      <td>ZTS</td>
      <td>0.454571</td>
      <td>0.001804</td>
      <td>0.011308</td>
      <td>5.094913</td>
      <td>0.584154</td>
      <td>0.043159</td>
      <td>0.255183</td>
      <td>0.117916</td>
      <td>...</td>
      <td>0.112302</td>
      <td>0.108197</td>
      <td>0.098801</td>
      <td>0.119920</td>
      <td>0.652778</td>
      <td>0.281915</td>
      <td>Health Care</td>
      <td>Pharmaceuticals, Biotechnology &amp; Life Sciences</td>
      <td>Pharmaceuticals</td>
      <td>Pharmaceuticals</td>
    </tr>
  </tbody>
</table>
<p>16039 rows × 23 columns</p>
</div>

<p>Each line describes an instance. Each instance contains quantitative information about a given stock for a given year, as well as its GICS sector, industry_group, industry, and sub_industry.</p>

<p>We select the top50 industries with that contain the most instances:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">top50</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="n">gics_industry</span><span class="p">.</span><span class="nf">value_counts</span><span class="p">().</span><span class="n">iloc</span><span class="p">[:</span><span class="mi">50</span><span class="p">]</span>
<span class="n">top50</span>
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Machinery                                         1379
Oil, Gas &amp; Consumable Fuels                       1312
Chemicals                                          916
Specialty Retail                                   899
Energy Equipment &amp; Services                        779
Aerospace &amp; Defense                                634
Health Care Equipment &amp; Supplies                   582
Electronic Equipment, Instruments &amp; Components     485
Hotels, Restaurants &amp; Leisure                      480
Food Products                                      463
Metals &amp; Mining                                    452
Commercial Services &amp; Supplies                     424
Health Care Providers &amp; Services                   387
Containers &amp; Packaging                             362
Textiles, Apparel &amp; Luxury Goods                   302
IT Services                                        301
Construction &amp; Engineering                         272
Professional Services                              270
Household Durables                                 255
Building Products                                  250
Auto Components                                    250
Media                                              241
Life Sciences Tools &amp; Services                     226
Multiline Retail                                   223
Pharmaceuticals                                    221
Household Products                                 203
Electrical Equipment                               203
Diversified Consumer Services                      197
Trading Companies &amp; Distributors                   194
Equity Real Estate Investment Trusts (REITs)       170
Food &amp; Staples Retailing                           167
Diversified Telecommunication Services             166
Technology Hardware, Storage &amp; Peripherals         160
Road &amp; Rail                                        157
Leisure Products                                   149
Capital Markets                                    137
Personal Products                                  136
Automobiles                                        134
Paper &amp; Forest Products                            125
Industrial Conglomerates                           125
Entertainment                                      118
Software                                           115
Marine                                             106
Tobacco                                            103
Beverages                                          101
Airlines                                            90
Construction Materials                              81
Real Estate Management &amp; Development                80
Gas Utilities                                       65
Air Freight &amp; Logistics                             63
Name: gics_industry, dtype: int64
</code></pre></div></div>

<p>And filter our data so that it only contains those GICS industries.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">data</span><span class="p">.</span><span class="n">gics_industry</span><span class="p">.</span><span class="nf">isin</span><span class="p">(</span><span class="n">top50</span><span class="p">.</span><span class="n">index</span><span class="p">)]</span>
</code></pre></div></div>

<p>We then standardize the numerical information:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">quantitative_vars</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="nf">select_dtypes</span><span class="p">(</span><span class="sh">'</span><span class="s">number</span><span class="sh">'</span><span class="p">).</span><span class="n">columns</span>
<span class="n">quantitative_data</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="n">quantitative_vars</span><span class="p">]</span>
<span class="n">data</span><span class="p">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="n">quantitative_vars</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">quantitative_data</span> <span class="o">-</span> <span class="n">quantitative_data</span><span class="p">.</span><span class="nf">mean</span><span class="p">())</span> <span class="o">/</span> <span class="n">quantitative_data</span><span class="p">.</span><span class="nf">std</span><span class="p">()</span>
</code></pre></div></div>

<p>We can now calculate and visualize the dissimilarity between industries, measured by the <a href="http://jmlr.csail.mit.edu/papers/v13/gretton12a.html">Maximum Mean Discrepancy</a> between the samples of the different industries).</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="n">qclustering</span> <span class="kn">import</span> <span class="n">dissimilarity_matrix</span>
<span class="kn">import</span> <span class="n">matplotlib.pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="kn">import</span> <span class="n">seaborn</span> <span class="k">as</span> <span class="n">sns</span>
<span class="n">sns</span><span class="p">.</span><span class="nf">set</span><span class="p">()</span>

<span class="n">dmatrix</span> <span class="o">=</span> <span class="nf">dissimilarity_matrix</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="sh">'</span><span class="s">gics_industry</span><span class="sh">'</span><span class="p">)</span>

<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="p">.</span><span class="nf">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span><span class="mi">30</span><span class="p">))</span>
<span class="n">cbar_kws</span> <span class="o">=</span> <span class="n">cbar_kws</span><span class="o">=</span><span class="p">{</span><span class="sh">'</span><span class="s">shrink</span><span class="sh">'</span><span class="p">:</span> <span class="p">.</span><span class="mi">8</span><span class="p">,</span> <span class="sh">'</span><span class="s">label</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">Distance</span><span class="sh">'</span><span class="p">}</span>
<span class="n">sns</span><span class="p">.</span><span class="nf">heatmap</span><span class="p">(</span><span class="n">dmatrix</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">vmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">square</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="sh">'</span><span class="s">Blues</span><span class="sh">'</span><span class="p">,</span> <span class="n">cbar_kws</span><span class="o">=</span><span class="n">cbar_kws</span><span class="p">)</span>
<span class="n">fig</span><span class="p">.</span><span class="n">axes</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="n">yaxis</span><span class="p">.</span><span class="n">label</span><span class="p">.</span><span class="nf">set_size</span><span class="p">(</span><span class="mi">23</span><span class="p">)</span>
<span class="n">fig</span><span class="p">.</span><span class="n">axes</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="nf">tick_params</span><span class="p">(</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">18</span><span class="p">)</span>
</code></pre></div></div>

<p><img src="/assets/img/industries_dissimilarities.png" alt="Stock Industries Dissimilarities" /></p>

<p>We can also frame this as a Hierarchical Clustering problem and use MMD as a linkage metric between industries and clusters of industries:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="n">qclustering</span> <span class="kn">import</span> <span class="n">hierarchical_clustering</span><span class="p">,</span> <span class="n">plot_dendrogram</span>
<span class="n">initial_clusters</span><span class="p">,</span> <span class="n">linkage</span> <span class="o">=</span> <span class="nf">hierarchical_clustering</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="sh">'</span><span class="s">gics_industry</span><span class="sh">'</span><span class="p">)</span>
<span class="nf">plot_dendrogram</span><span class="p">(</span><span class="n">initial_clusters</span><span class="p">,</span> <span class="n">linkage</span><span class="p">,</span> <span class="n">color_threshold</span><span class="o">=</span><span class="mf">0.09</span><span class="p">,</span> <span class="n">above_threshold_color</span><span class="o">=</span><span class="sh">'</span><span class="s">#CCCCCC</span><span class="sh">'</span><span class="p">);</span>
</code></pre></div></div>

<p><img src="/assets/img/stocks_clustering.png" alt="Stocks Clustering" /></p>

<p>Based on the chart above, we can see that some industries are being clustered with industries of different sectors. Therefor, the data indicates that we’re better off diversifying by industries than diversifying by sectors.</p>

<hr />

<p>This concludes Part 1.</p>

<p>In Part 2, we will look at ML-based diversification strategies at compare their foward testing / out-of-sampling results, including some methods from the <a href="https://github.com/hudson-and-thames/mlfinlab">MlFinLab python package</a>.</p>]]></content><author><name>Diogo Seca</name></author><category term="Risk Management" /><category term="Portfolio Management" /><category term="Machine Learning" /><category term="Python" /><summary type="html"><![CDATA[A better alternative to the Markowitz model is Machine Learning and Statistics.]]></summary></entry></feed>