import%20marimo%0A%0A__generated_with%20%3D%20%220.23.9%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Is%20flood%20risk%20priced%20right%3F%20%E2%80%94%20the%20FEMA%20map%20and%20the%20market%0A%0A%20%20%20%20Two%20pricing%20questions%20about%20the%20same%20risk%2C%20each%20answered%20from%20data%2C%20in%20order%3A%0A%0A%20%20%20%201.%20**Is%20FEMA's%20%22safe%22%20label%20trustworthy%3F**%20If%20the%20Zone%20X%20designation%20is%20stale%2C%20then%0A%20%20%20%20%20%20%20cheap%2C%20low-insurance%20%22X%22%20homes%20could%20be%20hiding%20flood%20risk%20%E2%80%94%20a%20buying%20trap.%20*(Test%3A%0A%20%20%20%20%20%20%20did%20Zone%20X%20areas%20actually%20flood%20in%202024%3F)*%0A%20%20%20%202.%20**Is%20the%20market's%20flood%20discount%20adequate%3F**%20Buyers%20haircut%20flood-zone%20homes%20by%0A%20%20%20%20%20%20%20~9%E2%80%9310%25%20(the%20F21%20penalty).%20Is%20that%20enough%20to%20cover%20the%20realized%20cost%20of%20flooding%3F%0A%20%20%20%20%20%20%20*(Test%3A%20how%20does%20the%20discount%20compare%20to%20what%202024%20actually%20paid%20out%3F)*%0A%0A%20%20%20%20The%20first%20turns%20out%20to%20be%20**good%20news%2C%20and%20narrow**%3B%20the%20second%20is%20the%20interesting%20one%20%E2%80%94%0A%20%20%20%20the%20discount%20is%20small%20relative%20to%20realized%20damage%2C%20and%20the%20reason%20why%20points%20at%20a%0A%20%20%20%20coming%20repricing.%0A%0A%20%20%20%20%3E%20Read-only%20against%20%60analytics.db%60%3B%20elevation%20sampled%20from%20the%20USGS%203DEP%20DEM%20with%20the%0A%20%20%20%20%3E%20cat-model's%20own%20%60sample_ground_elevation_ft%60.%20Decisions%20(%60D*%60)%20and%20findings%20(%60F*%60)%20are%0A%20%20%20%20%3E%20inline%2C%20flagged%20pre-%2Fpost-data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20sys%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20duckdb%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20return%20Path%2C%20duckdb%2C%20mo%2C%20plt%2C%20sys%0A%0A%0A%40app.cell%0Adef%20_(Path%2C%20duckdb%2C%20sys)%3A%0A%20%20%20%20def%20_find_root()%20-%3E%20Path%3A%0A%20%20%20%20%20%20%20%20for%20d%20in%20%5BPath.cwd()%2C%20*Path.cwd().parents%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(d%20%2F%20%22analytics.db%22).exists()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20d%0A%20%20%20%20%20%20%20%20raise%20FileNotFoundError(%22analytics.db%20not%20found%20walking%20up%20from%20cwd%22)%0A%0A%20%20%20%20_root%20%3D%20_find_root()%0A%20%20%20%20if%20str(_root)%20not%20in%20sys.path%3A%0A%20%20%20%20%20%20%20%20sys.path.insert(0%2C%20str(_root))%0A%20%20%20%20from%20analysis.catmodel.exposure%20import%20sample_ground_elevation_ft%0A%0A%20%20%20%20conn%20%3D%20duckdb.connect(str(_root%20%2F%20%22analytics.db%22)%2C%20read_only%3DTrue)%0A%20%20%20%20return%20conn%2C%20sample_ground_elevation_ft%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Part%201%20%E2%80%94%20Is%20the%20Zone%20X%20%22safe%22%20label%20trustworthy%3F%0A%0A%20%20%20%20%23%23%23%20D1%20%E2%80%94%20two%20independent%20tests%20(pre-data)%0A%0A%20%20%20%20%60flood_zone%60%20is%20fully%20populated%20(FEMA%20FIRM%20spatial%20join%2C%200%20nulls)%3B%20X%20%3D%20%22minimal%20risk%2C%22%0A%20%20%20%20where%20flood%20insurance%20is%20optional%20and%20cheap.%20The%20skeptic's%20worry%20is%20that%20the%20maps%20are%0A%20%20%20%20stale%20and%20X%20hides%20real%20risk.%20Two%20checks%3A%0A%0A%20%20%20%20-%20**Physical%3A**%20sample%20ground%20elevation%20for%20every%20St-Pete%20Zone-X%20parcel.%20The%202024%0A%20%20%20%20%20%20high-water%20marks%20read%207%E2%80%9311%20ft%20NAVD88%2C%20so%20an%20X%20parcel%20below%20~8%20ft%20is%20%22labeled%20safe%20but%0A%20%20%20%20%20%20low%20enough%20to%20have%20taken%20water.%22%20Count%20them.%0A%20%20%20%20-%20**Realized%3A**%20find%20block%20groups%20FEMA%20labels%20almost%20entirely%20Zone%20X%20that%20*still*%0A%20%20%20%20%20%20generated%202024%20NFIP%20claims.%20(Caveat%3A%20claims%20are%20block-group%20grain%2C%20so%20at%20%3C100%25%20X-share%0A%20%20%20%20%20%20a%20claim%20could%20come%20from%20the%20few%20non-X%20parcels%20%E2%80%94%20which%20is%20why%20we%20push%20the%20X-share%0A%20%20%20%20%20%20threshold%20high.)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(conn%2C%20sample_ground_elevation_ft)%3A%0A%20%20%20%20%23%20Physical%20test%3A%20ground%20elevation%20of%20every%20St-Pete%20Zone-X%20parcel.%0A%20%20%20%20_x%20%3D%20conn.execute(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20SELECT%20parcel_id%2C%20latitude%2C%20longitude%0A%20%20%20%20%20%20%20%20FROM%20parcels%0A%20%20%20%20%20%20%20%20WHERE%20municipality%20%3D%20'ST%20PETERSBURG'%20AND%20upper(flood_zone)%20%3D%20'X'%0A%20%20%20%20%20%20%20%20%20%20AND%20latitude%20IS%20NOT%20NULL%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20).fetchdf()%0A%20%20%20%20_x%5B%22elev_ft%22%5D%20%3D%20sample_ground_elevation_ft(%0A%20%20%20%20%20%20%20%20_x%5B%22latitude%22%5D.to_numpy()%2C%20_x%5B%22longitude%22%5D.to_numpy()%0A%20%20%20%20)%0A%20%20%20%20x_parcels%20%3D%20_x.dropna(subset%3D%5B%22elev_ft%22%5D)%0A%20%20%20%20x_below%20%3D%20%7Bthr%3A%20int((x_parcels%5B%22elev_ft%22%5D%20%3C%20thr).sum())%20for%20thr%20in%20(4%2C%206%2C%208)%7D%0A%20%20%20%20x_parcels%0A%20%20%20%20return%20x_below%2C%20x_parcels%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20x_below%2C%20x_parcels)%3A%0A%20%20%20%20_n%20%3D%20len(x_parcels)%0A%20%20%20%20_med%20%3D%20x_parcels%5B%22elev_ft%22%5D.median()%0A%20%20%20%20_p5%20%3D%20x_parcels%5B%22elev_ft%22%5D.quantile(0.05)%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20f%22%22%22%0A%20%20%20%20**F1%20%E2%80%94%20In%20St.%20Pete%2C%20Zone%20X%20is%20genuinely%20high%20ground%20(clean).**%20Of%20**%7B_n%3A%2C%7D**%20DEM-covered%0A%20%20%20%20St-Pete%20Zone-X%20parcels%3A%20median%20elevation%20**%7B_med%3A.0f%7D%20ft**%2C%205th%20percentile%20**%7B_p5%3A.1f%7D%20ft**.%0A%20%20%20%20Parcels%20below%20the%20surge-plausible%20line%3A%20**%7Bx_below%5B8%5D%7D%20below%208%20ft**%20(%7Bx_below%5B8%5D%20%2F%20_n%3A.1%25%7D)%2C%0A%20%20%20%20%7Bx_below%5B6%5D%7D%20below%206%20ft%2C%20%7Bx_below%5B4%5D%7D%20below%204%20ft.%20The%20%22safe%22%20label%20is%20**not**%20stale%20here%20%E2%80%94%0A%20%20%20%20X%20corresponds%20to%20real%20elevation%2C%20so%20the%20cheap%2C%20high-ground%20homes%20are%20genuinely%20low-risk.%0A%20%20%20%20This%20is%20the%20de-risking%20result%3A%20the%20obvious%20skeptic's%20objection%20doesn't%20hold%20in%20St.%20Pete.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(conn)%3A%0A%20%20%20%20%23%20Realized%20test%3A%20near-all-X%20block%20groups%20that%20still%20claimed%20in%202024.%0A%20%20%20%20xbg%20%3D%20conn.execute(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20WITH%20xs%20AS%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20pbg.block_group%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20count(*)%20AS%20n_parcels%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20avg(CASE%20WHEN%20upper(p.flood_zone)%20%3D%20'X'%20THEN%201.0%20ELSE%200.0%20END)%20AS%20x_share%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mode(p.zip)%20AS%20zip%0A%20%20%20%20%20%20%20%20%20%20%20%20FROM%20parcels%20p%20JOIN%20parcel_block_group%20pbg%20USING%20(parcel_id)%0A%20%20%20%20%20%20%20%20%20%20%20%20GROUP%20BY%201%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20SELECT%20c.block_group%2C%20xs.zip%2C%20xs.n_parcels%2C%20round(xs.x_share%2C%203)%20AS%20x_share%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20c.claim_count%2C%20c.total_paid%3A%3Adouble%20AS%20total_paid%0A%20%20%20%20%20%20%20%20FROM%20flood_claims_bg%20c%20JOIN%20xs%20USING%20(block_group)%0A%20%20%20%20%20%20%20%20WHERE%20c.year%20%3D%202024%20AND%20xs.x_share%20%3E%3D%200.90%0A%20%20%20%20%20%20%20%20ORDER%20BY%20c.claim_count%20DESC%0A%20%20%20%20%20%20%20%20LIMIT%2010%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20).fetchdf()%0A%20%20%20%20xbg%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**F2%20%E2%80%94%20The%20exception%20is%20inland%2C%20not%20St-Pete%20coastal%20(caveat).**%20A%20handful%20of%20~all-X%0A%20%20%20%20block%20groups%20did%20flood%20%E2%80%94%20the%20standout%20is%20in%20**Largo%20(33771)%3A%2099%25%20Zone%20X%2C%20~%2426M%20paid**%2C%0A%20%20%20%20sitting%20at%20~2%20ft%20elevation.%20These%20are%20flat%20inland%20%2F%20backwater%20pockets%20(Largo%2C%20Clearwater)%0A%20%20%20%20where%20flooding%20is%20rain%2Fdrainage-driven%2C%20which%20coastal%20surge%20maps%20aren't%20built%20to%20flag%20%E2%80%94%0A%20%20%20%20*not*%20a%20St-Pete%20surge%20gap.%20So%20%22X%20%3D%20safe%22%20is%20reliable%20**in%20St.%20Pete**%20but%20not%20a%20blanket%0A%20%20%20%20county-wide%20guarantee%3B%20a%20buyer%20screening%20only%20on%20the%20X%20label%20could%20still%20walk%20into%20one%20of%0A%20%20%20%20these%20inland%20pockets.%0A%0A%20%20%20%20**Part%201%20verdict%3A**%20for%20the%20St-Pete%20decision%2C%20FEMA's%20map%20is%20trustworthy%20enough%20to%20lean%0A%20%20%20%20on.%20Which%20lets%20us%20take%20the%20next%20question%20at%20face%20value%20%E2%80%94%20given%20the%20label%20is%20reliable%2C%20is%0A%20%20%20%20the%20*market*%20pricing%20the%20flood-zone%20homes%20correctly%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20D3%20%E2%80%94%20does%20low%20insurance%20take-up%20explain%20the%20low%20claims%20in%20X%3F%20(post-data%20check)%0A%0A%20%20%20%20The%20sharp%20objection%20to%20the%20realized%20test%3A%20flood%20insurance%20is%20**mandatory**%20in%20zones%20A%2FV%0A%20%20%20%20(with%20a%20federally-backed%20mortgage)%20but%20**optional**%20in%20Zone%20X%2C%20so%20X%20areas%20carry%20far%20fewer%0A%20%20%20%20policies%20%E2%80%94%20and%20*no%20policy%20%E2%87%92%20no%20claim%20is%20even%20possible*.%20So%20%22few%20claims%20in%20X%22%20could%20be%20a%0A%20%20%20%20pure%20take-up%20artifact%2C%20not%20dryness.%20Test%20it%20directly%3A%20split%20block%20groups%20on%20Zone-X%20share%2C%0A%20%20%20%20then%20compare%20the%20**raw**%20claim%20rate%20(per%20parcel)%20against%20the%20**take-up%E2%80%93adjusted**%20rate%0A%20%20%20%20(per%20policy-in-force%20%E2%80%94%20of%20the%20homes%20that%20*were*%20insured%2C%20how%20many%20filed%3F).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(conn)%3A%0A%20%20%20%20%23%20Take-up%20confound%20test%3A%20how%20many%20homes%20carry%20flood%20insurance%20vs%20how%20many%20filed%2C%20by%20X-share.%0A%20%20%20%20takeup%20%3D%20conn.execute(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20WITH%20xs%20AS%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20pbg.block_group%2C%20count(*)%20AS%20n_parcels%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20avg(CASE%20WHEN%20upper(p.flood_zone)%20%3D%20'X'%20THEN%201.0%20ELSE%200.0%20END)%20AS%20x_share%0A%20%20%20%20%20%20%20%20%20%20%20%20FROM%20parcels%20p%20JOIN%20parcel_block_group%20pbg%20USING%20(parcel_id)%0A%20%20%20%20%20%20%20%20%20%20%20%20GROUP%20BY%201%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20bg%20AS%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20CASE%20WHEN%20xs.x_share%20%3C%200.50%20THEN%20'%3C50%25%20X'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20WHEN%20xs.x_share%20%3C%200.80%20THEN%20'50-80%25%20X'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20WHEN%20xs.x_share%20%3C%200.95%20THEN%20'80-95%25%20X'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ELSE%20'95-100%25%20X'%20END%20AS%20band%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xs.x_share%2C%20xs.n_parcels%2C%20pol.policy_count%2C%20c.claim_count%0A%20%20%20%20%20%20%20%20%20%20%20%20FROM%20flood_claims_bg%20c%20JOIN%20xs%20USING%20(block_group)%0A%20%20%20%20%20%20%20%20%20%20%20%20JOIN%20nfip_policies%20pol%20ON%20pol.geo_id%20%3D%20c.block_group%0A%20%20%20%20%20%20%20%20%20%20%20%20WHERE%20c.year%20%3D%202024%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20SELECT%20band%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20count(*)%20%20%20%20%20%20%20%20%20%20%20%20%20%20AS%20n_bg%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sum(n_parcels)%20%20%20%20%20%20%20%20AS%20parcels%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sum(policy_count)%20%20%20%20%20AS%20policies_in_force%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sum(claim_count)%20%20%20%20%20%20AS%20claims%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20round(sum(policy_count)%20*%20100.0%20%2F%20sum(n_parcels)%2C%201)%20%20%20AS%20policies_per_100_homes%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20round(sum(claim_count)%20*%20100.0%20%2F%20sum(policy_count)%2C%201)%20AS%20claims_per_100_policies%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20round(sum(claim_count)%20*%20100.0%20%2F%20sum(n_parcels)%2C%201)%20%20%20%20AS%20claims_per_100_homes_raw%0A%20%20%20%20%20%20%20%20FROM%20bg%0A%20%20%20%20%20%20%20%20GROUP%20BY%20band%0A%20%20%20%20%20%20%20%20ORDER%20BY%20min(x_share)%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20).fetchdf()%0A%20%20%20%20takeup%0A%20%20%20%20return%20(takeup%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20takeup)%3A%0A%20%20%20%20_hi%20%3D%20takeup%5Btakeup%5B%22band%22%5D%20%3D%3D%20%2295-100%25%20X%22%5D.iloc%5B0%5D%0A%20%20%20%20_lo%20%3D%20takeup%5Btakeup%5B%22band%22%5D%20%3D%3D%20%22%3C50%25%20X%22%5D.iloc%5B0%5D%0A%20%20%20%20_raw_gap%20%3D%20_lo%5B%22claims_per_100_homes_raw%22%5D%20%2F%20_hi%5B%22claims_per_100_homes_raw%22%5D%0A%20%20%20%20_adj_gap%20%3D%20_lo%5B%22claims_per_100_policies%22%5D%20%2F%20_hi%5B%22claims_per_100_policies%22%5D%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20f%22%22%22%0A%20%20%20%20**F3%20%E2%80%94%20Take-up%20is%20a%20real%20confound%2C%20but%20it%20doesn't%20explain%20the%20gap%20away%20(clean).**%0A%20%20%20%20Near-all-X%20areas%20are%20**~%7B_lo%5B'policies_per_100_homes'%5D%20%2F%20_hi%5B'policies_per_100_homes'%5D%3A.0f%7D%C3%97%0A%20%20%20%20less%20insured**%20(%7B_hi%5B'policies_per_100_homes'%5D%3A.0f%7D%20vs%20%7B_lo%5B'policies_per_100_homes'%5D%3A.0f%7D%0A%20%20%20%20policies%20per%20100%20homes)%2C%20so%20the%20**raw**%20per-home%20claim%20gap%20(**%7B_raw_gap%3A.0f%7D%C3%97**)%20is%20badly%0A%20%20%20%20inflated%20by%20exactly%20the%20objection%20raised%20%E2%80%94%20many%20%22dry%22%20X%20homes%20simply%20had%20no%20policy%20to%20file.%0A%20%20%20%20But%20control%20for%20it%20%E2%80%94%20claims%20per%20*policy*%2C%20among%20homes%20that%20*were*%20insured%20%E2%80%94%20and%20the%20gap%0A%20%20%20%20shrinks%20to%20**~%7B_adj_gap%3A.1f%7D%C3%97**%20yet%20stays%20firmly%20in%20place%3A%20insured%20X-zone%20homeowners%20still%0A%20%20%20%20filed%20far%20less.%20The%20dryness%20is%20**real%2C%20just%20smaller%20than%20raw%20counts%20suggest**.%0A%0A%20%20%20%20**Blind%20spot%2C%20stated%20honestly%3A**%20claims%20only%20ever%20see%20*insured*%20flooding%20%E2%80%94%20a%20home%20that%0A%20%20%20%20flooded%20uninsured%20is%20invisible%20here.%20That%20is%20precisely%20why%20the%20load-bearing%20Part-1%0A%20%20%20%20evidence%20is%20the%20**physical%20elevation%20test**%20(F1)%2C%20which%20is%20immune%20to%20take-up%3A%20high%20ground%0A%20%20%20%20doesn't%20flood%20no%20matter%20who%20bought%20a%20policy.%20Claims%20corroborate%3B%20elevation%20proves.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Part%202%20%E2%80%94%20Is%20the%20market's%20flood%20discount%20adequate%3F%0A%0A%20%20%20%20%23%23%23%20D2%20%E2%80%94%20compare%20two%20realized%20dollar%20figures%20(pre-data)%0A%0A%20%20%20%20Both%20sides%20come%20from%20real%20data%2C%20no%20modeled%20premium%20(the%20warehouse's%20%60monthly_insurance%60%0A%20%20%20%20is%20a%20construction-type%20lookup%20with%20**no%20flood%20component**%2C%20so%20it%20can't%20price%20this%20%E2%80%94%20we%0A%20%20%20%20use%20realized%20payouts%20instead)%3A%0A%0A%20%20%20%20-%20**The%20discount%20(what%20the%20market%20took%20off)%3A**%20the%20F21%20within-neighborhood%20flood%20penalty%2C%0A%20%20%20%20%20%20**~9.3%25**%2C%20applied%20to%20the%20median%20flood-zone%20home%20%E2%80%94%20a%20one-time%2C%20permanent%20haircut%0A%20%20%20%20%20%20capitalized%20into%20price.%0A%20%20%20%20-%20**The%20damage%20(what%20flooding%20actually%20cost)%3A**%20realized%202024%20NFIP%20payouts%20in%0A%20%20%20%20%20%20flood-heavy%20block%20groups%2C%20per%20insured%20home.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(conn)%3A%0A%20%20%20%20%23%20Side%20A%3A%20median%20flood-zone%20(A%2FV)%20home%20price%2C%20and%20the%20~9.3%25%20discount%20in%20dollars.%0A%20%20%20%20median_flood_price%20%3D%20float(%0A%20%20%20%20%20%20%20%20conn.execute(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20median(price_basis)%20FROM%20parcel_detail%0A%20%20%20%20%20%20%20%20%20%20%20%20WHERE%20upper(flood_zone)%20LIKE%20'A%25'%20OR%20upper(flood_zone)%20LIKE%20'V%25'%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20).fetchone()%5B0%5D%0A%20%20%20%20)%0A%20%20%20%20F21_PENALTY%20%3D%200.093%20%20%23%20within-neighborhood%20repeat-sales%20flood%20penalty%20(F21%2C%2004_parcel_flood_penalty)%0A%20%20%20%20discount_dollars%20%3D%20F21_PENALTY%20*%20median_flood_price%0A%0A%20%20%20%20%23%20Side%20B%3A%20realized%202024%20payouts%20in%20flood-heavy%20block%20groups%20(%3E%3D50%25%20A%2FV%20parcels)%2C%20per%20policy.%0A%20%20%20%20_r%20%3D%20conn.execute(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20WITH%20xs%20AS%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20pbg.block_group%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20avg(CASE%20WHEN%20upper(p.flood_zone)%20LIKE%20'A%25'%20OR%20upper(p.flood_zone)%20LIKE%20'V%25'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20THEN%201.0%20ELSE%200.0%20END)%20AS%20flood_share%0A%20%20%20%20%20%20%20%20%20%20%20%20FROM%20parcels%20p%20JOIN%20parcel_block_group%20pbg%20USING%20(parcel_id)%0A%20%20%20%20%20%20%20%20%20%20%20%20GROUP%20BY%201%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20SELECT%20sum(c.total_paid)%3A%3Adouble%20AS%20paid%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sum(c.claim_count)%20AS%20claims%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sum(pol.policy_count)%20AS%20policies%0A%20%20%20%20%20%20%20%20FROM%20flood_claims_bg%20c%0A%20%20%20%20%20%20%20%20JOIN%20xs%20USING%20(block_group)%0A%20%20%20%20%20%20%20%20LEFT%20JOIN%20nfip_policies%20pol%20ON%20pol.geo_id%20%3D%20c.block_group%0A%20%20%20%20%20%20%20%20WHERE%20c.year%20%3D%202024%20AND%20xs.flood_share%20%3E%3D%200.5%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20).fetchdf()%0A%20%20%20%20paid%20%3D%20float(_r%5B%22paid%22%5D%5B0%5D)%0A%20%20%20%20policies%20%3D%20int(_r%5B%22policies%22%5D%5B0%5D)%0A%20%20%20%20claims%20%3D%20int(_r%5B%22claims%22%5D%5B0%5D)%0A%20%20%20%20payout_per_policy%20%3D%20paid%20%2F%20policies%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20claims%2C%0A%20%20%20%20%20%20%20%20discount_dollars%2C%0A%20%20%20%20%20%20%20%20median_flood_price%2C%0A%20%20%20%20%20%20%20%20paid%2C%0A%20%20%20%20%20%20%20%20payout_per_policy%2C%0A%20%20%20%20%20%20%20%20policies%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20claims%2C%0A%20%20%20%20discount_dollars%2C%0A%20%20%20%20median_flood_price%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20paid%2C%0A%20%20%20%20payout_per_policy%2C%0A%20%20%20%20policies%2C%0A)%3A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%7C%20%7C%20dollars%20%7C%0A%20%20%20%20%7C---%7C---%3A%7C%0A%20%20%20%20%7C%20Median%20flood-zone%20home%20(price%20basis)%20%7C%20%24%7Bmedian_flood_price%3A%2C.0f%7D%20%7C%0A%20%20%20%20%7C%20Market%20flood%20discount%20(~9.3%25%2C%20F21)%20%E2%80%94%20*one-time%2C%20permanent*%20%7C%20**%24%7Bdiscount_dollars%3A%2C.0f%7D**%20%7C%0A%20%20%20%20%7C%20Realized%202024%20payout%2C%20flood-heavy%20BGs%20%7C%20%24%7Bpaid%20%2F%201e6%3A%2C.0f%7DM%20across%20%7Bpolicies%3A%2C%7D%20policies%20%2F%20%7Bclaims%3A%2C%7D%20claims%20%7C%0A%20%20%20%20%7C%20Realized%20payout%20**per%20insured%20home**%2C%20*one%20season*%20%7C%20**%24%7Bpayout_per_policy%3A%2C.0f%7D**%20%7C%0A%0A%20%20%20%20**One%202024%20storm%20season%20paid%20out%20%E2%89%88%20%7Bpayout_per_policy%20%2F%20discount_dollars%3A.1f%7D%C3%97%20the%20entire%0A%20%20%20%20lifetime%20price%20discount.**%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(discount_dollars%2C%20payout_per_policy%2C%20plt)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots(figsize%3D(7%2C%203.4))%0A%20%20%20%20_bars%20%3D%20_ax.barh(%0A%20%20%20%20%20%20%20%20%5B%22Market%20flood%20discount%5Cn(~9.3%25%2C%20one-time)%22%2C%20%22Realized%202024%20payout%5Cnper%20insured%20home%20(one%20season)%22%5D%2C%0A%20%20%20%20%20%20%20%20%5Bdiscount_dollars%2C%20payout_per_policy%5D%2C%0A%20%20%20%20%20%20%20%20color%3D%5B%22%234C72B0%22%2C%20%22%23C44E52%22%5D%2C%20edgecolor%3D%22black%22%2C%20linewidth%3D0.5%2C%0A%20%20%20%20)%0A%20%20%20%20_ax.bar_label(_bars%2C%20labels%3D%5Bf%22%24%7Bdiscount_dollars%2F1e3%3A.0f%7Dk%22%2C%20f%22%24%7Bpayout_per_policy%2F1e3%3A.0f%7Dk%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20padding%3D4%2C%20fontsize%3D11)%0A%20%20%20%20_ax.set_xlabel(%22dollars%22)%0A%20%20%20%20_ax.set_title(%22The%20flood%20discount%20vs.%20one%20season's%20realized%20payout%22)%0A%20%20%20%20_ax.margins(x%3D0.18)%0A%20%20%20%20_ax.grid(alpha%3D0.3%2C%20axis%3D%22x%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**F4%20%E2%80%94%20The%20discount%20is%20small%20relative%20to%20realized%20flood%20damage%20(signal%2C%20with%20a%20framing%0A%20%20%20%20caveat).**%20The%20market's%20permanent%20flood%20haircut%20(~%2427k)%20is%20dwarfed%20by%20a%20single%20season's%0A%20%20%20%20realized%20payout%20(~%2485k%2Finsured%20home).%0A%0A%20%20%20%20**The%20honest%20caveat%20%E2%80%94%20who%20bears%20that%20%2485k.**%20It's%20an%20**NFIP-insured**%20payout%2C%20borne%20by%0A%20%20%20%20the%20federal%20program%2C%20*not*%20the%20homeowner's%20out-of-pocket.%20The%20homeowner's%20direct%20cost%20of%0A%20%20%20%20flooding%20is%20their%20deductible%20%2B%20uninsured%20loss%20%2B%20**premiums**.%20So%20this%20isn't%20a%20clean%0A%20%20%20%20apples-to-apples%20%22the%20buyer%20lost%20%2485k.%22%20What%20it%20shows%20is%20that%20the%20*physical*%20cost%20of%0A%20%20%20%20flood%20risk%20is%20several%20times%20the%20price%20signal%20the%20market%20is%20attaching%20to%20it.%0A%0A%20%20%20%20**Why%20that%20gap%20exists%2C%20and%20why%20it%20should%20close.**%20Federally%20**subsidized**%20flood%0A%20%20%20%20insurance%20has%20historically%20absorbed%20most%20of%20that%20physical%20cost%2C%20so%20it%20never%20had%20to%20show%0A%20%20%20%20up%20in%20the%20home%20price%20%E2%80%94%20the%20discount%20stays%20small%20because%20someone%20else%20pays.%20**Risk%20Rating%0A%20%20%20%202.0**%20(FEMA's%202021%2B%20actuarial%20repricing)%20is%20shifting%20true%20cost%20onto%20premiums%2C%20which%20*are*%0A%20%20%20%20a%20homeowner%20cost%20and%20*do*%20capitalize%20into%20price.%20As%20that%20plays%20through%2C%20the%20~%2427k%0A%20%20%20%20discount%20has%20to%20widen%20toward%20the%20real%20risk%20%E2%80%94%20i.e.%2C%20flood-zone%20homes%20carry%20repricing%0A%20%20%20%20**downside**%20the%20current%20discount%20doesn't%20reflect.%0A%0A%20%20%20%20%23%23%20Verdict%0A%0A%20%20%20%20Two%20questions%2C%20two%20answers%20that%20point%20the%20same%20way%20for%20a%20buyer.%20**The%20map%20is%20reliable**%0A%20%20%20%20in%20St.%20Pete%20(Part%201)%2C%20so%20a%20Zone-X%2C%20high-ground%20home%20is%20a%20genuine%20low-risk%20pick%20%E2%80%94%20not%20a%0A%20%20%20%20mislabeled%20trap.%20**The%20discount%20is%20not**%20(Part%202)%3A%20the%20market%20is%20under-pricing%20flood%20risk%0A%20%20%20%20relative%20to%20its%20realized%20cost%20because%20subsidized%20insurance%20has%20masked%20it%2C%20and%20the%0A%20%20%20%20subsidy%20is%20being%20unwound.%20Net%20read%3A%20**dry%2C%20high%2C%20Zone-X%20ground%20isn't%20just%20safer%20%E2%80%94%20it's%20on%0A%20%20%20%20the%20right%20side%20of%20a%20repricing%20that%20flood-zone%20homes%20haven't%20fully%20taken%20yet.**%0A%0A%20%20%20%20*Caveats%20carried%3A%20claims%20are%20block-group%20grain%3B%20payout-per-policy%20uses%20a%20current%20policy%0A%20%20%20%20snapshot%20against%202024%20claims%20(two%20storms%20%E2%86%92%20a%20policy%20could%20claim%20twice)%3B%20the%209.3%25%20penalty%0A%20%20%20%20is%20the%20pooled%20F21%20estimate.%20Treat%20the%20ratio%20as%20order-of-magnitude%2C%20not%20a%20point%20estimate.*%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
8ceb748b67a1b8e371ccac1dcc357b4a