import%20marimo%0A%0A__generated_with%20%3D%20%220.25.1%22%0Aapp%20%3D%20marimo.App(%0A%20%20%20%20width%3D%22medium%22%2C%0A%20%20%20%20app_title%3D%22Learn%20volatility%20dynamics%20from%20observed%20paths%22%2C%0A%20%20%20%20css_file%3D%22trajectory_inference.css%22%2C%0A)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20json%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%20from%20sbi4f_tutorial.shared%20import%20plots%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20lesson%20as%20trajectory%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20diagnostics%20as%20path_checks%2C%20simulation%20as%20path_simulation%2C%20model_checks%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20predictive_visuals%0A%20%20%20%20plots.style()%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20json%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20model_checks%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20path_checks%2C%0A%20%20%20%20%20%20%20%20path_simulation%2C%0A%20%20%20%20%20%20%20%20plt%2C%0A%20%20%20%20%20%20%20%20predictive_visuals%2C%0A%20%20%20%20%20%20%20%20trajectory%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Same%20section%2C%20type%20and%20navigation%20contract%20as%20the%20Heston%2FSPX%20notebook.%0A%20%20%20%20import%20html%20as%20_markup%0A%20%20%20%20import%20re%20as%20_re%0A%0A%20%20%20%20_stages%20%3D%20(%0A%20%20%20%20%20%20%20%20(%22Model%22%2C%20%22Parameters%20and%20physical%20return%20law%22)%2C%0A%20%20%20%20%20%20%20%20(%22Simulate%22%2C%20%22Histories%20before%20seeing%20data%22)%2C%0A%20%20%20%20%20%20%20%20(%22Train%22%2C%20%22Learn%20a%20conditional%20density%22)%2C%0A%20%20%20%20%20%20%20%20(%22Infer%22%2C%20%22Condition%20on%20observed%20returns%22)%2C%0A%20%20%20%20%20%20%20%20(%22Check%22%2C%20%22Replicate%2C%20recover%2C%20calibrate%22)%2C%0A%20%20%20%20%20%20%20%20(%22Use%22%2C%20%22What%20a%20continuation%20forecast%20requires%22)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20def%20_anchor(number)%3A%0A%20%20%20%20%20%20%20%20return%20%22s%22%20%2B%20str(number).replace(%22.%22%2C%20%22-%22)%0A%0A%20%20%20%20def%20lesson_md(text)%3A%0A%20%20%20%20%20%20%20%20%23%20Leave%20displayed%20code%20intact%20while%20giving%20numbered%20headings%20anchors.%0A%20%20%20%20%20%20%20%20pieces%20%3D%20_re.split(r%22(%5E%5B%20%5Ct%5D*(%3F%3A%60%60%60%7C~~~).*%3F%5E%5B%20%5Ct%5D*(%3F%3A%60%60%60%7C~~~)%5B%20%5Ct%5D*%24)%22%2C%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%20text%2C%20flags%3D_re.MULTILINE%20%7C%20_re.DOTALL)%0A%20%20%20%20%20%20%20%20for%20index%20in%20range(0%2C%20len(pieces)%2C%202)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20pieces%5Bindex%5D%20%3D%20_re.sub(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20r%22%5E(%5Cs*)%23%23%23%20(%5Cd%2B%5C.%5Cd%2B)%20(.%2B)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20lambda%20match%3A%20f'%7Bmatch%5B1%5D%7D%3Ch3%20id%3D%22%7B_anchor(match%5B2%5D)%7D%22%3E'%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%20%20%20f'%3Cspan%20class%3D%22nb-number%22%3E%7Bmatch%5B2%5D%7D%3C%2Fspan%3E%20%7Bmatch%5B3%5D%7D%3C%2Fh3%3E'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pieces%5Bindex%5D%2C%20flags%3D_re.MULTILINE)%0A%20%20%20%20%20%20%20%20return%20mo.md(%22%22.join(pieces))%0A%0A%20%20%20%20def%20workflow_map()%3A%0A%20%20%20%20%20%20%20%20steps%20%3D%20%22%22.join(%0A%20%20%20%20%20%20%20%20%20%20%20%20f'%3Ca%20class%3D%22nb-map-step%22%20href%3D%22%23%7B_anchor(number)%7D%22%3E%3Cdiv%20class%3D%22nb-map-name%22%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20f'%3Cspan%3E%7Bnumber%7D%3C%2Fspan%3E%7Bname%7D%3C%2Fdiv%3E%3Cdiv%20class%3D%22nb-map-text%22%3E%7Bdetail%7D%3C%2Fdiv%3E%3C%2Fa%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20number%2C%20(name%2C%20detail)%20in%20enumerate(_stages%2C%20start%3D1))%0A%20%20%20%20%20%20%20%20return%20mo.Html(f'%3Cdiv%20class%3D%22nb-map%22%3E%7Bsteps%7D%3C%2Fdiv%3E')%0A%0A%20%20%20%20def%20lesson_section(title%2C%20lead%2C%20stage%3DNone%2C%20kicker%3DNone)%3A%0A%20%20%20%20%20%20%20%20if%20stage%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20top%20%3D%20f'%3Cdiv%20class%3D%22nb-eyebrow%22%3E%7B_markup.escape(kicker%20or%20%22%22)%7D%3C%2Fdiv%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20number%2C%20outline%20%3D%20%22%22%2C%20%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20anchor%20%3D%20_re.sub(r%22%5B%5Ea-z0-9%5D%2B%22%2C%20%22-%22%2C%20title.lower()).strip(%22-%22)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20rail%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20index%2C%20(name%2C%20_)%20in%20enumerate(_stages%2C%20start%3D1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20state%20%3D%20%22is-done%22%20if%20index%20%3C%20stage%20else%20%22is-current%22%20if%20index%20%3D%3D%20stage%20else%20%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20index%20%3E%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rail.append(f'%3Cspan%20class%3D%22nb-rail-arrow%20%7B%22is-done%22%20if%20index%20%3C%3D%20stage%20else%20%22%22%7D%22%3E%26%238594%3B%3C%2Fspan%3E')%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rail.append(f'%3Ca%20class%3D%22nb-rail-step%20%7Bstate%7D%22%20href%3D%22%23%7B_anchor(index)%7D%22%3E'%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%20f'%3Cspan%20class%3D%22nb-rail-number%22%3E%7Bindex%7D%3C%2Fspan%3E%7Bname%7D%3C%2Fa%3E')%0A%20%20%20%20%20%20%20%20%20%20%20%20top%20%3D%20f'%3Cdiv%20class%3D%22nb-rail%22%3E%7B%22%22.join(rail)%7D%3C%2Fdiv%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20number%20%3D%20f'%3Cspan%20class%3D%22nb-section-number%22%3E%7Bstage%7D%3C%2Fspan%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20outline%2C%20anchor%20%3D%20f'%3Cspan%20class%3D%22nb-outline-only%22%3E%7Bstage%7D%20%3C%2Fspan%3E'%2C%20_anchor(stage)%0A%20%20%20%20%20%20%20%20return%20mo.Html(%0A%20%20%20%20%20%20%20%20%20%20%20%20f'%3Cdiv%20class%3D%22nb-section%22%20id%3D%22%7Banchor%7D%22%3E%7Btop%7D%3Cdiv%20class%3D%22nb-section-head%22%3E%7Bnumber%7D%3Cdiv%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20f'%3Ch2%20id%3D%22%7Banchor%7D-title%22%3E%7Boutline%7D%7B_markup.escape(title)%7D%3C%2Fh2%3E'%0A%20%20%20%20%20%20%20%20%20%20%20%20f'%3Cdiv%20class%3D%22nb-standfirst%22%3E%7Blesson_md(lead).text%7D%3C%2Fdiv%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%3C%2Fdiv%3E')%0A%0A%20%20%20%20return%20lesson_md%2C%20lesson_section%2C%20workflow_map%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20workflow_map)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%23%20Learn%20volatility%20dynamics%20from%20observed%20paths%0A%0A%20%20%20%20The%20option%20lessons%20used%20**prices%20across%20strikes%20and%20maturities**.%20Here%20we%20observe%0A%20%20%20%20**daily%20log%20returns**%2C%20in%20time%20order.%20Can%20one%20history%20tell%20us%20how%20volatility%0A%20%20%20%20moves%2C%20how%20it%20relates%20to%20returns%2C%20and%20what%20drift%20is%20plausible%3F%0A%0A%20%20%20%20We%20start%20with%20rough%20Bergomi%20and%20a%20supplied%20variance%20curve%3A%0A%20%20%20%20**model%20%E2%86%92%20simulate%20%E2%86%92%20train%20%E2%86%92%20infer%20%E2%86%92%20check%20%E2%86%92%20use**.%0A%20%20%20%20The%20result%20is%20a%20joint%20parameter%20distribution%2C%20not%20a%20reconstructed%20volatility%20path.%0A%0A%20%20%20%20%7C%20Route%20%7C%20What%20you%20do%20%7C%20Model%20source%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20**Train%20here**%20%7C%20Generate%20a%20small%20training%20set%2C%20fit%20the%20GRU%20and%20flow%2C%20then%20infer%20parameters%20%7C%20A%20new%20tutorial%20model%2C%20kept%20in%20this%20session%20%7C%0A%20%20%20%20%7C%20**Optional%20pretrained%20model**%20%7C%20Load%20the%20supplied%20estimator%20and%20reveal%20more%20days%20%7C%20A%20larger%2C%20separately%20trained%20model%3B%20saved%20draws%20work%20without%20a%20download%20%7C%0A%0A%20%20%20%20First%20introduce%20the%20model%20and%20explore%20the%20forward%20simulator.%20Choose%20the%0A%20%20%20%20observed%20history%20immediately%20before%20producing%20posteriors.%20Training%20and%20model%20loading%20are%20explicit%20actions%3B%0A%20%20%20%20the%20small%20simulator%20runs%20locally.%0A%0A%20%20%20%20The%20supplied%20estimators%20learn%20useful%20information%2C%20but%20**all%20three%20failed%0A%20%20%20%20their%20final%20marginal-calibration%20screen**.%20We%20will%20inspect%20that%20distinction.%0A%20%20%20%20%22%22%22)%2C%20workflow_map()%2C%0A%20%20%20%20mo.accordion(%7B%22Where%20BayesFlow%20is%20used%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%7C%20Call%20%7C%20Role%20here%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20%60simulation.generate%60%20(NumPy)%20%7C%20Draw%20parameters%20and%20daily%20return%20histories%20before%20fitting%20%7C%0A%20%20%20%20%7C%20%60bf.Adapter%60%20%7C%20Route%20transformed%20labels%2C%20return%20tokens%2C%20time%20context%20and%20mask%20%7C%0A%20%20%20%20%7C%20%60bf.networks.RecurrentNetwork%60%20%7C%20Learn%20a%20causal%20GRU%20summary%20of%20the%20observed%20prefix%20%7C%0A%20%20%20%20%7C%20%60bf.networks.CouplingFlow%60%20%7C%20Learn%20the%20conditional%20joint%20parameter%20density%20%7C%0A%20%20%20%20%7C%20%60bf.BasicWorkflow%60%2C%20%60fit_offline%60%20%7C%20Fit%20the%20summary%20and%20density%20on%20simulated%20pairs%20%7C%0A%20%20%20%20%7C%20%60workflow.sample%60%20through%20%60inference.sample%60%20%7C%20Condition%20on%20returns%20and%20restore%20physical%20parameter%20units%20%7C%0A%20%20%20%20%7C%20%60bf.diagnostics%60%20%7C%20Inspect%20the%20tutorial%20fit's%20loss%3B%20saved%20cohort%20reports%20document%20calibration%20%7C%0A%20%20%20%20%22%22%22)%7D)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20The%20problem%20this%20notebook%20addresses%0A%0A%20%20%20%20An%20asset's%20daily%20returns%20are%20visible%3B%20its%20volatility%20process%20and%20generating%0A%20%20%20%20parameters%20are%20hidden.%20This%20notebook%20addresses%20the%20inverse%20problem%3A%0A%20%20%20%20**infer%20which%20fixed%20stochastic-volatility%20parameters%20can%20explain%20one%20ordered%0A%20%20%20%20return%20history%2C%20while%20quantifying%20the%20uncertainty%20that%20remains.**%20Different%0A%20%20%20%20parameter%20combinations%20can%20produce%20similar%20histories%2C%20making%20a%20single%0A%20%20%20%20best-fitting%20vector%20an%20incomplete%20answer.%0A%0A%20%20%20%20We%20train%20BayesFlow%20on%20simulated%20parameter%E2%80%93history%20pairs%20to%20approximate%20the%0A%20%20%20%20joint%20parameter%20posterior.%20Synthetic%20examples%20let%20us%20reveal%20more%20evidence%2C%0A%20%20%20%20compare%20inference%20with%20known%20generating%20values%2C%20and%20check%20the%20learned%0A%20%20%20%20uncertainty.%20We%20also%20clarify%20the%20additional%20information%20needed%20to%20turn%0A%20%20%20%20parameter%20inference%20into%20a%20continuation%20forecast.%0A%20%20%20%20%22%22%22)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_section%2C%20mo)%3A%0A%20%20%20%20market_window%20%3D%20mo.ui.dropdown(options%3D%7B%0A%20%20%20%20%20%20%20%20%222020%20to%20latest%20available%20%C2%B7%2013%20November%202026%22%3A%20%22voo-2020-20261113%22%2C%0A%20%20%20%20%20%20%20%20%222020%20crisis%20window%20%C2%B7%20256%20trading%20days%22%3A%20%22voo-covid-256%22%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%222020%20to%20latest%20available%20%C2%B7%2013%20November%202026%22%2C%20label%3D%22VOO%20market%20window%22)%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_section(%22The%20data%22%2C%20%22Compare%20market%20returns%20with%20a%20simulated%20history%20and%20a%20matched%20Gaussian.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kicker%3D%22Before%20the%20workflow%22)%2C%0A%20%20%20%20%20%20%20%20market_window%2C%0A%20%20%20%20%20%20%20%20mo.md(%22This%20selects%20the%20**VOO%20observations%20in%20the%20next%20chart**.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20illustrative%20Bergomi%20history%20stays%20fixed%20for%20comparison.%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%20(market_window%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20market_story%0A%20%20%20%20%23%20An%20illustrative%20forward%20simulation%20only%3A%20no%20fitting%20or%20market%20inference.%0A%20%20%20%20illustrative_market_model%20%3D%20market_story.model_example()%0A%20%20%20%20return%20illustrative_market_model%2C%20market_story%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(illustrative_market_model%2C%20market_story%2C%20market_window%2C%20mo%2C%20trajectory)%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20_market%20%3D%20trajectory.load_market_example(market_window.value)%0A%20%20%20%20%20%20%20%20_metadata%20%3D%20_market%5B%22metadata%22%5D%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22%23%23%23%20What%20behavior%20are%20we%20trying%20to%20explain%3F%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Compare%20VOO%20with%20an%20explicit%20rough-Bergomi%20simulation%20using%20the%20**same%20trace%20and%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22tail-frequency%20views**.%20A%20Gaussian%20benchmark%20is%20matched%20to%20each%20displayed%20history's%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22mean%20and%20standard%20deviation.%20Does%20that%20match%20its%20frequency%20of%20large%20moves%3F%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22**Selected%20VOO%20window%3A%20%7B_market%5B'dates'%5D%5B0%5D%7D%20to%20%7B_market%5B'dates'%5D%5B-1%5D%7D%20%C2%B7%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Blen(_market%5B'dates'%5D)%3A%2C%7D%20daily%20returns.**%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20market_story.comparison_figure(_market%2C%20illustrative_market_model)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22**Bergomi%20can%20produce%20more%20large%20moves%20than%20a%20matched%20Gaussian.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22even%20though%20their%20mean%20and%20standard%20deviation%20match.%20Its%20instantaneous%20shocks%20are%20Gaussian%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22but%20their%20scale%20changes%20with%20hidden%20variance.%20This%20illustrates%20non-Gaussian%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22behavior%3B%20these%20parameters%20have%20not%20been%20fitted%20to%20VOO.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22**The%20synthetic%20lesson%20uses%201%2C260%20trading%20days.**%20The%20longer%20VOO%20snapshot%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22contains%201%2C726%20returns%20and%20extends%20beyond%20the%20neural%20estimator's%20five-year%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22training%20horizon.%20This%20descriptive%20market%20comparison%20does%20not%20extend%20that%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22estimator's%20supported%20input%20length.%22)%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.accordion(%7B%22Data%2C%20model%20settings%20and%20interpretation%22%3A%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22The%20dated%20VOO%20snapshot%20preserves%20adjusted-close%20returns%2C%20including%20corporate-action%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22adjustments%2C%20and%20converts%20simple%20returns%20with%20%60log1p%60.%20No%20recentering%2C%20volatility%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22normalization%2C%20filtering%20or%20market%20inference%20is%20performed.%20Each%20Gaussian%20uses%20its%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22own%20history's%20mean%20and%20population%20standard%20deviation%20as%20a%20descriptive%20control.%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22The%20Bergomi%20panel%20uses%20H%20%3D%200.12%2C%20eta%20%3D%201.2%2C%20rho%20%3D%20-0.7%2C%20drift%20%3D%200.07%20and%20a%20flat%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22mean-variance%20curve%20of%200.04.%20These%20settings%20and%20seed%2020261114%20were%20fixed%20for%20the%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22illustration%2C%20not%20estimated%20from%20VOO.%20Time%20starts%20at%20the%20model's%20origin%3B%20its%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22nonstationary%20long-history%20behavior%20is%20explained%20below.%20The%20same%20single%20simulated%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22history%20supplies%20both%20the%20trace%20and%20its%20tail%20curve.%20Empirical%20probabilities%20are%20discrete%3B%20a%20finite%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22tail%20plot%20is%20not%20a%20formal%20normality%20or%20model-adequacy%20test.%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20f%22Source%3A%20%7B_metadata.get('source_url'%2C%20_metadata%5B'source'%5D)%7D%20%20%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20f%22Last%20recorded%20trading%20date%3A%20**%7B_market%5B'dates'%5D%5B-1%5D%7D**.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22The%20notebook%20reads%20the%20accepted%20snapshot%20offline%20and%20does%20not%20download%20data%20on%20opening.%22)%7D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(%22**Next%3A%20a%20controlled%20synthetic%20history.**%20Its%20generating%20parameters%20and%20hidden%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%22variance%20are%20known%20for%20illustration.%20Only%20its%20returns%20enter%20the%20parameter%20estimator.%22)%5D)%0A%20%20%20%20%20%20%20%20%23%20%5D)%0A%20%20%20%20except%20(OSError%2C%20ValueError%2C%20KeyError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.callout(mo.md(f%22**Empirical%20motivation%20unavailable%3A**%20%7B_error%7D.%20%22%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%20%20%20%20%20%22The%20synthetic%20lesson%20remains%20available%20below.%22)%2C%20kind%3D%22warn%22)%0A%20%20%20%20_panel%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20trajectory)%3A%0A%20%20%20%20model_choice%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%7Blabel%3A%20key%20for%20key%2C%20label%20in%20trajectory.MODEL_LABELS.items()%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%22Rough%20Bergomi%20%C2%B7%20known%20variance%20curve%22%2C%20label%3D%22Stochastic%20volatility%20model%22)%0A%20%20%20%20mo.accordion(%7B%22Explore%20another%20model%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20model_choice%2C%0A%20%20%20%20%20%20%20%20mo.md(%22The%20other%20examples%20infer%20the%20rough%20variance%20curve%20or%20use%20Heston.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Each%20model%20has%20its%20own%20synthetic%20histories%20and%20fitted%20estimator%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22switching%20models%20changes%20the%20data%20as%20well%20as%20the%20assumptions.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22This%20selects%20the%20supplied%20example%3B%20the%20small%20live-training%20exercise%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22below%20remains%20rough%20Bergomi%20with%20the%20supplied%20curve.%22)%2C%0A%20%20%20%20%5D)%7D)%0A%20%20%20%20return%20(model_choice%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20model_choice%2C%20trajectory)%3A%0A%20%20%20%20mo.stop(not%20trajectory.CATALOGUE.is_file()%2C%20mo.callout(mo.md(%0A%20%20%20%20%20%20%20%20%22**Trajectory%20examples%20are%20not%20packaged%20in%20this%20copy.**%20See%20the%20tutorial%20%22%0A%20%20%20%20%20%20%20%20%22README%20for%20the%20matching%20assets.%20No%20training%20or%20model%20download%20starts%20automatically.%22)%2C%20kind%3D%22info%22))%0A%20%20%20%20cache_task%2C%20cache_report%2C%20cache_arrays%20%3D%20trajectory.load_example(model_choice.value)%0A%20%20%20%20return%20cache_arrays%2C%20cache_report%2C%20cache_task%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20lesson_md%2C%20lesson_section%2C%20mo)%3A%0A%20%20%20%20parameter_labels%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22kappa%22%3A%20%22Mean%20reversion%20%CE%BA%22%2C%20%22long_variance%22%3A%20%22Long%20variance%20L%22%2C%0A%20%20%20%20%20%20%20%20%22vol_of_vol%22%3A%20%22Volatility%20of%20variance%20%CF%83%22%2C%20%22rho%22%3A%20%22Leverage%20correlation%20%CF%81%22%2C%0A%20%20%20%20%20%20%20%20%22hurst%22%3A%20%22Roughness%20H%22%2C%20%22eta%22%3A%20%22Log-variance%20dispersion%20%CE%B7%22%2C%0A%20%20%20%20%20%20%20%20%22short_variance%22%3A%20%22Short%20variance%20S%22%2C%20%22decay%22%3A%20%22Curve%20decay%20k%22%2C%20%22drift%22%3A%20%22Physical%20drift%20%CE%BC%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20_meanings%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22kappa%22%3A%20%22Speed%20of%20reversion%20toward%20the%20long%20variance%20level%22%2C%0A%20%20%20%20%20%20%20%20%22long_variance%22%3A%20%22Long%20variance%20level%22%2C%0A%20%20%20%20%20%20%20%20%22vol_of_vol%22%3A%20%22Strength%20of%20variance%20shocks%22%2C%20%22rho%22%3A%20%22Correlation%20of%20price%20and%20variance-driver%20shocks%22%2C%0A%20%20%20%20%20%20%20%20%22hurst%22%3A%20%22Roughness%20of%20the%20Gaussian%20variance%20driver%22%2C%20%22eta%22%3A%20%22Dispersion%20of%20log%20variance%20at%20a%20fixed%20mean-variance%20curve%22%2C%0A%20%20%20%20%20%20%20%20%22short_variance%22%3A%20%22Initial%20variance-curve%20level%22%2C%20%22decay%22%3A%20%22Speed%20of%20transition%20between%20curve%20levels%22%2C%0A%20%20%20%20%20%20%20%20%22drift%22%3A%20%22Annual%20proportional%20price%20drift%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20_priors%20%3D%20%5B%7B%22parameter%22%3A%20parameter_labels%5B_name%5D%2C%20%22meaning%22%3A%20_meanings%5B_name%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prior%22%3A%20(%22Log-uniform%22%20if%20_kind%20%3D%3D%20%22log_uniform%22%20else%20%22Uniform%22)%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%2B%20f%22%20%5B%7B_bounds%5B0%5D%3Ag%7D%2C%20%7B_bounds%5B1%5D%3Ag%7D%5D%22%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_name%2C%20_kind%2C%20_bounds%20in%20zip(cache_task%5B%22parameter_names%22%5D%2C%20cache_task%5B%22prior_types%22%5D%2C%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%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20cache_task%5B%22prior_bounds%22%5D%2C%20strict%3DTrue)%5D%0A%20%20%20%20_heston%20%3D%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%0A%20%20%20%20_curve%20%3D%20(%22**Selected%20task%3A%20Heston.**%20Initial%20variance%20is%20supplied%3B%20the%20five%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22parameters%20in%20the%20table%20are%20inferred.%20A%20supplied%20initial%20value%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22does%20not%20fix%20the%20subsequent%20realized%20variance%20path.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_heston%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20r%22**Selected%20task%3A%20rough%20Bergomi%20with%20a%20supplied%20curve.**%20We%20set%20%24%5Cxi(t)%3D0.04%24%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22the%20deterministic%20ensemble%20mean%20of%20variance%2C%20and%20infer%20four%20parameters.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Each%20realized%20variance%20path%20remains%20random.%20The%20joint-curve%20example%20relaxes%20this%20assumption.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22rough-known%22%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20r%22**Selected%20task%3A%20rough%20Bergomi%20with%20an%20inferred%20curve.**%20We%20use%20%24%5Cxi(t)%3DL%2B(S-L)e%5E%7B-kt%7D%24.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20short%20level%20S%2C%20long%20level%20L%20and%20decay%20k%20join%20the%20other%20four%20parameters%20as%20joint%20targets.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22These%20coefficients%20are%20constant%20within%20each%20generated%20history%3B%20the%20realized%20variance%20is%20random.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Learning%20a%20mean%20curve%20does%20not%20turn%20this%20estimator%20into%20a%20latent-state%20filter.%22)%0A%20%20%20%20_steps%20%3D%20cache_task%5B%22numerics%22%5D.get(%22substeps%22%2C%20cache_task%5B%22numerics%22%5D.get(%22observation_substeps%22))%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_section(%22Model%22%2C%20%22Specify%20the%20return%20dynamics%20and%20parameter%20prior%2C%20then%20inspect%20one%20synthetic%20history.%22%2C%20stage%3D1)%2C%20lesson_md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%201.1%20Dynamics%20and%20unknowns%0A%0A%20%20%20%20%20%20%20%20**The%20price%20equation%20is%20shared%20with%20Heston%3B%20the%20variance%20mechanism%20changes.**%0A%20%20%20%20%20%20%20%20We%20model%20one%20ordered%20return%20history%20under%20the%20physical%20probability%20**P**.%0A%20%20%20%20%20%20%20%20Here%20are%20the%20rough%20Bergomi%20components%20together%2C%20in%20continuous%20time%3A%0A%0A%20%20%20%20%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20%20%20%20%20%5Cfrac%7BdS_t%7D%7BS_t%7D%26%3D%5Cmu%5C%2Cdt%2B%5Csqrt%7BV_t%7D%5C%2CdW_t%5ES%2C%0A%20%20%20%20%20%20%20%20%26d%5Clangle%20W%5ES%2CW%5EV%5Crangle_t%26%3D%5Crho%5C%2Cdt%2C%5C%5C%0A%20%20%20%20%20%20%20%20Y_t%26%3D%5Csqrt%7B2H%7D%5Cint_0%5Et(t-s)%5E%7BH-1%2F2%7D%5C%2CdW_s%5EV%2C%0A%20%20%20%20%20%20%20%20%26q(t)%26%3D%5Coperatorname%7BVar%7D(Y_t)%3Dt%5E%7B2H%7D%2C%5C%5C%0A%20%20%20%20%20%20%20%20V_t%26%3D%5Cxi(t)%5Cexp%5C!%5Cleft(%5Ceta%20Y_t-%5Ctfrac12%5Ceta%5E2q(t)%5Cright)%2C%0A%20%20%20%20%20%20%20%20%26Y_0%26%3D0%2C%5Cquad%20V_0%3D%5Cxi(0).%0A%20%20%20%20%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20%20%20%20%20Time%20is%20measured%20in%20years%2C%20with%20**252%20observed%20trading%20days%20per%20year**.%0A%20%20%20%20%20%20%20%20%24W%5ES%24%20and%20%24W%5EV%24%20are%20standard%20Brownian%20drivers%20under%20P.%0A%0A%20%20%20%20%20%20%20%20-%20**Price%20%24S_t%24%3A**%20%CE%BC%20is%20the%20annual%20proportional%20price%20drift.%20Variance%20%24V_t%24%0A%20%20%20%20%20%20%20%20%20%20sets%20the%20noise%20scale%3B%20volatility%20is%20%24%5Csqrt%7BV_t%7D%24.%0A%20%20%20%20%20%20%20%20-%20**Driver%20%24Y_t%24%3A**%20a%20weighted%20history%20of%20Gaussian%20innovations.%20The%20power-law%0A%20%20%20%20%20%20%20%20%20%20kernel%20gives%20recent%20innovations%20more%20weight%3B%20H%20controls%20its%20roughness.%0A%20%20%20%20%20%20%20%20-%20**Variance%20%24V_t%24%3A**%20exponentiating%20the%20driver%20makes%20it%20positive.%20%CE%B7%20controls%0A%20%20%20%20%20%20%20%20%20%20log-variance%20dispersion.%20The%20compensator%20%24-%5Ceta%5E2q(t)%2F2%24%20ensures%0A%20%20%20%20%20%20%20%20%20%20%24%5Cmathbb%20E_P%5BV_t%5D%3D%5Cxi(t)%24%3B%20it%20does%20not%20pull%20each%20path%20toward%20that%20mean.%0A%20%20%20%20%20%20%20%20-%20**Correlation%20%CF%81%3A**%20price%20and%20variance-driver%20innovations%20are%20correlated.%0A%20%20%20%20%20%20%20%20%20%20Negative%20%CF%81%20creates%20leverage%2C%20linking%20negative%20price%20innovations%20with%0A%20%20%20%20%20%20%20%20%20%20positive%20variance-driver%20innovations.%0A%0A%20%20%20%20%20%20%20%20We%20observe%20daily%20**log%20returns**%2C%20so%20It%C3%B4's%20formula%20supplies%20the%20correction%0A%0A%20%20%20%20%20%20%20%20%24%24d%5Clog%20S_t%3D(%5Cmu-V_t%2F2)%5C%2Cdt%2B%5Csqrt%7BV_t%7D%5C%2CdW_t%5ES.%24%24%0A%0A%20%20%20%20%20%20%20%20**What%20differs%20from%20Heston%3F**%20Keep%20the%20same%20price%20equation%20and%20correlation%2C%0A%20%20%20%20%20%20%20%20but%20replace%20the%20driver%20and%20exponential%20variance%20construction%20by%0A%0A%20%20%20%20%20%20%20%20%24%24dV_t%3D%5Ckappa(L-V_t)%5C%2Cdt%2B%5Csigma%5Csqrt%7BV_t%7D%5C%2CdW_t%5EV.%24%24%0A%0A%20%20%20%20%20%20%20%20%7C%20%7C%20Heston%20variance%20%7C%20Rough%20Bergomi%20variance%20above%20%7C%0A%20%20%20%20%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%20%20%20%20%7C%20Random%20mechanism%20%7C%20Square-root%20diffusion%20%7C%20Exponential%20of%20a%20Gaussian%20Volterra%20driver%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Memory%20%7C%20Current%20variance%20is%20a%20Markov%20state%20%7C%20With%20%24%5Ceta%3E0%24%20and%20%24H%3C1%2F2%24%2C%20current%20variance%20alone%20does%20not%20summarize%20the%20past%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Mean%20reversion%20%7C%20%24%5Ckappa(L-V_t)%24%20pulls%20variance%20toward%20L%20%7C%20No%20corresponding%20restoring%20drift%3B%20%24%5Cxi(t)%24%20specifies%20the%20ensemble%20mean%20%7C%0A%0A%20%20%20%20%20%20%20%20These%20equations%20describe%20the%20mathematical%20models.%20**The%20estimator%20learns%0A%20%20%20%20%20%20%20%20our%20declared%20finite-step%20simulator%3A**%20rough%20Bergomi%20uses%20the%20hybrid%0A%20%20%20%20%20%20%20%20driver's%20actual%20variance%20%24q_i%3D%5Coperatorname%7BVar%7D_%7B%5Crm%20grid%7D(Y_i)%24%20in%20the%0A%20%20%20%20%20%20%20%20compensator%2C%20rather%20than%20substituting%20%24t_i%5E%7B2H%7D%24.%20The%20numerical%20updates%0A%20%20%20%20%20%20%20%20appear%20together%20in%20**The%20discrete%20model%2C%20step%20by%20step**%20below.%0A%0A%20%20%20%20%20%20%20%20The%20option%20lessons%20used%20a%20pricing%20probability%20**Q**%2C%20under%20which%20discounted%0A%20%20%20%20%20%20%20%20prices%20are%20martingales.%20A%20parameter%20fitted%20under%20P%20need%20not%20have%20the%20same%0A%20%20%20%20%20%20%20%20value%20under%20Q%3B%20this%20is%20a%20declared%20return-history%20law%2C%20not%20a%20fitted%20change%0A%20%20%20%20%20%20%20%20of%20measure.%20Returns%20contain%20process%20randomness%2C%20with%20**no%20extra%0A%20%20%20%20%20%20%20%20measurement-error%20or%20quote-noise%20term**.%20The%20variance%20constructions%20follow%0A%20%20%20%20%20%20%20%20%5BHeston%5D(https%3A%2F%2Fdoi.org%2F10.1093%2Frfs%2F6.2.327)%20and%0A%20%20%20%20%20%20%20%20%5BBayer%2C%20Friz%20and%20Gatheral%5D(https%3A%2F%2Frealvol.com%2FRVOL2Paper.pdf)%3B%20our%20physical%0A%20%20%20%20%20%20%20%20drift%2C%20initialization%20and%20training%20priors%20are%20explicit%20tutorial%20choices.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.md(_curve)%2C%0A%20%20%20%20%20%20%20%20mo.ui.table(_priors%2C%20selection%3DNone%2C%20pagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20mo.accordion(%7B%22Why%20this%20H%20prior%2C%20and%20what%20happens%20at%20H%20%3D%201%2F2%3F%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20**We%20assume%20the%20rough%20regime%20when%20training%20this%20estimator.**%20The%20uniform%0A%20%20%20%20%20%20%20%20prior%20%24H%5Cin%5B0.03%2C0.4%5D%24%20covers%20strongly%20rough%20through%20less%20rough%20paths.%0A%20%20%20%20%20%20%20%20High-frequency%20volatility%20studies%20motivate%20values%20often%20around%200.1%0A%20%20%20%20%20%20%20%20(%5BGatheral%2C%20Jaisson%20and%20Rosenbaum%5D(https%3A%2F%2Farxiv.org%2Fabs%2F1410.3394))%2C%0A%20%20%20%20%20%20%20%20but%20do%20not%20prescribe%20our%20exact%20endpoints%20or%20a%20uniform%20density.%20Those%0A%20%20%20%20%20%20%20%20are%20simulation%2Ftraining%20design%20choices%2C%20kept%20away%20from%20the%20endpoints%0A%20%20%20%20%20%20%20%20of%20the%20supported%20interval%20%240%3CH%3C1%2F2%24.%0A%0A%20%20%20%20%20%20%20%20**Gaussianity%20and%20roughness%20are%20different%20properties.**%20The%20driver%0A%20%20%20%20%20%20%20%20%24Y_t%24%20above%20is%20Gaussian%20for%20every%20H%3A%20it%20is%20a%20linear%20integral%20of%0A%20%20%20%20%20%20%20%20Brownian%20noise.%20Smaller%20H%20makes%20its%20paths%0A%20%20%20%20%20%20%20%20rougher%20and%20changes%20dependence%3B%20it%20does%20not%20make%20the%20driver%20non-Gaussian.%0A%0A%20%20%20%20%20%20%20%20At%20the%20mathematical%20boundary%20%24H%3D1%2F2%24%2C%20the%20kernel%20becomes%20constant%20and%0A%20%20%20%20%20%20%20%20%24Y_t%3DW_t%5EV%24%2C%20ordinary%20Brownian%20motion.%20For%20%24%5Ceta%3E0%24%2C%20variance%20remains%0A%20%20%20%20%20%20%20%20random%20and%20lognormal%20at%20a%20fixed%20time.%20This%20does%20**not**%20give%20a%0A%20%20%20%20%20%20%20%20constant-volatility%20Gaussian-return%20model.%20That%20benchmark%20would%20use%0A%20%20%20%20%20%20%20%20%24%5Ceta%3D0%24%20and%20a%20constant%20supplied%20variance%20curve.%0A%0A%20%20%20%20%20%20%20%20This%20estimator%20cannot%20test%20whether%20%24H%3D1%2F2%24%20is%20adequate%3A%20its%20prior%0A%20%20%20%20%20%20%20%20excludes%20that%20possibility.%20Our%20current%20rough-driver%20implementation%0A%20%20%20%20%20%20%20%20also%20enforces%20%240%3CH%3C1%2F2%24.%20Comparing%20the%20Brownian%20boundary%20needs%20a%0A%20%20%20%20%20%20%20%20matching%20simulator%20and%20estimator%3B%20changing%20a%20label%20or%20slider%20cannot%0A%20%20%20%20%20%20%20%20extend%20the%20existing%20checkpoint's%20training%20support.%0A%20%20%20%20%20%20%20%20%22%22%22)%7D)%20if%20not%20_heston%20else%20mo.md(%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.accordion(%7B%22Priors%2C%20supplied%20quantities%20and%20numerical%20details%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22The%20parameter%20priors%20are%20independent.%20Uniform%20priors%20assign%20equal%20probability%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22to%20equal-width%20intervals%3B%20log-uniform%20priors%20assign%20equal%20probability%20to%20equal%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22multiplicative%20ranges.%20A%20log-uniform%20density%20on%20%5Ba%2Cb%5D%20is%201%2F%5Bx%20log(b%2Fa)%5D.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Supplied%20quantities%20are%20modelling%20assumptions%2C%20not%20measurements%20of%20latent%20volatility.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(%5B%7B%22supplied%20quantity%22%3A%20_name.replace(%22_%22%2C%20%22%20%22)%2C%20%22value%22%3A%20_value%7D%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%20for%20_name%2C%20_value%20in%20cache_task%5B%22fixed%22%5D.items()%5D%2C%20selection%3DNone%2C%20pagination%3DFalse)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20cache_task%5B%22fixed%22%5D%20else%20mo.md(%22No%20fixed%20model%20parameters%20in%20this%20joint-curve%20task.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22The%20simulator%20uses%20**%7B_steps%7D%20internal%20steps%20per%20day**%2C%20then%20supplies%20one%20daily%20return.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Inference%20is%20trained%20for%20that%20finite-step%20law.%20Changing%20models%20does%20not%20change%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22the%20daily%20observation%20frequency.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22The%20Heston%20implementation%20uses%20a%20signed%20auxiliary%20variance%20state%20and%20its%20positive%20part.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20rough%20implementation%20uses%20a%20hybrid%20Gaussian%20driver%20and%20its%20matching%20variance%20compensator.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20step-by-step%20equations%20below%20describe%20the%20selected%20numerical%20law.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Each%20history%20starts%20at%20the%20declared%20origin%3B%20extending%20it%20reveals%20an%20older%20process%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22rather%20than%20a%20stationary%20window%20shifted%20to%20a%20new%20starting%20date.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(%5B%7B%22setting%22%3A%20_name.replace(%22_%22%2C%20%22%20%22)%2C%20%22value%22%3A%20_value%7D%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%20for%20_name%2C%20_value%20in%20cache_task%5B%22numerics%22%5D.items()%5D%2C%20selection%3DNone%2C%20pagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%5D)%7D)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%20(parameter_labels%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20mo)%3A%0A%20%20%20%20_warning%20%3D%20(mo.callout(mo.md(%0A%20%20%20%20%20%20%20%20%22**Heston%20numerical%20limitation.**%20The%20finite-step%20simulator%20can%20keep%20effective%20variance%20%22%0A%20%20%20%20%20%20%20%20%22at%20zero%20for%20an%20entire%20day%2C%20making%20that%20return%20exactly%20drift%20%C3%97%20time.%20Its%20drift%20posterior%20%22%0A%20%20%20%20%20%20%20%20%22can%20therefore%20contain%20a%20point%20mass%20that%20a%20continuous%20neural%20density%20cannot%20represent%20%22%0A%20%20%20%20%20%20%20%20%22exactly.%20Resolving%20this%20needs%20a%20new%20numerical%20specification%20and%20fit.%22)%2C%20kind%3D%22warn%22)%0A%20%20%20%20%20%20%20%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%20else%20mo.md(%22%22))%0A%20%20%20%20_warning%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20mo)%3A%0A%20%20%20%20_heston%20%3D%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%0A%20%20%20%20_innovations%20%3D%20(r%22%22%22%0A%20%20%20%20The%20Heston%20simulator%20draws%20independent%20%24Z_j%5EV%2CZ_j%5E%5Cperp%5Csim%20N(0%2C1)%24%20at%0A%20%20%20%20each%20internal%20step%20and%20for%20each%20path.%20A%20Brownian%20increment%20is%20%24%5Csqrt%20h%20Z%24.%0A%20%20%20%20The%20variance%20shock%20uses%20%24Z_j%5EV%24%3B%20the%20price%20shock%20uses%0A%20%20%20%20%24%5Crho%20Z_j%5EV%2B%5Csqrt%7B1-%5Crho%5E2%7DZ_j%5E%5Cperp%24.%20Shared%20%24Z_j%5EV%24%20gives%20the%20chosen%0A%20%20%20%20price%E2%80%93variance%20correlation.%20These%20process%20shocks%20are%20not%20measurement%20noise.%0A%20%20%20%20%22%22%22%20if%20_heston%20else%20r%22%22%22%0A%20%20%20%20Rough%20Bergomi%20uses%20three%20independent%20standard-normal%20channels%20per%20internal%0A%20%20%20%20step%3A%20%24Z%5EW%24%2C%20a%20Gaussian%20bridge%20residual%20%24Z%5EB%24%2C%20and%20%24Z%5E%5Cperp%24.%0A%20%20%20%20The%20hybrid%20convolution%20of%20past%20%24Z%5EW%24%20values%20plus%20%24Z%5EB%24%20builds%20the%20Gaussian%0A%20%20%20%20driver%20%24Y%24.%20The%20bridge%20residual%20approximates%20the%20kernel's%20most%20recent%2C%0A%20%20%20%20singular%20contribution%3B%20it%20is%20not%20a%20quote%20or%20measurement%20error.%0A%20%20%20%20The%20price%20shock%20is%20%24%5Crho%20Z%5EW%2B%5Csqrt%7B1-%5Crho%5E2%7DZ%5E%5Cperp%24.%0A%20%20%20%20Paths%20draw%20independent%20channels.%20A%20fixed%20seed%20freezes%20these%20normal%20draws%0A%20%20%20%20within%20the%20selected%20model%3B%20changing%20parameters%20still%20changes%20its%20variance%0A%20%20%20%20and%20return%20paths.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20_calculation%20%3D%20(r%22%22%22%0A%20%20%20%20**Eight%20internal%20steps%20make%20one%20observed%20day.**%20Write%20%24h%3D1%2F(252%5Ccdot8)%24%2C%0A%20%20%20%20let%20%24%5Cwidetilde%20V_j%24%20be%20the%20signed%20numerical%20variance%20state%2C%20and%20set%0A%20%20%20%20%24v_j%3D%5Cmax(%5Cwidetilde%20V_j%2C0)%24.%20Each%20step%20computes%0A%0A%20%20%20%20%24%24%5CDelta%5Cell_j%3D(%5Cmu-v_j%2F2)h%2B%5Csqrt%7Bv_jh%7D%0A%20%20%20%20%20%20%20(%5Crho%20Z_j%5EV%2B%5Csqrt%7B1-%5Crho%5E2%7DZ_j%5E%5Cperp)%2C%24%24%0A%0A%20%20%20%20%24%24%5Cwidetilde%20V_%7Bj%2B1%7D%3D%5Cwidetilde%20V_j%2B%5Ckappa(L-v_j)h%0A%20%20%20%20%20%20%20%2B%5Csigma%5Csqrt%7Bv_jh%7DZ_j%5EV.%24%24%0A%0A%20%20%20%20Sum%20the%20eight%20%24%5CDelta%5Cell_j%24%20values%20to%20obtain%20one%20daily%20log%20return.%0A%20%20%20%20The%20signed%20state%20and%20its%20positive%20part%20are%20different%20objects%3B%20neither%20is%0A%20%20%20%20an%20observed%20network%20input.%20The%20zero-variance-day%20limitation%20described%20above%0A%20%20%20%20belongs%20to%20this%20actual%20finite-step%20law.%0A%20%20%20%20%22%22%22%20if%20_heston%20else%20r%22%22%22%0A%20%20%20%20**Four%20internal%20steps%20make%20one%20observed%20day.**%20With%20%24h%3D1%2F(252%5Ccdot4)%24%2C%0A%20%20%20%20the%20hybrid%20driver%20and%20return%20update%20are%0A%0A%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20Y_i%26%3D%5Csum_%7Bj%3D0%7D%5E%7Bi-1%7Dw_%7Bij%7D(H%2Ch)Z_j%5EW%2Bb(H%2Ch)Z_%7Bi-1%7D%5EB%2C%0A%20%20%20%20%20%20%20%26q_i%26%3D%5Coperatorname%7BVar%7D_%7B%5Crm%20grid%7D(Y_i)%2C%5Cqquad%20i%5Cge1%2C%5C%5C%0A%20%20%20%20V_i%26%3D%5Cxi(t_i)%5Cexp(%5Ceta%20Y_i-%5Ctfrac12%5Ceta%5E2q_i)%2C%5C%5C%0A%20%20%20%20%5CDelta%5Cell_i%26%3D(%5Cmu-V_i%2F2)h%2B%5Csqrt%7BV_i%20h%7D%0A%20%20%20%20%20%20%20(%5Crho%20Z_i%5EW%2B%5Csqrt%7B1-%5Crho%5E2%7DZ_i%5E%5Cperp).%0A%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20Thus%20%24Y_i%24%20uses%20earlier%20shocks%2C%20while%20%24Z_i%5EW%24%20drives%20the%20next%20return%20step%0A%20%20%20%20and%20contributes%20to%20%24Y_%7Bi%2B1%7D%24.%20The%20return%20step%20uses%20left-endpoint%20variance.%20Four%20consecutive%0A%20%20%20%20%24%5CDelta%5Cell_i%24%20values%20are%20summed%20into%20one%20daily%20return.%20At%20the%20declared%0A%20%20%20%20origin%20%24Y_0%3Dq_0%3D0%24.%20The%20idealized%20continuous%20driver%20has%20variance%20%24t%5E%7B2H%7D%24%3B%0A%20%20%20%20substituting%20it%20for%20%24q_i%24%20would%20change%20this%20simulator's%20finite-grid%20law.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20_curve%20%3D%20(r%22%22%22%0A%20%20%20%20Heston%20supplies%20the%20initial%20variance%20%24V_0%3D0.04%24%2C%20not%20a%20subsequent%20variance%0A%20%20%20%20path.%20%24L%24%20is%20the%20mean-reversion%20destination%2C%20%24%5Ckappa%24%20its%20speed%2C%20and%20%24%5Csigma%24%0A%20%20%20%20the%20shock%20amplitude.%20Their%20P-law%20priors%20and%20the%20drift%20prior%20are%20shown%20above.%0A%20%20%20%20This%20task%20does%20not%20supply%20a%20market-derived%20forward-variance%20curve.%0A%20%20%20%20%22%22%22%20if%20_heston%20else%20r%22%22%22%0A%20%20%20%20**Which%20curve%20is%20fixed%3F**%20The%20supplied%20example%20fixes%20only%20the%20deterministic%0A%20%20%20%20mean-variance%20curve%2C%20not%20the%20latent%20path.%20Three%20distinct%20objects%20appear%3A%0A%0A%20%20%20%20%7C%20Object%20%7C%20Meaning%20%7C%20Our%20inference%20task%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20%24%5Cxi(t)%24%20%7C%20Deterministic%20ensemble%20mean%20of%20variance%20%7C%20Supplied%2C%20or%20described%20by%20inferred%20curve%20coefficients%20%7C%0A%20%20%20%20%7C%20%24V_t%24%20%7C%20Random%20variance%20along%20one%20particular%20history%20%7C%20Hidden%3B%20integrated%20out%20of%20parameter%20inference%20%7C%0A%20%20%20%20%7C%20%24%5CTheta%24%20%7C%20Parameters%20shared%20across%20that%20history%20%7C%20Joint%20posterior%20target%20%7C%0A%0A%20%20%20%20In%20this%20declared%20synthetic%0A%20%20%20%20P%20model%2C%20%24%5Cxi(t_i)%3D%5Cmathbb%20E_P%5BV_i%5D%24%20at%20simulator%20grid%20nodes.%20The%20Gaussian%0A%20%20%20%20compensator%20ensures%20this%20equality%20for%20the%20hybrid%20approximation.%20It%20is%20a%0A%20%20%20%20physical-law%20variance-scale%20curve%2C%20not%20a%20Q%20curve%20estimated%20from%20option%20prices.%0A%0A%20%20%20%20**A%20constant%20mean%20does%20not%20make%20this%20process%20stationary.**%20At%20each%20grid%0A%20%20%20%20time%2C%20%24Y_i%5Csim%20N(0%2Cq_i)%24%2C%20so%0A%0A%20%20%20%20%24%24%5Cmathbb%20E_P%5BV_i%5D%3D%5Cxi(t_i)%2C%5Cqquad%0A%20%20%20%20%20%20%5Coperatorname%7Bmedian%7D(V_i)%3D%5Cxi(t_i)%5Cexp(-%5Ceta%5E2q_i%2F2).%24%24%0A%0A%20%20%20%20The%20contrast%20grows%20even%20while%20a%20typical%20path%20becomes%20quieter%3A%0A%0A%20%20%20%20%24%24%5Coperatorname%7BVar%7D(%5Clog%20V_i)%3D%5Ceta%5E2q_i%2C%5Cqquad%0A%20%20%20%20%20%20%5Coperatorname%7BVar%7D(V_i)%3D%5Cxi(t_i)%5E2%5Cbigl(e%5E%7B%5Ceta%5E2q_i%7D-1%5Cbigr).%24%24%0A%0A%20%20%20%20The%20driver%20variance%20%24q_i%24%20grows%20from%20zero.%20Its%20distribution%20therefore%0A%20%20%20%20widens%2C%20and%20its%20median%20falls%20relative%20to%20the%20mean.%20Rare%20high-variance%0A%20%20%20%20realizations%20keep%20the%20ensemble%20mean%20at%20the%20curve%20level%3B%20there%20is%20no%0A%20%20%20%20pathwise%20pull%20back%20to%20that%20level.%20This%20explains%20a%20tendency%20for%20typical%0A%20%20%20%20histories%20to%20become%20quiet%2C%20especially%20with%20larger%20amplitude%2C%20but%20does%0A%20%20%20%20not%20force%20an%20individual%20path%20to%20decline%20monotonically.%20The%20idealized%0A%20%20%20%20continuous%20driver%20has%20%24q(t)%3Dt%5E%7B2H%7D%24%3B%20the%20simulator%20uses%20its%20stated%20grid%0A%20%20%20%20variance.%20Revealing%20more%20days%20changes%20both%20evidence%20and%20process%20age.%0A%0A%20%20%20%20**What%20is%20this%20model%20suitable%20for%3F**%20It%20gives%20a%20precisely%20specified%20synthetic%0A%20%20%20%20task%3A%20learn%20which%20parameter%20combinations%20can%20generate%20an%20ordered%20history%2C%0A%20%20%20%20and%20test%20whether%20inference%20recovers%20those%20combinations.%20Its%20finite-origin%0A%20%20%20%20rough%20variance%20law%20is%20**not%20a%20stationary%20model%20of%20an%20arbitrary%20five-year%0A%20%20%20%20market%20window**.%20Quiet%20later%20segments%20can%20be%20a%20model%20effect%2C%20rather%20than%0A%20%20%20%20evidence%20that%20a%20market%20has%20permanently%20become%20calm.%20Before%20using%20this%20law%0A%20%20%20%20for%20real-market%20continuation%20forecasts%2C%20we%20would%20need%20to%20review%20the%20physical%0A%20%20%20%20variance%20dynamics%20and%20initialization%2Fprehistory%2C%20specify%20the%20state-inference%0A%20%20%20%20target%2C%20and%20validate%20a%20corresponding%20simulator%20and%20estimator.%20A%20different%0A%20%20%20%20initialization%20or%20mean-reverting%20rough%20law%20would%20require%20a%20new%20training%20task%3B%0A%20%20%20%20changing%20the%20plot%20or%20reusing%20the%20present%20checkpoint%20would%20not%20implement%20it.%0A%0A%20%20%20%20-%20**Supplied%20curve%3A**%20%24%5Cxi(t)%3D0.04%24.%20Mean%20variance%20is%20constant%20at%20%240.2%5E2%24%3B%0A%20%20%20%20%20%20each%20realized%20%24V_i%24%20still%20fluctuates.%20The%20constant%20does%20not%20say%20that%20the%0A%20%20%20%20%20%20average%20realized%20volatility%20is%20exactly%2020%25.%0A%20%20%20%20-%20**Inferred%20curve%3A**%20%24%5Cxi(t)%3DL%2B(S-L)e%5E%7B-kt%7D%24.%20%24S%24%20is%20the%20initial%20level%2C%0A%20%20%20%20%20%20%24L%24%20the%20long%20level%2C%20and%20%24k%24%20the%20transition%20rate.%20These%20coefficients%20join%0A%20%20%20%20%20%20%24H%2C%5Ceta%2C%5Crho%2C%5Cmu%24%20as%20targets%3B%20they%20are%20not%20extra%20inputs%20supplied%20to%20the%20GRU.%0A%20%20%20%20%20%20If%20%24S%24%20and%20%24L%24%20are%20similar%2C%20changing%20%24k%24%20barely%20changes%20the%20curve%2C%20so%0A%20%20%20%20%20%20decay%20can%20remain%20weakly%20informed.%0A%0A%20%20%20%20**To%20relax%20the%20supplied%20curve**%2C%20select%20the%20rough%20Bergomi%20joint-curve%20model%0A%20%20%20%20in%20**Explore%20another%20model**.%20It%20has%20its%20own%20estimator%3A%20seven%20fixed%0A%20%20%20%20parameters%20rather%20than%20four.%20Changing%200.04%20under%20the%20supplied%20estimator%0A%20%20%20%20would%20change%20its%20training%20task%2C%20so%20it%20cannot%20be%20treated%20as%20a%20free%20query%20input.%0A%0A%20%20%20%20This%20choice%20is%20separate%20from%20filtering.%20Even%20after%20learning%20%24S%2CL%2Ck%24%2C%20we%0A%20%20%20%20still%20have%20to%20infer%20a%20history's%20latent%20state%20and%20memory%20to%20continue%20it%20from%0A%20%20%20%20its%20last%20observation.%20Curve%20uncertainty%20is%20uncertainty%20about%20the%20ensemble%0A%20%20%20%20law%3B%20state%20uncertainty%20is%20uncertainty%20about%20this%20particular%20realization.%0A%0A%20%20%20%20At%20a%20fixed%20driver%20realization%2C%20%24%5Cpartial_%5Ceta%5Clog%20V_i%3DY_i-%5Ceta%20q_i%24%20can%0A%20%20%20%20be%20negative.%20Thus%20larger%20%CE%B7%20means%20a%20wider%20log-variance%20distribution%2C%20not%20a%0A%20%20%20%20guarantee%20that%20every%20displayed%20return%20or%20variance%20amplitude%20increases.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20mo.accordion(%7B%0A%20%20%20%20%20%20%20%20%22P%20versus%20Q%3A%20what%20changes%20from%20the%20option%20lessons%3F%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20%7C%20%7C%20Return-history%20lesson%20%7C%20Option%20lessons%20%7C%0A%20%20%20%20%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%20%20%20%20%7C%20Data%20%7C%20One%20ordered%20history%20of%20daily%20returns%20%7C%20Option%20prices%20across%20strikes%20and%20maturities%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Law%20%7C%20Physical%20probability%20P%20%7C%20Pricing%20probability%20Q%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Price%20drift%20%7C%20Inferred%20physical%20growth%20rate%20%24%5Cmu%24%20%7C%20Rate%20minus%20dividend%20yield%3B%20zero%20in%20the%20examples%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Randomness%20in%20an%20observation%20%7C%20Process%20shocks%20along%20that%20history%20%7C%20The%20declared%20option%20observation%20model%20%7C%0A%0A%20%20%20%20%20%20%20%20Fitting%20either%20model%20does%20not%20estimate%20the%20change%20of%20measure%20between%20them.%0A%20%20%20%20%20%20%20%20Similar%20parameter%20names%20therefore%20do%20not%20make%20the%20fitted%20laws%20interchangeable.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%22What%20are%20the%20random%20innovations%3F%22%3A%20mo.md(_innovations)%2C%0A%20%20%20%20%20%20%20%20%22The%20discrete%20model%2C%20step%20by%20step%22%3A%20mo.md(_calculation)%2C%0A%20%20%20%20%20%20%20%20%22What%20does%20the%20variance%20curve%20mean%3F%22%3A%20mo.md(_curve)%2C%0A%20%20%20%20%7D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20lesson_section%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5Blesson_section(%22Simulate%22%2C%20%22Choose%20parameters%20and%20generate%20ordered%20return%20histories%20before%20fitting%20a%20network.%22%2C%20stage%3D2)%2C%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%202.1%20Try%20the%20forward%20model%0A%0A%20%20%20%20**Choose%20the%20parameters%3B%20see%20the%20histories%20they%20can%20generate.**%20The%20sliders%0A%20%20%20%20use%20the%20model's%20declared%20parameter%20ranges.%20Eight%20independent%20five-year%20paths%0A%20%20%20%20share%20those%20parameters.%20A%20fixed%20seed%20keeps%20the%20same%20innovations%20when%20a%0A%20%20%20%20slider%20changes%2C%20so%20it%20is%20easier%20to%20see%20a%20parameter's%20effect.%0A%0A%20%20%20%20**One%20observed%20data%20set%20is%20one%20path's%20ordered%20return%20history.**%20The%20eight%0A%20%20%20%20paths%20below%20are%20eight%20possible%20histories%2C%20not%20paths%20averaged%20into%20one%20price%0A%20%20%20%20observation.%20Each%20training%20pair%20uses%20just%20one%20such%20history.%0A%0A%20%20%20%20The%20purple%20path%20is%20shown%20as%20daily%20returns%20and%2021-day%20realized%20volatility%0A%20%20%20%20on%20the%20right.%20Realized%20volatility%20is%20a%20summary%20of%20those%20returns%2C%20not%20the%0A%20%20%20%20hidden%20instantaneous%20variance.%20This%20panel%20is%20a%20separate%20forward%20example%3B%0A%20%20%20%20the%20posterior%20sections%20retain%20the%20selected%20supplied%20history.%0A%20%20%20%20%22%22%22)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20mo%2C%20parameter_labels)%3A%0A%20%20%20%20_defaults%20%3D%20%7B%22hurst%22%3A%20.10%2C%20%22eta%22%3A%201.5%2C%20%22rho%22%3A%20-.70%2C%20%22drift%22%3A%20.05%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22kappa%22%3A%202.%2C%20%22long_variance%22%3A%20.04%2C%20%22vol_of_vol%22%3A%20.30%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22short_variance%22%3A%20.04%2C%20%22decay%22%3A%202.%7D%0A%20%20%20%20_steps%20%3D%20%7B%22hurst%22%3A%20.01%2C%20%22eta%22%3A%20.05%2C%20%22rho%22%3A%20.01%2C%20%22drift%22%3A%20.01%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22kappa%22%3A%20.05%2C%20%22long_variance%22%3A%20.001%2C%20%22vol_of_vol%22%3A%20.01%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22short_variance%22%3A%20.001%2C%20%22decay%22%3A%20.05%7D%0A%20%20%20%20simulator_controls%20%3D%20mo.ui.dictionary(%7B%0A%20%20%20%20%20%20%20%20_name%3A%20mo.ui.slider(_bounds%5B0%5D%2C%20_bounds%5B1%5D%2C%20step%3D_steps%5B_name%5D%2C%20value%3D_defaults%5B_name%5D%2C%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%20label%3Dparameter_labels%5B_name%5D%2C%20show_value%3DTrue%2C%20debounce%3DTrue)%0A%20%20%20%20%20%20%20%20for%20_name%2C%20_bounds%20in%20zip(cache_task%5B%22parameter_names%22%5D%2C%20cache_task%5B%22prior_bounds%22%5D%2C%20strict%3DTrue)%7D)%0A%20%20%20%20_curve_names%20%3D%20%7B%22short_variance%22%2C%20%22long_variance%22%2C%20%22decay%22%7D%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22rough-joint%22%20else%20set()%0A%20%20%20%20_main%20%3D%20%5B_name%20for%20_name%20in%20cache_task%5B%22parameter_names%22%5D%20if%20_name%20not%20in%20_curve_names%5D%0A%20%20%20%20_panels%20%3D%20%5Bmo.hstack(%5Bsimulator_controls%5B_name%5D%20for%20_name%20in%20_main%5B_i%3A_i%20%2B%202%5D%5D%2C%20justify%3D%22start%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_i%20in%20range(0%2C%20len(_main)%2C%202)%5D%0A%20%20%20%20if%20_curve_names%3A%0A%20%20%20%20%20%20%20%20_panels.append(mo.accordion(%7B%22Set%20the%20variance-curve%20coefficients%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20simulator_controls%5B_name%5D%20for%20_name%20in%20cache_task%5B%22parameter_names%22%5D%20if%20_name%20in%20_curve_names%5D)%7D))%0A%20%20%20%20if%20cache_task%5B%22model%22%5D%20!%3D%20%22heston%22%3A%0A%20%20%20%20%20%20%20%20_panels.append(mo.md(r%22**%CE%B7%20controls%20log-variance%20dispersion%20at%20a%20fixed%20mean.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20r%22Raising%20%CE%B7%20spreads%20the%20distribution%3B%20it%20need%20not%20raise%20a%20particular%20variance%20path.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20r%22The%20compensator%20also%20changes%3A%20%24%5Cpartial_%5Ceta%5Clog%20V%3DY-%5Ceta%20q%24.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20r%22With%20fixed%20random%20inputs%2C%20many%20realized%20values%20can%20fall%20as%20%CE%B7%20rises.%22))%0A%20%20%20%20mo.vstack(_panels)%0A%20%20%20%20return%20(simulator_controls%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20trajectory)%3A%0A%20%20%20%20simulator_scale%20%3D%20mo.ui.dropdown(options%3Dlist(trajectory.SIMULATOR_SCALES)%2C%20value%3D%22Standard%22%2C%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%20%20%20%20%20%20%20%20%20%20label%3D%22Fixed%20simulator%20axes%22)%0A%20%20%20%20simulator_view%20%3D%20mo.ui.radio(options%3D%5B%22Explore%20one%20setting%22%2C%20%22Compare%20three%20settings%22%5D%2C%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%20%20%20%20%20%20value%3D%22Explore%20one%20setting%22%2C%20inline%3DTrue%2C%20label%3D%22Simulator%20view%22)%0A%20%20%20%20simulator_refresh%20%3D%20mo.ui.button(value%3D0%2C%20on_click%3Dlambda%20value%3A%20value%20%2B%201%2C%20label%3D%22New%20realizations%22)%0A%20%20%20%20mo.vstack(%5Bsimulator_view%2C%20mo.hstack(%5Bsimulator_scale%2C%20simulator_refresh%5D%2C%20justify%3D%22start%22)%2C%20mo.md(%0A%20%20%20%20%20%20%20%20%22The%20axis%20limits%20stay%20fixed%20when%20model%20parameters%20change.%20Choose%20a%20wider%20preset%20yourself.%20%22%0A%20%20%20%20%20%20%20%20%22All%20simulated%20points%20remain%20in%20the%20data%3B%20counts%20on%20each%20panel%20report%20points%20outside%20the%20view.%20%22%0A%20%20%20%20%20%20%20%20%22New%20realizations%20refreshes%20the%20random%20inputs%20for%20every%20setting%20together.%22)%5D)%0A%20%20%20%20return%20simulator_refresh%2C%20simulator_scale%2C%20simulator_view%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20mo%2C%20parameter_labels%2C%20simulator_view)%3A%0A%20%20%20%20_choices%20%3D%20%5B%22vol_of_vol%22%2C%20%22kappa%22%5D%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%20else%20%5B%22hurst%22%2C%20%22eta%22%5D%0A%20%20%20%20simulator_compare%20%3D%20mo.ui.dropdown(options%3D%7Bparameter_labels%5Bname%5D%3A%20name%20for%20name%20in%20_choices%7D%2C%0A%20%20%20%20%20%20%20%20value%3Dparameter_labels%5B_choices%5B0%5D%5D%2C%20label%3D%22Parameter%20to%20compare%22)%0A%20%20%20%20simulator_compare%20if%20simulator_view.value%20%3D%3D%20%22Compare%20three%20settings%22%20else%20mo.md(%22%22)%0A%20%20%20%20return%20(simulator_compare%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20cache_task%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20simulator_compare%2C%0A%20%20%20%20simulator_controls%2C%0A%20%20%20%20simulator_refresh%2C%0A%20%20%20%20simulator_scale%2C%0A%20%20%20%20simulator_view%2C%0A%20%20%20%20trajectory%2C%0A)%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20_seed%20%3D%2020261108%20%2B%20simulator_refresh.value%0A%20%20%20%20%20%20%20%20simulation_preview%20%3D%20None%0A%20%20%20%20%20%20%20%20_limits%20%3D%20trajectory.SIMULATOR_SCALES%5Bsimulator_scale.value%5D%0A%20%20%20%20%20%20%20%20if%20simulator_view.value%20%3D%3D%20%22Compare%20three%20settings%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_comparison%20%3D%20trajectory.simulator_comparison(cache_task%2C%20simulator_controls.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20simulator_compare.value%2C%20paths%3D4%2C%20days%3D1260%2C%20seed%3D_seed)%0A%20%20%20%20%20%20%20%20%20%20%20%20_display%20%3D%20trajectory.simulator_comparison_figure(_comparison%2C%20scale%3Dsimulator_scale.value)%0A%20%20%20%20%20%20%20%20%20%20%20%20_detail%20%3D%20mo.md(%22**Held%20fixed%3A**%20%22%20%2B%20%22%2C%20%22.join(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bname%7D%20%3D%20%7Bvalue%3Ag%7D%22%20for%20name%2C%20value%20in%20_comparison%5B%22fixed_parameters%22%5D.items())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20f%22.%20Seed%20%7B_seed%7D%3B%20four%20matched%20realizations%20per%20setting.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20selected%20parameter%20slider%20is%20replaced%20by%20the%20three%20displayed%20values.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22One%20realization%20need%20not%20change%20monotonically.%20Change%20the%20random%20inputs%20and%20inspect%20again.%22)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20simulation_preview%20%3D%20trajectory.simulator_preview(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20cache_task%2C%20simulator_controls.value%2C%20paths%3D8%2C%20days%3D1260%2C%20seed%3D_seed)%0A%20%20%20%20%20%20%20%20%20%20%20%20_display%20%3D%20trajectory.forward_simulator_figure(simulation_preview%2C%20scale%3Dsimulator_scale.value)%0A%20%20%20%20%20%20%20%20%20%20%20%20_detail%20%3D%20mo.accordion(%7B%22Exact%20axis%20limits%2C%20outside%20counts%20and%20data%20ranges%22%3A%20mo.ui.table(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20trajectory.simulator_axis_summary(simulation_preview%2C%20simulator_scale.value)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20selection%3DNone%2C%20pagination%3DFalse)%7D)%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20f%22**Fixed%20axes%20(%7Bsimulator_scale.value%7D)%3A**%20asset%20price%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20f%22**%7B_limits%5B'prices'%5D%5B0%5D%3Ag%7D%E2%80%93%7B_limits%5B'prices'%5D%5B1%5D%3Ag%7D**%3B%20daily%20return%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20f%22**%7B_limits%5B'returns'%5D%5B0%5D%3Ag%7D%E2%80%93%7B_limits%5B'returns'%5D%5B1%5D%3Ag%7D%25**%3B%20realized%20volatility%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20f%22**%7B_limits%5B'realized'%5D%5B0%5D%3Ag%7D%E2%80%93%7B_limits%5B'realized'%5D%5B1%5D%3Ag%7D%25**.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20_display%2C%20_detail%0A%20%20%20%20%20%20%20%20%5D)%0A%20%20%20%20except%20(ValueError%2C%20FloatingPointError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20simulation_preview%20%3D%20None%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.callout(mo.md(%22This%20forward%20example%20could%20not%20be%20simulated%3A%20%22%20%2B%20str(_error))%2C%20kind%3D%22warn%22)%0A%20%20%20%20_panel%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_task%2C%20mo)%3A%0A%20%20%20%20_amplitude%20%3D%20%22%CF%83%20(volatility%20of%20variance)%22%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%20else%20%22%CE%B7%20(log-variance%20dispersion)%22%0A%20%20%20%20_memory%20%3D%20%22%CE%BA%22%20if%20cache_task%5B%22model%22%5D%20%3D%3D%20%22heston%22%20else%20%22H%22%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%7C%20Change%20%7C%20Predict%20and%20inspect%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Raise%20%CE%BC%20only%20%7C%20The%20cumulative%20log-return%20paths%20shift%20upward%3B%20variance%20dynamics%20keep%20the%20same%20innovations.%20%7C%0A%20%20%20%20%7C%20Change%20%7B_amplitude%7D%20%7C%20Which%20paths%20develop%20larger%20bursts%3F%20One%20fixed%20realization%20need%20not%20change%20monotonically.%20%7C%0A%20%20%20%20%7C%20Move%20%CF%81%20toward%20zero%20%7C%20Compare%20price%2Fvolatility%20co-movement%3B%20rolling%20realized%20volatility%20is%20a%20return%20summary.%20%7C%0A%20%20%20%20%7C%20Change%20%7B_memory%7D%20%7C%20Compare%20how%20volatility%20patterns%20persist%20or%20roughen%2C%20rather%20than%20reading%20the%20parameter%20from%20one%20price%20path.%20%7C%0A%0A%20%20%20%20Revealing%20more%20observed%20days%20later%20uses%20a%20longer%20prefix%20of%20one%20history.%20Rough%0A%20%20%20%20histories%20retain%20their%20original%20starting%20point%20and%20memory%3B%20they%20are%20not%20restarted%0A%20%20%20%20at%20the%20first%20day%20visible%20on%20a%20plot.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%23%20Forward%20simulation%20at%20chosen%20parameters%3B%20fixed%20seed%20keeps%20innovations%20fixed.%0A%20%20%20%20parameters%20%3D%20simulator_controls.value%0A%20%20%20%20preview%20%3D%20trajectory.simulator_preview(%0A%20%20%20%20%20%20%20%20cache_task%2C%20parameters%2C%20paths%3D8%2C%20days%3D1260%2C%20seed%3D20261108)%0A%20%20%20%20%23%20Plot%20returns%20and%20return-based%20summaries%3B%20no%20posterior%20is%20fitted%20here.%0A%20%20%20%20trajectory.forward_simulator_figure(preview%2C%20scale%3Dsimulator_scale.value)%0A%20%20%20%20%23%20Scale%20selection%20changes%20the%20view%20only%3B%20no%20path%20value%20is%20clipped%20or%20discarded.%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20The%20helper%20calls%20%60simulation.simulate_parameters%60%2C%20which%20uses%20the%20**same%0A%20%20%20%20numerical%20implementation**%20as%20training-pair%20generation.%20Only%20daily%20returns%0A%20%20%20%20leave%20that%20simulator.%20No%20latent%20variance%20is%20supplied%20to%20inference.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20%23%20In-memory%20inputs%20only%2C%20kept%20separate%20for%20every%20complete%20task%20identity.%0A%20%20%20%20diagnostic_panels%20%3D%20%7B%7D%0A%20%20%20%20return%20(diagnostic_panels%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md)%3A%0A%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%202.2%20Prior%20predictive%3A%20could%20this%20model%20generate%20a%20history%20like%20this%3F%0A%0A%20%20%20%20The%20sliders%20hold%20parameters%20fixed.%20A%20**prior-predictive%20check**%20instead%20draws%0A%20%20%20%20parameters%20from%20their%20prior%2C%20then%20simulates%20one%20history%20for%20each%20draw.%20Compare%0A%20%20%20%20200%20histories%20at%20the%20same%20observed%20length%20before%20using%20the%20selected%20posterior.%0A%20%20%20%20Each%20row%20is%20**one%20parameter%20vector%20and%20one%20process%20realization**%2C%20not%20an%0A%20%20%20%20option-price%20average%20over%20many%20paths%3A%0A%0A%20%20%20%20%24%24p(r_%7B1%3AT%7D)%3D%5Cint%20p(r_%7B1%3AT%7D%5Cmid%5CTheta)%5C%2Cp(%5CTheta)%5C%2Cd%5CTheta.%24%24%0A%0A%20%20%20%20By%20default%20compare%20with%20**VOO%20from%202020%2C%20using%20the%20same%20number%20of%20observed%0A%20%20%20%20days**.%20You%20can%20instead%20select%20the%20supplied%20synthetic%20history.%20This%20is%20a%0A%20%20%20%20prior-predictive%20adequacy%20check%20only%3A%20real%20returns%20are%20**not%20sent%20into%20the%0A%20%20%20%20neural%20estimator**%2C%20and%20no%20real-data%20posterior%20is%20inferred%20here.%0A%0A%20%20%20%20**Does%20return%20order%20matter%3F**%20Six%20daily%20log%20returns%2C%20three%20%2B2%25%20and%20three%20%E2%88%923%25%2C%0A%20%20%20%20have%20cumulative%20log%20return%20%E2%88%923%25%2C%20annualized%20RMS%2040.47%25%2C%20and%20maximum%20daily%20size%203%25%0A%20%20%20%20in%20either%20order.%20Yet%20%60%2B%20%2B%20%2B%20%E2%88%92%20%E2%88%92%20%E2%88%92%60%20has%20**8.61%25%20maximum%20drawdown**%2C%20while%0A%20%20%20%20%60%2B%20%E2%88%92%20%2B%20%E2%88%92%20%2B%20%E2%88%92%60%20has%20**4.88%25**.%20Magnitude%20summaries%20miss%20this%20difference.%0A%0A%20%20%20%20The%20default%20view%20connects%20return%20paths%2C%20cumulative%20log%20wealth%20and%20the%20return%0A%20%20%20%20distribution.%20**Timing%20checks**%20compare%20signed%20and%20absolute-return%20dependence.%0A%20%20%20%20A%20constant-variance%20**IID%20Gaussian%20fitted%20to%20this%20observation's%20mean%20and%20SD**%0A%20%20%20%20provides%20a%20descriptive%20control.%20It%20is%20not%20another%20prior-predictive%20model.%0A%20%20%20%20Finite%20Gaussian%20histories%20can%20also%20produce%20large%20moves%20and%20apparent%20clusters%3B%0A%20%20%20%20compare%20their%20frequencies%20rather%20than%20declaring%20those%20observations%20impossible.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20prior_target%20%3D%20mo.ui.radio(options%3D%7B%22VOO%20from%202020%2C%20same%20number%20of%20days%22%3A%20%22market%22%2C%0A%20%20%20%20%20%20%20%20%22Selected%20synthetic%20history%22%3A%20%22synthetic%22%7D%2C%20value%3D%22VOO%20from%202020%2C%20same%20number%20of%20days%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Observation%20for%20the%20prior-predictive%20comparison%22)%0A%20%20%20%20prior_target%0A%20%20%20%20return%20(prior_target%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20prior_target%2C%20selection)%3A%0A%20%20%20%20_selected_history%20%3D%20(selection%2Cprior_target.value)%0A%20%20%20%20prior_check_button%20%3D%20mo.ui.run_button(label%3D%22Simulate%20200%20histories%20from%20the%20prior%22)%0A%20%20%20%20mo.accordion(%7B%22Optional%3A%20run%20the%20prior-predictive%20comparison%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20prior_check_button%2C%0A%20%20%20%20%20%20%20%20mo.md(%22Generate%20one%20history%20per%20parameter%20draw.%20The%20same%20complete%20histories%20are%20reused%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22when%20changing%20the%20observed%20prefix%3B%20no%20inference%20or%20training%20runs%20here.%22)%2C%0A%20%20%20%20%5D)%7D)%0A%20%20%20%20return%20(prior_check_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20diagnostic_panels%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_checks%2C%0A%20%20%20%20path_checks%2C%0A%20%20%20%20path_simulation%2C%0A%20%20%20%20prior_check_button%2C%0A%20%20%20%20prior_target%2C%0A%20%20%20%20requested_days%2C%0A%20%20%20%20trajectory%2C%0A)%3A%0A%20%20%20%20prior_predictive_result%20%3D%20None%0A%20%20%20%20_status%20%3D%20None%0A%20%20%20%20if%20prior_check_button.value%3A%0A%20%20%20%20%20%20%20%20_key%20%3D%20path_simulation.task_fingerprint(cache_task)%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20_key%20not%20in%20diagnostic_panels%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20diagnostic_panels%5B_key%5D%20%3D%20path_checks.generate_panel(cache_task%2C%20count%3D200%2C%20seed%3D20261111)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20prior_target.value%20%3D%3D%20%22market%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_market%20%3D%20trajectory.load_market_example(%22voo-2020-20261113%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_observation%20%3D%20_market%5B%22log_returns%22%5D%5B%3Arequested_days%2C%20None%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_label%20%3D%20f%22VOO%20%C2%B7%20%7B_market%5B'dates'%5D%5B0%5D%7D%20to%20%7B_market%5B'dates'%5D%5Brequested_days-1%5D%7D%20%C2%B7%20%7Brequested_days%7D%20trading%20days%22%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_observation%20%3D%20active_history%5B%22returns%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_label%20%3D%20f%22Selected%20synthetic%20history%20%C2%B7%20%7Brequested_days%7D%20trading%20days%22%0A%20%20%20%20%20%20%20%20%20%20%20%20prior_predictive_result%20%3D%20model_checks.compare_prior(cache_task%2C%20diagnostic_panels%5B_key%5D%2C%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_observation%2C%20requested_days)%0A%20%20%20%20%20%20%20%20%20%20%20%20prior_predictive_result%5B%22comparison_observation%22%5D%20%3D%20_label%0A%20%20%20%20%20%20%20%20except%20(OSError%2C%20KeyError%2C%20ValueError%2C%20RuntimeError%2C%20FloatingPointError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_status%20%3D%20mo.callout(mo.md(f%22**Prior%20check%20stopped%3A**%20%7B_error%7D.%20No%20histories%20are%20replaced%20or%20filtered.%22)%2C%20kind%3D%22warn%22)%0A%20%20%20%20_status%0A%20%20%20%20return%20(prior_predictive_result%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20model_checks%2C%20predictive_visuals%2C%20prior_predictive_result)%3A%0A%20%20%20%20if%20prior_predictive_result%20is%20None%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_comparison%20%3D%20predictive_visuals.compare(prior_predictive_result)%0A%20%20%20%20%20%20%20%20_control%20%3D%20(%22Brown%20is%20a%20separate%20200-history%20IID%20Gaussian%20control%20fitted%20to%20the%20observed%20prefix.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22It%20matches%20its%20mean%20and%20variance%20by%20construction%3B%20tails%20and%20timing%20can%20still%20differ.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_comparison%5B%22metadata%22%5D%5B%22gaussian_available%22%5D%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20fitted%20Gaussian%20control%20is%20unavailable%20for%20fewer%20than%20two%20varying%20observations%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model%20histories%20are%20still%20shown.%20%22)%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%22Paths%20and%20distributions%22%3A%20predictive_visuals.paths_and_distributions(_comparison)%2C%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%22Summary%20checks%22%3A%20model_checks.plot_check(prior_predictive_result)%2C%7D)%5D)%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%23%20%22Timing%20checks%22%3A%20predictive_visuals.timing(prior_predictive_result%2C_comparison%2Cshow_shuffle%3Dordering_shuffle.value)%7D)%2C%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.ui.table(predictive_visuals.feature_rows(_comparison)%2Cselection%3DNone%2Cpagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(f%22**Observation%3A%20%7Bprior_predictive_result%5B'comparison_observation'%5D%7D.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20f%22Prior%20simulations%3A%20%7Bprior_predictive_result%5B'length'%5D%7D%20days%20each%20%C2%B7%20200%20histories.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22Blue%20bands%20are%20pointwise%20central%2090%25%20ranges%2C%20computed%20from%20all%20model%20histories.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%2B%20_control%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22The%20return%20and%20cumulative-log-wealth%20views%20have%20fixed%20limits%3B%20crosses%20report%20values%20outside%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22the%20view%20without%20removing%20them.%20Distribution%20bins%20use%20all%20days%20in%20their%20denominators.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22Zero%20tail%20frequency%20remains%20visible%20and%20means%20no%20exceedance%20in%20this%20finite%20history.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22These%20are%20descriptive%20comparisons%2C%20not%20joint-support%20or%20calibrated%20rejection%20tests.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22Undefined%20short%2Fconstant-series%20dependence%20remains%20explicit.%22)%2C%0A%20%20%20%20%20%20%20%20%23%20%5D)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5Blesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%202.3%20Why%20not%20just%20fit%20this%20model%20in%20PyMC%3F%0A%0A%20%20%20%20**Rough%20Bergomi%20makes%20this%20a%20hidden-path%20problem.**%20Its%20Volterra%20kernel%0A%20%20%20%20makes%20variance%20depend%20on%20earlier%20innovations%2C%20with%20weights%20that%20change%0A%20%20%20%20with%20H.%20In%20the%20five-year%20conditional%20formulation%20below%2C%20roughly%20**10%2C000%0A%20%20%20%20latent%20variance-driver%20and%20bridge%20coordinates**%20remain%20after%20integrating%0A%20%20%20%20out%20the%20independent%20price%20shocks.%20We%20must%20account%20for%20those%20hidden%0A%20%20%20%20histories%20alongside%20the%20four%20or%20seven%20fixed%20parameters.%0A%0A%20%20%20%20**PyMC%20can%20fit%20stochastic-volatility%20models.**%20The%20challenge%20here%20is%0A%20%20%20%20constructing%20and%20sampling%20the%20joint%20parameter%E2%80%93path%20target%2C%20or%20integrating%0A%20%20%20%20the%20hidden%20paths%20with%20a%20suitable%20specialized%20method.%0A%0A%20%20%20%20%7C%20Route%20%7C%20What%20has%20to%20be%20computed%3F%20%7C%20Where%20does%20the%20cost%20occur%3F%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Latent-path%20MCMC%20%7C%20Infer%20parameters%20together%20with%20hidden%20driving%20shocks%2C%20or%20integrate%2Ffilter%20those%20shocks%20using%20a%20specialized%20method%20%7C%20Repeated%20likelihood%20or%20latent-path%20work%20for%20each%20observed%20dataset%20%7C%0A%20%20%20%20%7C%20Our%20BayesFlow%20estimator%20%7C%20Learn%20parameters%20from%20many%20simulated%20parameter%E2%80%93return%20pairs%2C%20with%20hidden%20paths%20averaged%20over%20by%20simulation%20%7C%20Upfront%20simulation%20and%20training%3B%20later%20conditional%20sampling%20is%20reusable%20%7C%0A%0A%20%20%20%20For%20one%20dataset%20a%20carefully%20built%20MCMC%20analysis%20may%20be%20the%20better%20choice.%0A%20%20%20%20Amortization%20is%20attractive%20when%20we%20will%20analyze%20many%20histories%20or%20many%0A%20%20%20%20prefixes%20under%20the%20**same%20simulation%20design%20and%20prior**.%20Its%20price%20is%20an%0A%20%20%20%20approximate%20learned%20posterior%20that%20needs%20the%20checks%20below.%20We%20have%20not%0A%20%20%20%20benchmarked%20PyMC%20against%20these%20networks%2C%20and%20training%20is%20not%20free.%0A%20%20%20%20%22%22%22)%2C%20mo.accordion(%7B%22Where%20the%20likelihood%20and%20PyMC%20implementation%20become%20harder%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20For%20our%20discretized%20rough%20Bergomi%20task%2C%20a%20likelihood%20is%20available%0A%20%20%20%20**conditional%20on%20the%20latent%20Gaussian%20innovations**.%0A%20%20%20%20Let%20%24U%24%20contain%20the%20variance-driving%20and%20hybrid-bridge%20shocks.%20For%20one%0A%20%20%20%20observed%20day%2C%20summing%20its%20fine%20steps%20gives%0A%0A%20%20%20%20%24%24%0A%20%20%20%20I_t%3D%5Csum_%7Bj%5Cin%20t%7D%20V_j%20h%2C%5Cqquad%0A%20%20%20%20J_t%3D%5Csum_%7Bj%5Cin%20t%7D%5Csqrt%7BV_jh%7D%5C%2CZ_%7BW%2Cj%7D.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20r_t%5Cmid%5CTheta%2CU%5Csim%5Cmathcal%7BN%7D%5C!%5Cleft(%0A%20%20%20%20%20%20%5Cmu%5CDelta-%5Cfrac%7B1%7D%7B2%7DI_t%2B%5Crho%20J_t%2C%5C%20(1-%5Crho%5E2)I_t%5Cright).%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20Normal's%20second%20argument%20is%20its%20variance.%20The%20independent%20asset-shock%0A%20%20%20%20channel%20has%20been%20integrated%20out.%20The%20parameter%20posterior%20still%20contains%0A%20%20%20%20a%20latent-variable%20integral%3A%0A%0A%20%20%20%20%24%24p(%5CTheta%5Cmid%20r_%7B1%3AT%7D)%5Cpropto%20p(%5CTheta)%0A%20%20%20%20%20%20%5Cint%20%5Cleft%5B%5Cprod_%7Bt%3D1%7D%5ET%20p(r_t%5Cmid%5CTheta%2CU)%5Cright%5D%5Cphi(U)%5C%2CdU.%24%24%0A%0A%20%20%20%20Here%20%24%5Cphi(U)%24%20is%20the%20standard%20Gaussian%20density%20of%20all%20the%20independent%0A%20%20%20%20volatility-driving%20and%20bridge%20shocks.%20There%20are%20two%20conventional%20routes%3A%0A%0A%20%20%20%20-%20**Augment%20the%20target%3A**%20sample%20%24%5CTheta%2CU%24%20together.%20Each%20log%20density%20is%0A%20%20%20%20%20%20deterministic%20and%20computable%3B%20NUTS%20does%20not%20have%20to%20evaluate%20the%20integral%0A%20%20%20%20%20%20inside%20every%20step.%20It%20must%20explore%20the%20much%20larger%20joint%20posterior%20and%0A%20%20%20%20%20%20differentiate%20the%20variance%20construction%20as%20H%20and%20the%20shocks%20change.%0A%20%20%20%20-%20**Marginalize%20the%20shocks%3A**%20evaluate%20or%20estimate%20the%20integral%20for%20each%0A%20%20%20%20%20%20proposed%20%24%5CTheta%24%2C%20using%20a%20suitable%20integration%20or%20filtering%20method.%0A%20%20%20%20%20%20Rough%20memory%20and%20long%20histories%20make%20that%20integration%20demanding%20too.%0A%0A%20%20%20%20Five%20years%20%C3%97%20252%20days%20%C3%97%20four%20fine%20steps%20%C3%97%20two%20Gaussian%20driving%20channels%0A%20%20%20%20gives%20roughly%20**10%2C000%20latent%20coordinates**%20in%20a%20direct%20augmented%20model.%0A%20%20%20%20The%20H-dependent%20memory%20kernel%20couples%20these%20to%20the%20whole%20variance%20history.%0A%0A%20%20%20%20A%20PyMC%2FNUTS%20implementation%20would%20need%20a%20deterministic%20differentiable%20log%0A%20%20%20%20density%2C%20validated%20gradients%20and%20a%20parameterization%20that%20samples%20well.%0A%20%20%20%20Our%20NumPy%2FFFT%20forward%20simulator%20is%20not%20automatically%20that%20PyTensor%20model.%0A%20%20%20%20Drawing%20fresh%20simulator%20randomness%20on%20every%20ordinary%20NUTS%20likelihood%20call%0A%20%20%20%20does%20not%20create%20a%20valid%20deterministic%20target.%20Particle%20and%20pseudo-marginal%0A%20%20%20%20approaches%20are%20alternatives%20with%20their%20own%20requirements.%0A%0A%20%20%20%20See%20PyMC's%20%5Bstochastic-volatility%20example%5D(https%3A%2F%2Fwww.pymc.io%2Fprojects%2Fexamples%2Fen%2Flatest%2Ftime_series%2Fstochastic_volatility.html)%0A%20%20%20%20and%20%5Bexternal-likelihood%20guide%5D(https%3A%2F%2Fwww.pymc.io%2Fprojects%2Fexamples%2Fen%2Flatest%2Fhowto%2Fblackbox_external_likelihood_numpy.html).%0A%20%20%20%20These%20explain%20feasible%20routes%3B%20they%20are%20not%20a%20matched%20performance%20comparison%0A%20%20%20%20with%20the%20Bergomi%20task%20shown%20here.%0A%20%20%20%20%22%22%22)%7D)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20lesson_section%2C%20mo%2C%20trajectory)%3A%0A%20%20%20%20_figure%20%3D%20trajectory.ASSETS%20%2F%20%22illustrations%22%20%2F%20%22application-workflows-20261101%22%20%2F%20%22trajectory-prefix-workflow.png%22%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_section(%22Train%22%2C%20%22Train%20a%20compact%20posterior%20estimator%20on%20simulated%20parameter%E2%80%93history%20pairs.%22%2C%20stage%3D3)%2C%20mo.md(%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22**One%20training%20pair%3A%20parameters%20drawn%20from%20the%20prior%20and%20the%20daily%20returns%20they%20generate.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Only%20returns%20enter%20the%20estimator.%20Generating%20parameters%20are%20training%20labels%3B%20latent%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22variance%20and%20shocks%20stay%20inside%20the%20simulator.%22)%2C%0A%20%20%20%20%20%20%20%20mo.image(_figure)%20if%20_figure.is_file()%20else%20mo.md(%22%22)%2C%0A%20%20%20%20%20%20%20%20lesson_md(f%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%203.1%20Generate%20parameter%E2%80%93history%20pairs%0A%0A%20%20%20%20%20%20%20%20%60%60%60python%0A%20%20%20%20%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20simulation%2C%20inference%0A%0A%20%20%20%20%20%20%20%20%23%20A%20physical-measure%20return%20model%3B%20process%20randomness%20needs%20no%20extra%20quote%20noise.%0A%20%20%20%20%20%20%20%20task%20%3D%20simulation.teaching_task(%22rough-known%22%2C%20observations%3D1260)%0A%20%20%20%20%20%20%20%20pairs%20%3D%20simulation.generate(%0A%20%20%20%20%20%20%20%20%20%20%20%20task%2C%20%22train%22%2C%20start%3D0%2C%20count%3D128%2C%20seed%3D20261107%2C%20backend%3D%22numpy%22)%0A%20%20%20%20%20%20%20%20%23%20A%20fresh%2C%20independent%20history%20is%20used%20only%20after%20training.%0A%20%20%20%20%20%20%20%20example%20%3D%20simulation.generate(%0A%20%20%20%20%20%20%20%20%20%20%20%20task%2C%20%22validation%22%2C%20start%3D0%2C%20count%3D1%2C%20seed%3D20261108%2C%20backend%3D%22numpy%22)%0A%20%20%20%20%20%20%20%20%23%20128%20training%20histories%2C%20each%20with%201%2C260%20daily%20returns%20(five%20years)%0A%20%20%20%20%20%20%20%20%23%20One%20independently%20generated%20history%20for%20the%20inference%20example%0A%20%20%20%20%20%20%20%20%60%60%60%0A%0A%20%20%20%20%20%20%20%20The%20simulator%20samples%20both%20parameters%20and%20process%20innovations.%20It%20retains%0A%20%20%20%20%20%20%20%20aligned%20parameter%20labels%2C%20daily%20returns%20and%20history%20IDs.%20This%20tutorial%20route%0A%20%20%20%20%20%20%20%20uses%20**rough%20Bergomi%20with%20a%20supplied%20curve**%2C%20five-year%20histories%20and%20drift%0A%20%20%20%20%20%20%20%20inference%2C%20regardless%20of%20the%20model%20selected%20for%20the%20supplied%20examples.%0A%20%20%20%20%20%20%20%20The%20implementation%20lives%20in%20%60src%2Fsbi4f_tutorial%2Ftrajectories%2F%60.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20mo%2C%20trajectory)%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20simulation%20as%20_input_simulation%0A%20%20%20%20_task%20%3D%20_input_simulation.teaching_task(%22rough-known%22%2C%20observations%3D1260)%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_md(%22%23%23%23%203.2%20From%20a%20return%20sequence%20to%20network%20inputs%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20tutorial%20and%20supplied%20models%20both%20use%20a%201%2C260-day%20maximum%20(five%20trading%20years).%20Each%20observed%20day%20becomes%20a%20scaled%20return%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22and%20a%20known%20time%20coordinate.%20Padding%20gets%20a%20false%20mask%3B%20a%20genuine%20zero%20return%20remains%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22observed.%20Generating%20parameter%20labels%20follow%20a%20separate%20training%20route.%22)%2C%0A%20%20%20%20%20%20%20%20trajectory.input_concept_figure(_task)%2C%0A%20%20%20%20%20%20%20%20mo.md(%22The%20query%20supplies%20the%20upper%20route%20only.%20%60training_data%60%20also%20transforms%20the%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22parameter%20labels%20for%20density%20scoring%20during%20training.%20Both%20models%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22use%20the%20same%20input%20format%20and%20daily%20time%20step.%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(trajectory)%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20simulation%20as%20_architecture_simulation%0A%20%20%20%20_task%20%3D%20_architecture_simulation.teaching_task(%22rough-known%22%2C%20observations%3D1260)%0A%20%20%20%20trajectory.architecture_figure(_task%2C%20network%3Dtrajectory.TUTORIAL_NETWORK)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md)%3A%0A%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%203.3%20Build%20the%20posterior%20estimator%0A%0A%20%20%20%20**Keep%20the%20order%3B%20ignore%20the%20padding.**%20A%20causal%20GRU%20reads%20returns%20in%20order%0A%20%20%20%20and%20produces%20a%20learned%20summary.%20The%20conditional%20flow%20maps%20that%20summary%20to%20a%0A%20%20%20%20joint%20parameter%20distribution.%20Both%20networks%20train%20together.%0A%0A%20%20%20%20The%20**encoder**%20extracts%20temporal%20features.%20The%20**density%20estimator**%20turns%0A%20%20%20%20the%20summary%20and%20known%20time%20design%20into%20uncertainty%20about%20the%20parameters.%0A%20%20%20%20The%20tutorial%20GRU%20emits%20**16%20learned%20summary%20values**%3B%20the%20supplied%20models%20emit%0A%20%20%20%20**32**.%20The%20flow%20also%20receives%20**two%20separate%20known%20time%20features**%3A%20observed%0A%20%20%20%20length%20%2F%20maximum%20length%20and%20the%20observation%20step%20in%20reference%20daily%20units.%0A%20%20%20%20Summary%20dimensions%20are%20compression%20choices%2C%20not%20parameter%20counts%20or%20guarantees%0A%20%20%20%20of%20sufficient%20statistics.%20A%20feature%20discarded%20by%20the%20summary%20is%20unavailable%0A%20%20%20%20to%20the%20flow%3B%20validation%20must%20check%20the%20resulting%20posteriors.%0A%20%20%20%20A%20spline%20coupling%20block%20transforms%20part%20of%20a%20parameter%20vector%20conditional%0A%20%20%20%20on%20the%20rest%3B%20several%20blocks%20can%20represent%20curved%2C%20dependent%20distributions.%0A%0A%20%20%20%20%7C%20Component%20%7C%20Tutorial%20model%20%7C%20Supplied%20model%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Causal%20GRU%20%7C%2016%20hidden%20units%20%E2%86%92%2016%20summary%20values%20%7C%2064%20hidden%20units%20%E2%86%92%2032%20summary%20values%20%7C%0A%20%20%20%20%7C%20Spline%20coupling%20flow%20%7C%202%20blocks%2C%20subnets%20%5B32%2C%2032%5D%2C%208%20bins%20%7C%206%20blocks%2C%20subnets%20%5B64%2C%2064%5D%2C%208%20bins%20%7C%0A%20%20%20%20%7C%20Training%20data%20%7C%20128%20five-year%20histories%20%7C%20One%20million%20five-year%20histories%20per%20model%20%7C%0A%0A%20%20%20%20**What%20changes%20from%20the%20option%20lessons%3F**%20The%20%60BasicWorkflow%60%20pattern%20stays%3A%0A%20%20%20%20simulate%20pairs%2C%20adapt%20inputs%2C%20fit%2C%20then%20sample.%20The%20observation%20representation%0A%20%20%20%20and%20the%20two%20networks%20change.%0A%0A%20%20%20%20%7C%20Piece%20%7C%20Heston%20%2F%20rough%20option%20examples%20%7C%20This%20return-history%20example%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Observations%20%7C%20Flat%20quote%20vector%20in%20%60inference_conditions%60%20%7C%20Ordered%20returns%20in%20%60summary_variables%60%2C%20with%20an%20observation%20mask%20%7C%0A%20%20%20%20%7C%20Encoder%20%7C%20No%20sequence%20encoder%20in%20the%20displayed%20workflow%20%7C%20Causal%20GRU%20learns%20a%20summary%20of%20the%20observed%20prefix%20%7C%0A%20%20%20%20%7C%20Density%20estimator%20%7C%20%60FlowMatching%60%20in%20the%20displayed%20small%20fit%20%7C%20Spline%20%60CouplingFlow%60%2C%20conditional%20on%20the%20summary%20and%20known%20time%20design%20%7C%0A%20%20%20%20%7C%20Parameter%20bounds%20and%20units%20%7C%20Adapter%20constraints%20and%20fitted%20standardization%20%7C%20Fixed%20return%20units%20and%20prior-CDF%20logits%20in%20%60training_data%60%3B%20%60sample%60%20reverses%20the%20parameter%20transform%20%7C%0A%20%20%20%20%7C%20Additional%20noise%20%7C%20Prescribed%20Gaussian%20quote%20errors%20%7C%20None%3B%20the%20return%20process%20is%20already%20stochastic%20%7C%0A%0A%20%20%20%20**Why%20these%20choices%3F**%0A%0A%20%20%20%20%7C%20Choice%20here%20%7C%20Reason%20%7C%20Other%20choices%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Causal%20GRU%20with%20a%20mask%20%7C%20Return%20order%20and%20observed%20length%20matter%3B%20padding%20is%20not%20data%20%7C%20An%20attention-based%20sequence%20encoder%20would%20require%20its%20own%20training%3B%20a%20permutation-invariant%20quote-set%20encoder%20discards%20order%20%7C%0A%20%20%20%20%7C%20Spline%20%60CouplingFlow%60%20%7C%20Evaluates%20the%20learned%20density%20and%20samples%20through%20finite%20invertible%20blocks%20%7C%20%60FlowMatching%60%20learns%20a%20velocity%20field%20and%20samples%20by%20integration%2C%20as%20in%20the%20option%20fits%20%7C%0A%20%20%20%20%7C%20Fixed%20return%20units%20and%20prior-CDF%20logits%20%7C%20Preserve%20amplitude%20information%20and%20the%20declared%20prior%20support%20%7C%20A%20learned%20preprocessing%20transform%20is%20a%20new%20training%20choice%2C%20not%20a%20change%20to%20apply%20to%20existing%20weights%20%7C%0A%20%20%20%20%7C%20Random%20observed%20prefixes%20%7C%20Reuse%20one%20estimator%20across%20lengths%20within%20its%20exact%20model%2C%20prior%20and%20daily%20design%20%7C%20A%20different%20prior%2C%20observation%20law%20or%20initialization%20needs%20a%20new%20estimator%20%7C%0A%0A%20%20%20%20The%20adapter%20below%20routes%20arrays.%20It%20receives%20the%20already%20transformed%20targets%0A%20%20%20%20and%20scaled%20return%20tokens%3B%20it%20does%20not%20fit%20another%20standardizer.%20This%20is%20the%0A%20%20%20%20construction%20inside%20%60inference.build_workflow(task%2C%20network%3Dtrajectory.TUTORIAL_NETWORK)%60%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20import%20bayesflow%20as%20bf%0A%0A%20%20%20%20%23%20Preprocessing%20has%20already%20scaled%20returns%20and%20transformed%20bounded%20parameters.%0A%20%20%20%20%23%20Route%20the%20ordered%20history%20to%20a%20summary%2C%20and%20known%20times%20to%20the%20density.%0A%20%20%20%20adapter%20%3D%20(bf.Adapter().convert_dtype(%22float64%22%2C%20%22float32%22)%0A%20%20%20%20%20%20%20%20.rename(%22parameters%22%2C%20%22inference_variables%22)%0A%20%20%20%20%20%20%20%20.rename(%22observations%22%2C%20%22summary_variables%22)%0A%20%20%20%20%20%20%20%20.rename(%22time_context%22%2C%20%22inference_conditions%22))%0A%20%20%20%20%23%20The%20encoder%20reads%20observed%20returns%20in%20order%3B%20the%20mask%20excludes%20padded%20days.%0A%20%20%20%20summary%20%3D%20bf.networks.RecurrentNetwork(%0A%20%20%20%20%20%20%20%20hidden_dim%3D16%2C%20summary_dim%3D16%2C%20recurrent_type%3D%22gru%22%2C%0A%20%20%20%20%20%20%20%20bidirectional%3DFalse%2C%20time_axis%3D1%2C%20time_embed_dim%3D4%2C%0A%20%20%20%20%20%20%20%20dropout%3D0.0%2C%20return_sequences%3DFalse)%0A%20%20%20%20%23%20This%20spline%20flow%20replaces%20FlowMatching%20in%20the%20displayed%20option%20fits.%0A%20%20%20%20density%20%3D%20bf.networks.CouplingFlow(%0A%20%20%20%20%20%20%20%20depth%3D2%2C%20transform%3D%22spline%22%2C%20subnet_kwargs%3D%7B%22widths%22%3A%20%5B32%2C%2032%5D%7D%2C%0A%20%20%20%20%20%20%20%20transform_kwargs%3D%7B%22bins%22%3A%208%7D)%0A%20%20%20%20%23%20BasicWorkflow%20is%20unchanged%3B%20now%20it%20trains%20the%20summary%20and%20density%20together.%0A%20%20%20%20workflow%20%3D%20bf.BasicWorkflow(%0A%20%20%20%20%20%20%20%20adapter%3Dadapter%2C%20summary_network%3Dsummary%2C%0A%20%20%20%20%20%20%20%20inference_network%3Ddensity%2C%20standardize%3DNone)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60training_data%60%20scales%20returns%20in%20fixed%20units%2C%20adds%20known%20time%20coordinates%0A%20%20%20%20and%20a%20boolean%20mask%2C%20and%20transforms%20parameter%20labels%20to%20unbounded%20coordinates.%0A%20%20%20%20The%20GRU%20state%20summarizes%20observations%3B%20it%20is%20not%20a%20fitted%20latent-volatility%20filter.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%203.4%20Train%20on%20different%20amounts%20of%20evidence%0A%0A%20%20%20%20%20%20%20%20**Reveal%20a%20random%20prefix%2C%20then%20mask%20its%20future.**%20This%20teaches%20one%20network%0A%20%20%20%20%20%20%20%20to%20accept%20shorter%20or%20longer%20histories%20without%20treating%20padding%20as%20data.%0A%0A%20%20%20%20%20%20%20%20The%20executing%20function%20below%20prepares%20training%20and%20independent%20validation%0A%20%20%20%20%20%20%20%20histories%2C%20constructs%20the%20GRU%20and%20flow%2C%20fits%20both%20together%2C%20then%20samples%0A%20%20%20%20%20%20%20%20the%20independent%20example.%20Its%20loss%20curves%20use%20%60bf.diagnostics.loss%60.%0A%0A%20%20%20%20%20%20%20%20This%20continues%20the%20simulation%20example%20above.%20Two%20epochs%20on%20128%0A%20%20%20%20%20%20%20%20histories%20make%20**eight%20optimizer%20updates**.%20The%20last%20call%20infers%20parameters%0A%20%20%20%20%20%20%20%20for%20the%20independent%20example%20using%20the%20newly%20trained%20model.%20It%20illustrates%0A%20%20%20%20%20%20%20%20the%20workflow%3B%20no%20accuracy%20or%20calibration%20result%20is%20established.%0A%20%20%20%20%20%20%20%20The%2064%20validation%20histories%20score%20the%20fit%20but%20do%20not%20update%20its%20weights.%20Two%20epochs%20cannot%20establish%20convergence%20or%20calibrated%20uncertainty.%20No%20training%20starts%20on%20opening%20the%20notebook.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.accordion(%7B%22Training%20target%20and%20full-scale%20reproduction%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(r%22The%20target%20integrates%20out%20hidden%20paths%20z%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20r%22%24p(%5CTheta%5Cmid%20r_%7B1%3AT%7D)%5Cpropto%20p(%5CTheta)%5Cint%20p(r_%7B1%3AT%7D%2Cz%5Cmid%5CTheta)dz%24.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Training%20minimizes%20negative%20log%20density%20of%20transformed%20generating%20parameters%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22conditional%20on%20the%20summary%20and%20time%20design.%20Labels%20never%20enter%20inference%20conditions.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22The%20supplied%20fits%20use%20one%20million%20independent%20training%20histories%20per%20model%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22with%20independent%20validation%2Ftest%20histories%2C%20a%2064-unit%20GRU%2C%20a%2032-value%20summary%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22and%20six%20spline%20coupling%20layers.%20Generation%20precedes%20training.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22A%20streamed%20runner%20reads%20bounded%20shards%2C%20with%20a%20small%20cache.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20fits%20completed%20five%20epochs%3B%20exact%20reproduction%20also%20requires%20their%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22recorded%20seeds%2C%20optimizer%20and%20checkpoint%20selection.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(r%22%22%22%60%60%60bash%0A%20%20%20%20%23%20From%20lab%2F%2C%20with%20the%20matching%20native%20bank.%0A%20%20%20%20python%20scripts%2Ftrain_path_posterior.py%20%5C%0A%20%20%20%20%20%20%20%20--bank%20%2Fpath%2Fto%2Fnative-bank%20--out%20%2Fpath%2Fto%2Fnew-run%20%5C%0A%20%20%20%20%20%20%20%20--streaming%20--training-limit%201000000%20--cache-shards%202%20%5C%0A%20%20%20%20%20%20%20%20--prefix-policy%20uniform_log_mixture%20--epochs%205%20--batch-size%20128%0A%20%20%20%20%60%60%60%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22The%20prefix%20policy%20mixes%20uniform%20integer%20lengths%20with%20more%20exposure%20to%20short%20histories.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Every%20integer%20length%20is%20possible%3B%20the%20prior%20and%20process%20law%20stay%20unchanged.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Supporting%20a%20length%20does%20not%20establish%20calibration%20at%20that%20length.%22)%2C%0A%20%20%20%20%20%20%20%20%5D)%7D)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md)%3A%0A%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%203.5%20Run%20the%20tutorial%20training%20route%0A%0A%20%20%20%20The%20button%20executes%20the%20simulation%2C%20network%2C%20training%20and%20sampling%20steps%0A%20%20%20%20above.%20It%20creates%20a%20**new%20five-year%20rough%20Bergomi%20model**.%20Its%20loss%20and%0A%20%20%20%20posterior%20summary%20appear%20here%2C%20separately%20from%20the%20supplied%20model%20below.%0A%0A%20%20%20%20The%20button%20runs%20these%20steps%20on%20the%20CPU%2C%20keeps%20results%20only%20in%20this%20session%2C%0A%20%20%20%20and%20reports%20generation%2C%20model-building%2Ftraining%20and%20sampling%20time%20separately.%0A%20%20%20%20First%20use%20includes%20backend%20imports%20and%20compilation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20train_demo_button%20%3D%20mo.ui.run_button(label%3D%22Train%20the%20tutorial%20model%20and%20infer%20its%20example%22)%0A%20%20%20%20train_demo_button%0A%20%20%20%20return%20(train_demo_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20path_simulation%2C%20trajectory)%3A%0A%20%20%20%20def%20train_tutorial_model()%3A%0A%20%20%20%20%20%20%20%20import%20time%0A%20%20%20%20%20%20%20%20import%20bayesflow%20as%20bf%0A%20%20%20%20%20%20%20%20import%20keras%0A%20%20%20%20%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20inference%0A%0A%20%20%20%20%20%20%20%20started%20%3D%20time.perf_counter()%0A%20%20%20%20%20%20%20%20task%20%3D%20path_simulation.teaching_task(%22rough-known%22%2C%20observations%3D1260)%0A%20%20%20%20%20%20%20%20%23%20Three%20independent%20random%20streams%3A%20fitting%2C%20validation%20loss%2C%20and%20the%20example.%0A%20%20%20%20%20%20%20%20pairs%20%3D%20path_simulation.generate(task%2C%20%22train%22%2C%200%2C%20128%2C%20seed%3D20261107%2C%20backend%3D%22numpy%22)%0A%20%20%20%20%20%20%20%20validation%20%3D%20path_simulation.generate(task%2C%20%22validation%22%2C%200%2C%2064%2C%20seed%3D20261112%2C%20backend%3D%22numpy%22)%0A%20%20%20%20%20%20%20%20example%20%3D%20path_simulation.generate(task%2C%20%22validation%22%2C%200%2C%201%2C%20seed%3D20261108%2C%20backend%3D%22numpy%22)%0A%20%20%20%20%20%20%20%20generated%20%3D%20time.perf_counter()%0A%20%20%20%20%20%20%20%20%23%20Fixed%20units%2C%20bounded-label%20transforms%2C%20time%20tokens%20and%20masks%20are%20shared%20with%20inference.%0A%20%20%20%20%20%20%20%20train%20%3D%20inference.training_data(pairs%2C%20task)%0A%20%20%20%20%20%20%20%20validate%20%3D%20inference.training_data(validation%2C%20task)%0A%20%20%20%20%20%20%20%20keras.utils.set_random_seed(20261107)%0A%20%20%20%20%20%20%20%20workflow%20%3D%20inference.build_workflow(task%2C%20network%3Dtrajectory.TUTORIAL_NETWORK)%0A%20%20%20%20%20%20%20%20prefixes%20%3D%20inference.random_prefixes(task%2C%20seed%3D20261109%2C%20policy%3D%22uniform_log_mixture%22)%0A%20%20%20%20%20%20%20%20%23%20The%20same%20offline%20API%20as%20SPX%3B%20jointly%20train%20summary%20and%20density%20for%20eight%20updates.%0A%20%20%20%20%20%20%20%20history%20%3D%20workflow.fit_offline(data%3Dtrain%2C%20validation_data%3Dvalidate%2C%20epochs%3D2%2C%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%20%20%20%20%20%20%20%20%20%20%20%20batch_size%3D32%2C%20augmentations%3Dprefixes%2C%20verbose%3D0)%0A%20%20%20%20%20%20%20%20fitted%20%3D%20time.perf_counter()%0A%20%20%20%20%20%20%20%20draws%20%3D%20inference.sample(workflow%2C%20task%2C%20example%5B%22observations%22%5D%2C%20draws%3D128%2C%20seed%3D20261110)%5B0%5D%0A%20%20%20%20%20%20%20%20sampled%20%3D%20time.perf_counter()%0A%20%20%20%20%20%20%20%20return%20task%2C%20workflow%2C%20draws%2C%20bf.diagnostics.loss(history%2C%20smoothing_factor%3D0%2C%20figsize%3D(8%2C%203))%2C%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22generation%22%3A%20generated-started%2C%20%22fit%22%3A%20fitted-generated%2C%20%22sampling%22%3A%20sampled-fitted%7D%0A%0A%20%20%20%20mo.show_code()%0A%20%20%20%20return%20(train_tutorial_model%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20mo%2C%0A%20%20%20%20path_simulation%2C%0A%20%20%20%20train_demo_button%2C%0A%20%20%20%20train_tutorial_model%2C%0A%20%20%20%20trajectory%2C%0A)%3A%0A%20%20%20%20tutorial_task%20%3D%20path_simulation.teaching_task(%22rough-known%22%2C%20observations%3D1260)%0A%20%20%20%20tutorial_workflow%20%3D%20None%0A%20%20%20%20_output%20%3D%20mo.md(%22The%20training%20example%20is%20idle%20until%20requested.%22)%0A%20%20%20%20if%20train_demo_button.value%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20tutorial_task%2C%20tutorial_workflow%2C%20_draws%2C%20_loss%2C%20_timing%20%3D%20train_tutorial_model()%0A%20%20%20%20%20%20%20%20%20%20%20%20_output%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22**Source%3A%20newly%20trained%20tutorial%20model%20%C2%B7%20eight%20optimizer%20updates.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22Generation%20(128%20train%2C%2064%20validation%20and%20one%20example)%3A%20**%7B_timing%5B'generation'%5D%3A.2f%7D%20s**%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22model%20construction%20and%20fitting%3A%20**%7B_timing%5B'fit'%5D%3A.2f%7D%20s**%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22128%20posterior%20draws%3A%20**%7B_timing%5B'sampling'%5D%3A.2f%7D%20s**.%20Imports%20precede%20these%20timers.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_loss%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22Training%20loss%20scores%20the%20fitting%20histories%3B%20validation%20loss%20scores%20independent%20histories.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Validation%20uses%20their%20full%20five-year%20length%20while%20training%20sees%20random%20prefixes%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22so%20a%20loss%20difference%20also%20changes%20the%20distribution%20of%20conditioning%20lengths.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Two%20loss%20values%20cannot%20diagnose%20convergence%2C%20overfitting%2C%20information%20preservation%20or%20calibrated%20posteriors.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Use%20the%20independent%20recovery%20and%20rank%20checks%20below.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(trajectory.posterior_rows(tutorial_task%2C%20_draws)%2C%20selection%3DNone%2C%20pagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D)%0A%20%20%20%20%20%20%20%20except%20(ImportError%2C%20OSError%2C%20RuntimeError%2C%20ValueError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20tutorial_workflow%20%3D%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20_output%20%3D%20mo.callout(mo.md(f%22**Tutorial%20fit%20stopped%3A**%20%7B_error%7D.%22)%2C%20kind%3D%22warn%22)%0A%20%20%20%20_output%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_section)%3A%0A%20%20%20%20lesson_section(%22Infer%22%2C%20%22Choose%20an%20observed%20history%2C%20condition%20the%20supplied%20estimator%20on%20its%20returns%2C%20and%20inspect%20parameter%20uncertainty.%22%2C%20stage%3D4)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_arrays%2C%20lesson_md%2C%20mo)%3A%0A%20%20%20%20history_source%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20%7B%22Supplied%20history%22%3A%20%22saved%22%2C%20%22Choose%20generating%20parameters%22%3A%20%22custom%22%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%22Supplied%20history%22%2C%20inline%3DTrue%2C%20label%3D%22Observed-history%20source%22)%0A%20%20%20%20case_choice%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%7Bf%22History%20%7Bindex%20%2B%201%7D%22%3A%20index%20for%20index%20in%20range(len(cache_arrays%5B%22trajectory_id%22%5D))%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%22History%201%22%2C%20label%3D%22Supplied%20synthetic%20history%22)%0A%20%20%20%20mo.vstack(%5Blesson_md(%22%23%23%23%204.1%20The%20observed%20history%22)%2C%20history_source%5D)%0A%20%20%20%20return%20case_choice%2C%20history_source%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20cache_arrays%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20case_choice%2C%0A%20%20%20%20history_source%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20parameter_labels%2C%0A)%3A%0A%20%20%20%20%23%20These%20controls%20use%20the%20selected%20trained%20task's%20exact%20physical%20parameter%20bounds.%0A%20%20%20%20_controls%20%3D%20%7B%7D%0A%20%20%20%20for%20_index%2C%20(_name%2C%20(_low%2C%20_high))%20in%20enumerate(zip(cache_task%5B%22parameter_names%22%5D%2C%20cache_task%5B%22prior_bounds%22%5D))%3A%0A%20%20%20%20%20%20%20%20_controls%5B_name%5D%20%3D%20mo.ui.slider(float(_low)%2C%20float(_high)%2C%20step%3Dfloat((_high-_low)%2F200)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20value%3Dfloat(cache_arrays%5B%22truth%22%5D%5Bcase_choice.value%2C%20_index%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dparameter_labels%5B_name%5D%2C%20show_value%3DTrue%2C%20include_input%3DTrue)%0A%20%20%20%20observed_parameters%20%3D%20mo.ui.dictionary(_controls)%0A%20%20%20%20history_seed%20%3D%20mo.ui.number(0%2C%202**31-1%2C%20value%3D20261114%2C%20step%3D1%2C%20label%3D%22Random%20realization%20seed%22)%0A%20%20%20%20if%20history_source.value%20%3D%3D%20%22custom%22%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22Choose%20parameters%20within%20the%20trained%20bounds.%20Changes%20regenerate%20one%20complete%201%2C260-day%20history%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22with%20the%20same%20seed%3B%20change%20the%20seed%20for%20another%20realization.%20Posterior%20sampling%20is%20a%20separate%20action%20below.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20observed_parameters%2C%20history_seed%2C%0A%20%20%20%20%20%20%20%20%5D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20case_choice%0A%20%20%20%20_panel%0A%20%20%20%20return%20history_seed%2C%20observed_parameters%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20cache_arrays%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20case_choice%2C%0A%20%20%20%20history_seed%2C%0A%20%20%20%20history_source%2C%0A%20%20%20%20observed_parameters%2C%0A)%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20observations%20as%20history_data%0A%20%20%20%20if%20history_source.value%20%3D%3D%20%22custom%22%3A%0A%20%20%20%20%20%20%20%20active_history%20%3D%20history_data.custom_history(cache_task%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Bobserved_parameters.value%5Bname%5D%20for%20name%20in%20cache_task%5B%22parameter_names%22%5D%5D%2C%20seed%3Dhistory_seed.value)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20active_history%20%3D%20history_data.saved_history(cache_task%2C%20cache_arrays%2C%20case_choice.value)%0A%20%20%20%20return%20active_history%2C%20history_data%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(active_history%2C%20mo)%3A%0A%20%20%20%20_options%20%3D%20(%7B%22Use%20saved%20posterior%20samples%22%3A%20%22saved%22%2C%20%22Compute%20posterior%20for%20selected%20prefix%22%3A%20%22live%22%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%20else%20%7B%22Compute%20posterior%20for%20selected%20prefix%22%3A%20%22live%22%7D)%0A%20%20%20%20inference_mode%20%3D%20mo.ui.radio(_options%2C%20value%3Dnext(iter(_options))%2C%20inline%3DTrue%2C%20label%3D%22Posterior%20calculation%22)%0A%20%20%20%20inference_mode%0A%20%20%20%20return%20(inference_mode%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(active_history%2C%20cache_arrays%2C%20inference_mode%2C%20mo%2C%20trajectory)%3A%0A%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22saved%22%3A%0A%20%20%20%20%20%20%20%20observed_days%20%3D%20mo.ui.slider(steps%3Dtrajectory.saved_lengths(cache_arrays)%2C%20value%3D1260%2C%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%20%20%20%20%20%20%20%20%20label%3D%22Observed%20trading%20days%22%2C%20show_value%3DTrue)%0A%20%20%20%20%20%20%20%20_caption%20%3D%20%22Saved%20samples%20belong%20to%20this%20supplied%20history%20at%20this%20exact%20prefix.%20No%20model%20is%20loaded.%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20observed_days%20%3D%20mo.ui.slider(1%2C%201260%2C%20step%3D1%2C%20value%3D1260%2C%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%20%20%20%20%20%20%20%20%20label%3D%22Observed%20trading%20days%22%2C%20show_value%3DTrue%2C%20include_input%3DTrue)%0A%20%20%20%20%20%20%20%20_caption%20%3D%20(%22Choose%20a%20prefix%2C%20then%20press%20Compute%20posterior%20below.%20Only%20its%20returns%20enter%20the%20matching%20network.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20(%22Until%20then%2C%20the%20labelled%20saved%20snapshot%20is%20shown.%22%20if%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20%22A%20chosen%20history%20has%20no%20saved%20posterior%3B%20load%20the%20matching%20model%20to%20compute%20one.%22))%0A%20%20%20%20mo.accordion(%7B%22Optional%3A%20change%20the%20prefix%20used%20for%20posterior%20calculations%22%3A%20mo.vstack(%5Bobserved_days%2C%20mo.md(_caption)%5D)%7D)%0A%20%20%20%20return%20(observed_days%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(active_history%2C%20cache_task%2C%20history_data%2C%20mo%2C%20observed_days%2C%20trajectory)%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20history_widget%0A%20%20%20%20requested_days%20%3D%20observed_days.value%0A%20%20%20%20selection%20%3D%20history_data.selection_key(cache_task%2C%20active_history%2C%20requested_days)%0A%20%20%20%20%23%20Edit%20this%20title%20and%20these%20panel%20labels%20directly%20in%20marimo.%0A%20%20%20%20_title%20%3D%20(f%22%7Btrajectory.MODEL_LABELS%5Bcache_task%5B'model'%5D%5D%7D%20%C2%B7%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20(f%22synthetic%20history%20%7Bactive_history%5B'case'%5D%2B1%7D%22%20if%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20%22chosen%20synthetic%20history%22))%0A%20%20%20%20_labels%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22returns%22%3A%20%22Observed%20daily%20log%20return%20(%25)%22%2C%0A%20%20%20%20%20%20%20%20%22variance%22%3A%20%22Actual%20hidden%20variance%20V%20(annualized%20variance)%22%2C%0A%20%20%20%20%20%20%20%20%22returnhist%22%3A%20%22Revealed%20returns%20(%25)%22%2C%0A%20%20%20%20%20%20%20%20%22variancehist%22%3A%20%22Revealed%20boundary%20V%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20_html%20%3D%20history_widget.render_html(active_history%5B%22paired_history%22%5D%2C%20end%3Drequested_days%2C%0A%20%20%20%20%20%20%20%20label%3D_title%2C%20labels%3D_labels%2C%20show_header%3DFalse%2C%20show_footer%3DFalse%2C%20show_references%3DFalse)%0A%20%20%20%20mo.vstack(%5Bmo.md(f%22**%7B_title%7D**%22)%2C%20mo.iframe(_html%2C%20height%3D%22650px%22)%5D)%0A%20%20%20%20return%20requested_days%2C%20selection%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md)%3A%0A%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%204.2%20Produce%20and%20read%20the%20posterior%0A%0A%20%20%20%20**Condition%20the%20supplied%20estimator%20on%20this%20history.**%20Saved%20draws%20provide%20immediate%0A%20%20%20%20results%20for%20the%20supplied%20examples.%20A%20chosen%20history%20needs%20a%20fresh%20query%20using%20the%0A%20%20%20%20matching%20pretrained%20weights%3B%20no%20fitting%20is%20performed%20here.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20task%2C%20workflow%2C%20record%20%3D%20trajectory.load_live(model_choice.value)%0A%20%20%20%20%23%20Only%20observed%20returns%20enter%3A%20no%20future%20returns%2C%20labels%20or%20hidden%20variance.%0A%20%20%20%20revealed%20%3D%20active_history%5B%22returns%22%5D%5BNone%2C%20%3Aobserved_days.value%5D%0A%20%20%20%20draws%20%3D%20trajectory.sample(workflow%2C%20task%2C%20revealed%2C%20draws%3D512%2C%20seed%3D20261031)%5B0%5D%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20Each%20query%20uses%20the%20original%20prior%20and%20the%20complete%20revealed%20prefix.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(inference_mode%2C%20mo)%3A%0A%20%20%20%20checkpoint_path%20%3D%20mo.ui.text(value%3D%22%22%2C%20placeholder%3D%22local-checkpoints%2Fpath-rough-known%20(blank%20%3D%20selected%20model)%22%2C%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%20%20%20%20%20%20label%3D%22Model%20folder%20relative%20to%20tutorial%2Fassets%2F%20(optional)%22%2C%20full_width%3DTrue)%0A%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22live%22%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.accordion(%7B%22Model%20download%20and%20folder%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22Download%20the%20matching%20native%20model%20as%20described%20in%20the%20tutorial%20README.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Place%20its%20unchanged%20%60task.json%60%2C%20%60training.json%60%20and%20%60model.keras%60%20under%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%60assets%2Flocal-checkpoints%2Fpath-rough-known%2F%60%2C%20%60path-rough-joint%2F%60%20or%20%60path-heston%2F%60.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Leave%20this%20field%20blank%20for%20the%20selected%20model's%20default.%20No%20bank%20is%20needed.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20checkpoint_path%2C%0A%20%20%20%20%20%20%20%20%5D)%7D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.md(%22%22)%0A%20%20%20%20_panel%0A%20%20%20%20return%20(checkpoint_path%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(checkpoint_path%2C%20inference_mode%2C%20mo%2C%20requested_days%2C%20selection)%3A%0A%20%20%20%20_request%20%3D%20(selection%2C%20checkpoint_path.value%2C%20inference_mode.value)%0A%20%20%20%20live_button%20%3D%20mo.ui.run_button(label%3Df%22Compute%20posterior%20for%20%7Brequested_days%7D%20observed%20days%22)%0A%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22live%22%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.vstack(%5Blive_button%2C%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22The%20computed%20samples%20update%20the%20posterior%20views%20below.%20Changing%20the%20model%2C%20history%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22day%20or%20model%20folder%20clears%20the%20previous%20result%20and%20requires%20a%20new%20click.%22)%5D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.md(%22%22)%0A%20%20%20%20_panel%0A%20%20%20%20return%20(live_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20cache_arrays%2C%0A%20%20%20%20cache_report%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20checkpoint_path%2C%0A%20%20%20%20history_data%2C%0A%20%20%20%20inference_mode%2C%0A%20%20%20%20live_button%2C%0A%20%20%20%20model_choice%2C%0A%20%20%20%20requested_days%2C%0A%20%20%20%20selection%2C%0A%20%20%20%20trajectory%2C%0A)%3A%0A%20%20%20%20live_result%2C%20live_error%2C%20live_timing%20%3D%20None%2C%20None%2C%20None%0A%20%20%20%20pretrained_workflow%20%3D%20None%0A%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22live%22%20and%20live_button.value%3A%0A%20%20%20%20%20%20%20%20from%20time%20import%20perf_counter%20as%20_live_clock%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_start%20%3D%20_live_clock()%0A%20%20%20%20%20%20%20%20%20%20%20%20_task%2C%20_workflow%2C%20_record%20%3D%20trajectory.load_live(model_choice.value%2C%20checkpoint_path.value.strip()%20or%20None)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20_task%20!%3D%20cache_task%20or%20_record%5B%22model_sha256%22%5D%20!%3D%20cache_report%5B%22checkpoint_sha256%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22checkpoint%20or%20task%20differs%20from%20this%20observed%20history%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_load_seconds%20%3D%20_live_clock()%20-%20_start%0A%20%20%20%20%20%20%20%20%20%20%20%20_revealed%20%3D%20active_history%5B%22returns%22%5D%5BNone%2C%20%3Arequested_days%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20_start%20%3D%20_live_clock()%0A%20%20%20%20%20%20%20%20%20%20%20%20_draws%20%3D%20trajectory.sample(_workflow%2C%20_task%2C%20_revealed%2C%20draws%3D512%2C%20seed%3D20261031)%5B0%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20_sample_seconds%20%3D%20_live_clock()%20-%20_start%0A%20%20%20%20%20%20%20%20%20%20%20%20_candidate%20%3D%20%7B%22selection%22%3A%20selection%2C%20%22draws%22%3A%20_draws%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20history_data.posterior_view(cache_task%2C%20cache_arrays%2C%20active_history%2C%20requested_days%2C%20live%3D_candidate)%0A%20%20%20%20%20%20%20%20%20%20%20%20live_result%2C%20pretrained_workflow%20%3D%20_candidate%2C%20_workflow%0A%20%20%20%20%20%20%20%20%20%20%20%20live_timing%20%3D%20(_load_seconds%2C%20_sample_seconds)%0A%20%20%20%20%20%20%20%20except%20(FileNotFoundError%2C%20ValueError%2C%20RuntimeError%2C%20ImportError%2C%20OSError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20live_error%20%3D%20str(_error)%0A%20%20%20%20return%20live_error%2C%20live_result%2C%20live_timing%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20cache_arrays%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20history_data%2C%0A%20%20%20%20live_result%2C%0A%20%20%20%20requested_days%2C%0A)%3A%0A%20%20%20%20posterior%20%3D%20history_data.posterior_view(cache_task%2C%20cache_arrays%2C%20active_history%2C%20requested_days%2C%20live%3Dlive_result)%0A%20%20%20%20return%20(posterior%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20inference_mode%2C%0A%20%20%20%20live_error%2C%0A%20%20%20%20live_timing%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20posterior%2C%0A%20%20%20%20requested_days%2C%0A)%3A%0A%20%20%20%20_contents%20%3D%20%5B%5D%0A%20%20%20%20if%20posterior%20is%20None%3A%0A%20%20%20%20%20%20%20%20_contents.append(mo.md(%22**No%20posterior%20computed%20for%20this%20chosen%20history%20yet.**%20Use%20the%20matching%20pretrained%20model%20and%20press%20Compute%20posterior.%22))%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_contents.append(mo.callout(mo.md(f%22**Source%3A%20supplied%20pretrained%20model.%20%7Bposterior%5B'label'%5D%7D.**%22)%2C%20kind%3D%22neutral%22))%0A%20%20%20%20%20%20%20%20if%20posterior%5B%22source%22%5D%20%3D%3D%20%22live%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_contents.append(mo.md(f%22Model%20verification%2Fload%3A%20**%7Blive_timing%5B0%5D%3A.3f%7D%20s**%3B%20%22%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%20%20%20%20%20%20%20f%22512%20paired%20draws%3A%20**%7Blive_timing%5B1%5D%3A.3f%7D%20s**.%20Fresh%20describes%20execution%2C%20not%20accuracy.%22))%0A%20%20%20%20%20%20%20%20elif%20inference_mode.value%20%3D%3D%20%22live%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_contents.append(mo.md(f%22The%20display%20reveals%20%7Brequested_days%7D%20days%3B%20the%20saved%20posterior%20uses%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bposterior%5B'length'%5D%7D%20days.%20Press%20Compute%20posterior%20to%20query%20the%20selected%20prefix.%22))%0A%20%20%20%20if%20live_error%3A%0A%20%20%20%20%20%20%20%20_suffix%20%3D%20(%22%20The%20labelled%20saved%20result%20remains%20visible.%22%20if%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20%22%20No%20other%20history's%20posterior%20is%20substituted.%22)%0A%20%20%20%20%20%20%20%20_contents.append(mo.callout(mo.md(%22Posterior%20calculation%20is%20unavailable%3A%20%22%20%2B%20live_error%20%2B%20_suffix)%2C%20kind%3D%22warn%22))%0A%20%20%20%20mo.vstack(_contents)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(active_history%2C%20cache_task%2C%20mo%2C%20np%2C%20parameter_labels%2C%20plt%2C%20posterior)%3A%0A%20%20%20%20if%20posterior%20is%20None%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_names%20%3D%20cache_task%5B%22parameter_names%22%5D%0A%20%20%20%20%20%20%20%20_figure%2C%20_axes%20%3D%20plt.subplots((len(_names)%20%2B%201)%20%2F%2F%202%2C%202%2C%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%20%20%20%20%20%20%20%20%20%20figsize%3D(10%2C%202.45%20*%20((len(_names)%20%2B%201)%20%2F%2F%202))%2C%20squeeze%3DFalse)%0A%20%20%20%20%20%20%20%20_label%20%3D%20%22fresh%20neural%20approximation%22%20if%20posterior%5B%22source%22%5D%20%3D%3D%20%22live%22%20else%20%22saved%20neural%20approximation%22%0A%20%20%20%20%20%20%20%20for%20_index%2C%20_axis%20in%20enumerate(_axes.flat)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20_index%20%3E%3D%20len(_names)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_axis.set_visible(False)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20_low%2C%20_high%20%3D%20cache_task%5B%22prior_bounds%22%5D%5B_index%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20_grid%20%3D%20np.linspace(_low%2C%20_high%2C%20240)%0A%20%20%20%20%20%20%20%20%20%20%20%20_density%20%3D%20(1%20%2F%20(_grid%20*%20np.log(_high%20%2F%20_low))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20cache_task%5B%22prior_types%22%5D%5B_index%5D%20%3D%3D%20%22log_uniform%22%20else%20np.full_like(_grid%2C%201%20%2F%20(_high%20-%20_low)))%0A%20%20%20%20%20%20%20%20%20%20%20%20_axis.hist(posterior%5B%22draws%22%5D%5B%3A%2C%20_index%5D%2C%20bins%3Dnp.linspace(_low%2C%20_high%2C%2029)%2C%20density%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alpha%3D.42%2C%20color%3D%22%232563eb%22%2C%20label%3D_label)%0A%20%20%20%20%20%20%20%20%20%20%20%20_axis.plot(_grid%2C%20_density%2C%20linestyle%3D%22--%22%2C%20color%3D%22%2364748b%22%2C%20linewidth%3D1.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22declared%20prior%20density%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_axis.axvline(active_history%5B%22truth%22%5D%5B_index%5D%2C%20linestyle%3D%22%3A%22%2C%20color%3D%22%23111827%22%2C%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%20linewidth%3D1%2C%20label%3D%22synthetic%20truth%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_axis.set(xlim%3D(_low%2C%20_high)%2C%20title%3Dparameter_labels%5B_names%5B_index%5D%5D%2C%20ylabel%3D%22Marginal%20density%22)%0A%20%20%20%20%20%20%20%20_axes.flat%5B0%5D.legend(fontsize%3D7)%0A%20%20%20%20%20%20%20%20_figure.suptitle(f%22Prior%20and%20approximate%20posterior%20%C2%B7%20%7Bposterior%5B'length'%5D%7D%20days%22%2C%20fontsize%3D12)%0A%20%20%20%20%20%20%20%20_figure.tight_layout()%0A%20%20%20%20%20%20%20%20_display%20%3D%20_figure%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20**Read%20the%20comparison%3A**%20the%20dotted%20truth%20line%20is%20for%20evaluation%20only%3B%20it%20never%0A%20%20%20%20enters%20the%20network.%20Dashed%20curves%20show%20the%20declared%20priors%2C%20including%20log-uniform%0A%20%20%20%20densities.%20Contraction%20does%20not%20establish%20accuracy.%20There%20is%20no%20matched%20reference%0A%20%20%20%20posterior%20for%20these%20histories%20and%20lengths.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(active_history%2C%20cache_task%2C%20mo%2C%20parameter_labels%2C%20posterior%2C%20trajectory)%3A%0A%20%20%20%20if%20posterior%20is%20None%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_reading%20%3D%20trajectory.posterior_readout(cache_task%2C%20posterior%5B%22draws%22%5D%2C%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%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20truth%3Dactive_history%5B%22truth%22%5D)%0A%20%20%20%20%20%20%20%20_small%20%3D%20_reading%5B%22narrowest_relative_to_prior%22%5D%0A%20%20%20%20%20%20%20%20_large%20%3D%20_reading%5B%22widest_relative_to_prior%22%5D%0A%20%20%20%20%20%20%20%20_parameters%20%3D%20_reading%5B%22parameters%22%5D%0A%20%20%20%20%20%20%20%20_precision%20%3D%20(f%22**Relative%20width.**%20%7Bparameter_labels%5B_small%5D%7D%20has%20the%20narrowest%20central%2090%25%20interval%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22relative%20to%20its%20own%20prior%3A%20**%7B100*_parameters%5B_small%5D%5B'width_ratio90'%5D%3A.1f%7D%25**%20of%20the%20prior's%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22central%2090%25%20width.%20%7Bparameter_labels%5B_large%5D%7D%20retains%20**%7B100*_parameters%5B_large%5D%5B'width_ratio90'%5D%3A.1f%7D%25**.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22These%20compare%20equal-probability%20widths%2C%20including%20the%20log-uniform%20priors.%22)%0A%20%20%20%20%20%20%20%20_pair%20%3D%20_reading%5B%22strongest_pair%22%5D%0A%20%20%20%20%20%20%20%20_dependence%20%3D%20(f%22**Dependence.**%20The%20largest%20absolute%20Pearson%20correlation%20is%20between%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bparameter_labels%5B_pair%5B'names'%5D%5B0%5D%5D%7D%20and%20%7Bparameter_labels%5B_pair%5B'names'%5D%5B1%5D%5D%7D%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22**%7B_pair%5B'correlation'%5D%3A%2B.2f%7D**.%20Keep%20their%20coordinates%20paired%20when%20using%20these%20draws.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_pair%20else%20%22**Dependence.**%20Fewer%20than%20two%20coordinates%20vary%20in%20these%20draws%3B%20a%20Pearson%20pair%20correlation%20is%20undefined.%22)%0A%20%20%20%20%20%20%20%20_misses%20%3D%20_reading%5B%22truth_excluded_parameters%22%5D%0A%20%20%20%20%20%20%20%20_truth%20%3D%20(%22**Synthetic%20truths.**%20Outside%20the%20central%2090%25%20marginal%20intervals%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2B%20%22%2C%20%22.join(parameter_labels%5Bname%5D%20for%20name%20in%20_misses)%20%2B%20%22.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_misses%20else%20%22**Synthetic%20truths.**%20All%20generating%20values%20lie%20within%20their%20central%2090%25%20marginal%20intervals%20for%20this%20history.%22)%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.vstack(%5Bmo.md(%22**Read%20this%20posterior%20in%20three%20steps**%5Cn%5Cn%22%20%2B%20_precision)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(_dependence)%2C%20mo.md(_truth)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22These%20summaries%20describe%20the%20displayed%20**approximation**%20for%20this%20history%20and%20prefix.%20%22%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%22Width%20reduction%20and%20truth%20inclusion%20in%20one%20case%20do%20not%20establish%20accuracy.%20%22%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%22The%20final%20calibration%20failures%20and%20model-specific%20numerical%20limits%20still%20apply.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.accordion(%7B%22Definitions%20behind%20this%20reading%22%3A%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Relative%20width%20is%20(posterior%20q95%20%E2%88%92%20q05)%20%2F%20(prior%20q95%20%E2%88%92%20q05)%2C%20in%20physical%20units.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22It%20is%20not%20an%20information-distance%20or%20accuracy%20score.%20Pearson%20correlation%20measures%20linear%20dependence%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22a%20small%20value%20does%20not%20rule%20out%20nonlinear%20dependence.%20Truth%20markers%20are%20evaluation%20labels%20and%20never%20network%20inputs.%22)%7D)%5D)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20evidence%20as%20evidence_frames%2C%20evidence_widget%0A%20%20%20%20%23%20Session-only%20frame%2Fworkflow%20contexts%3B%20no%20files%20are%20written%20by%20the%20player.%0A%20%20%20%20evidence_contexts%20%3D%20%7B%7D%0A%20%20%20%20return%20evidence_contexts%2C%20evidence_frames%2C%20evidence_widget%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md)%3A%0A%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%23%23%23%204.3%20Watch%20the%20evidence%20grow%0A%0A%20%20%20%20**Reveal%20observations%3B%20watch%20the%20parameter%20distributions%20respond.**%20This%20local%0A%20%20%20%20player%20follows%20the%20model%20and%20history%20selected%20above.%20The%20upper%20observed-day%0A%20%20%20%20control%20sets%20its%20maximum%3B%20the%20player%20cursor%20does%20not%20change%20the%20other%20notebook%0A%20%20%20%20views.%20Start%20with%20the%20prior%2C%20then%20play%2C%20pause%2C%20advance%20or%20scrub%20through%20actual%0A%20%20%20%20posterior%20frames.%20Zoom%20into%20the%20first%20days%20and%20switch%20the%20time-axis%20units.%0A%0A%20%20%20%20Drift%20may%20remain%20uncertain%20after%20volatility%20parameters%20sharpen.%20Intervals%20can%0A%20%20%20%20move%20or%20widen%20after%20surprising%20returns%3B%20the%20generating%20parameters%20stay%20fixed.%0A%20%20%20%20The%20posteriors%20are%20actual%20saved%20or%20explicitly%20queried%20distributions%2C%20never%0A%20%20%20%20interpolated.%20**This%20is%20evidence%20revelation%2C%20not%20hidden-state%20propagation%20or%0A%20%20%20%20a%20particle%20filter.**%20No%20process%20is%20regenerated%20during%20playback.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20cache_arrays%2C%0A%20%20%20%20cache_report%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20case_choice%2C%0A%20%20%20%20checkpoint_path%2C%0A%20%20%20%20evidence_contexts%2C%0A%20%20%20%20evidence_frames%2C%0A%20%20%20%20inference_mode%2C%0A)%3A%0A%20%20%20%20from%20hashlib%20import%20sha256%20as%20_playback_hash%0A%20%20%20%20_checkpoint%20%3D%20cache_report%5B%22checkpoint_sha256%22%5D%0A%20%20%20%20_history%20%3D%20active_history%5B%22id%22%5D%0A%20%20%20%20_path%20%3D%20checkpoint_path.value.strip()%20or%20None%0A%20%20%20%20_history_hash%20%3D%20_playback_hash(active_history%5B%22returns%22%5D.tobytes()).hexdigest()%0A%20%20%20%20_key%20%3D%20(cache_report%5B%22task_sha256%22%5D%2C%20_checkpoint%2C%20_history%2C%20_history_hash%2C%20inference_mode.value%2C%20_path)%0A%20%20%20%20if%20_key%20not%20in%20evidence_contexts%3A%0A%20%20%20%20%20%20%20%20_dense_error%20%3D%20None%0A%20%20%20%20%20%20%20%20_manager%20%3D%20(evidence_frames.saved_manager(cache_task%2C%20cache_arrays%2C%20case_choice.value%2C%20_checkpoint)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22saved%22%20and%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%20else%20evidence_frames.native_manager(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20cache_task%2C%20active_history%5B%22returns%22%5D%2C%20_checkpoint%2C%20_history%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20draws%3D128%2C%20seed%3D20261113))%0A%20%20%20%20%20%20%20%20if%20inference_mode.value%20%3D%3D%20%22saved%22%20and%20active_history%5B%22source%22%5D%20%3D%3D%20%22saved%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20from%20sbi4f_tutorial.trajectories%20import%20evidence_assets%20as%20_dense_evidence%0A%20%20%20%20%20%20%20%20%20%20%20%20except%20ImportError%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pass%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_manager%20%3D%20_dense_evidence.load_dense(_manager)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20except%20(OSError%2C%20ValueError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_dense_error%20%3D%20(%22Optional%20denser%20replay%20unavailable%3A%20%22%20%2B%20str(_error)%20%2B%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%22.%20The%20original%20verified%20snapshots%20remain%20available%3B%20no%20extra%20frames%20were%20accepted.%22)%0A%20%20%20%20%20%20%20%20evidence_contexts%5B_key%5D%20%3D%20%7B%22manager%22%3A%20_manager%2C%20%22workflow%22%3A%20None%2C%20%22dense_error%22%3A%20_dense_error%7D%0A%20%20%20%20_context%20%3D%20evidence_contexts%5B_key%5D%0A%20%20%20%20playback_manager%20%3D%20_context%5B%22manager%22%5D%0A%20%20%20%20playback_message%2C%20playback_error%20%3D%20None%2C%20_context.get(%22dense_error%22)%0A%20%20%20%20return%20playback_error%2C%20playback_manager%2C%20playback_message%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20evidence_frames%2C%0A%20%20%20%20evidence_widget%2C%0A%20%20%20%20inference_mode%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20parameter_labels%2C%0A%20%20%20%20playback_error%2C%0A%20%20%20%20playback_manager%2C%0A%20%20%20%20playback_message%2C%0A%20%20%20%20requested_days%2C%0A)%3A%0A%20%20%20%20_frames%20%3D%20evidence_frames.frame_list(playback_manager%2C%20requested_days)%0A%20%20%20%20_parts%20%3D%20%5B%5D%0A%20%20%20%20if%20playback_error%3A%0A%20%20%20%20%20%20%20%20_parts.append(mo.callout(mo.md(%22**Evidence%20player%20notice%3A**%20%22%20%2B%20playback_error)%2C%20kind%3D%22warn%22))%0A%20%20%20%20if%20playback_message%3A%0A%20%20%20%20%20%20%20%20_parts.append(mo.md(playback_message))%0A%20%20%20%20if%20not%20_frames%3A%0A%20%20%20%20%20%20%20%20_parts.append(mo.md(%22*No%20posterior%20playback%20frames%20are%20available%20for%20this%20history.*%22))%0A%20%20%20%20_html%20%3D%20evidence_widget.render_html(playback_manager%5B%22task%22%5D%2C%0A%20%20%20%20%20%20%20%20active_history%5B%22returns%22%5D%2C%20_frames%2C%20end%3Drequested_days%2C%0A%20%20%20%20%20%20%20%20labels%3Dparameter_labels%2C%20truth%3Dactive_history%5B%22truth%22%5D%2C%0A%20%20%20%20%20%20%20%20history_label%3Df%22%7Bactive_history%5B'source'%5D.title()%7D%20history%20%C2%B7%20%7B'saved%20posterior%20samples'%20if%20inference_mode.value%20%3D%3D%20'saved'%20else%20'computed%20posterior%20frames'%7D%22)%0A%20%20%20%20_rows%20%3D%20(len(playback_manager%5B%22task%22%5D%5B%22parameter_names%22%5D)%2B1)%2F%2F2%0A%20%20%20%20_parts.append(mo.iframe(_html%2C%20height%3Df%22%7B380%2B210*_rows%7Dpx%22))%0A%20%20%20%20mo.vstack(_parts)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20lesson_section%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5Blesson_section(%22Check%22%2C%20%22Check%20replicated%20histories%2C%20parameter%20recovery%20and%20uncertainty%20before%20interpreting%20the%20results.%22%2C%20stage%3D5)%2C%20lesson_md(r%22%22%22%0A%20%20%20%20%7C%20Check%20%7C%20Question%20%7C%20Evidence%20here%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Replicated%20histories%20%7C%20Can%20fitted%20parameters%20reproduce%20these%20return%20summaries%3F%20%7C%20Independent%2C%20zero-origin%20posterior-predictive%20histories%20%7C%0A%20%20%20%20%7C%20Many%20independent%20histories%20%7C%20Does%20this%20estimator%20recover%20parameters%20and%20report%20uncertainty%3F%20%7C%20Saved%20final-cohort%20recovery%20and%20marginal%20coverage%20%7C%0A%20%20%20%20%7C%20One%20conditional%20posterior%20%7C%20Does%20the%20approximation%20match%20an%20independent%20numerical%20reference%3F%20%7C%20No%20matched%20reference%20for%20these%20histories%20and%20lengths%20%7C%0A%0A%20%20%20%20The%20saved%20final-cohort%20results%20below%20answer%20a%20broader%20validation%20question.%0A%20%20%20%20A%20successful%20small%20fit%20or%20a%20good-looking%20predictive%20plot%20does%20not%20replace%20them.%0A%0A%20%20%20%20%23%23%23%205.1%20Posterior%20predictive%3A%20replicate%2C%20then%20compare%0A%0A%20%20%20%20Select%20complete%20paired%20parameter%20draws%20from%20the%20displayed%20posterior%20and%0A%20%20%20%20generate%20a%20new%20history%20from%20the%20model's%20origin%20for%20each.%20Compare%20the%20**same%0A%20%20%20%20length%20used%20by%20that%20posterior**%20with%20the%20observed%20prefix.%20These%20are%20independent%0A%20%20%20%20replicas%2C%20not%20paths%20continuing%20from%20the%20end%20of%20the%20observed%20history.%0A%20%20%20%20%22%22%22)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20predictive_count%20%3D%20mo.ui.radio(options%3D%7B%2232%20histories%3A%20inspect%20individual%20curves%22%3A%2032%2C%0A%20%20%20%20%20%20%20%20%22256%20histories%3A%20optional%20finer%20simulation%20envelope%22%3A%20256%7D%2C%0A%20%20%20%20%20%20%20%20value%3D%2232%20histories%3A%20inspect%20individual%20curves%22%2C%20label%3D%22Posterior%20replication%20budget%22)%0A%20%20%20%20return%20(predictive_count%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20posterior%2C%20predictive_count%2C%20selection)%3A%0A%20%20%20%20_source%20%3D%20(selection%2C%20None%20if%20posterior%20is%20None%20else%20(posterior%5B%22source%22%5D%2C%20posterior%5B%22length%22%5D)%2C%20predictive_count.value)%0A%20%20%20%20replicate_button%20%3D%20mo.ui.run_button(label%3Df%22Replicate%20%7Bpredictive_count.value%7D%20histories%22)%0A%20%20%20%20if%20posterior%20is%20None%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.md(%22Compute%20a%20posterior%20for%20the%20chosen%20history%20before%20generating%20its%20predictive%20replicas.%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_panel%20%3D%20mo.accordion(%7B%22Optional%3A%20generate%20a%20posterior-predictive%20comparison%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20predictive_count%2C%20replicate_button%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22**Posterior%20source%3A%20%7Bposterior%5B'source'%5D%7D%20%C2%B7%20%7Bposterior%5B'length'%5D%7D%20days.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Independent%20replicas%20retain%20parameter%20uncertainty%20and%20fresh%20process%20randomness.%22)%5D)%7D)%0A%20%20%20%20_panel%0A%20%20%20%20return%20(replicate_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20active_history%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_checks%2C%0A%20%20%20%20posterior%2C%0A%20%20%20%20predictive_count%2C%0A%20%20%20%20replicate_button%2C%0A)%3A%0A%20%20%20%20posterior_predictive_result%20%3D%20None%0A%20%20%20%20_status%20%3D%20None%0A%20%20%20%20if%20posterior%20is%20not%20None%20and%20replicate_button.value%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20posterior_predictive_result%20%3D%20model_checks.replicate_check(cache_task%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20active_history%5B%22returns%22%5D%2C%20posterior%5B%22draws%22%5D%2C%20posterior%5B%22length%22%5D%2C%20count%3Dpredictive_count.value)%0A%20%20%20%20%20%20%20%20except%20(ValueError%2C%20RuntimeError%2C%20FloatingPointError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_status%20%3D%20mo.callout(mo.md(f%22**Replication%20stopped%3A**%20%7B_error%7D.%20No%20replicas%20are%20discarded%20or%20replaced.%22)%2C%20kind%3D%22warn%22)%0A%20%20%20%20_status%0A%20%20%20%20return%20(posterior_predictive_result%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20model_checks%2C%20posterior_predictive_result%2C%20predictive_visuals)%3A%0A%20%20%20%20if%20posterior_predictive_result%20is%20None%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_result%20%3D%20posterior_predictive_result%0A%20%20%20%20%20%20%20%20_comparison%20%3D%20predictive_visuals.compare(_result)%0A%20%20%20%20%20%20%20%20_control%20%3D%20(%22The%20brown%20IID%20Gaussian%20reference%20is%20fitted%20to%20this%20observed%20prefix's%20mean%20and%20SD.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_comparison%5B%22metadata%22%5D%5B%22gaussian_available%22%5D%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20Gaussian%20reference%20is%20unavailable%20for%20a%20short%20or%20constant%20prefix.%20%22)%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%22Paths%20and%20distributions%22%3Apredictive_visuals.paths_and_distributions(_comparison)%2C%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%22Summary%20checks%22%3Amodel_checks.plot_check(_result)%2C%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%22Timing%20checks%22%3Apredictive_visuals.timing(_result%2C%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%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%20%20%20%20%20%20%20%20%20%20%20%20_comparison%2Cshow_shuffle%3DFalse)%7D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.ui.table(predictive_visuals.feature_rows(_comparison)%2Cselection%3DNone%2Cpagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(f%22**%7B_result%5B'metadata'%5D%5B'count'%5D%7D%20independent%20replicas%20%C2%B7%20%7Bposterior%5B'length'%5D%7D%20days%20each.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20f%22The%20return%20plot%20reveals%20%7Brequested_days%7D%20days%3B%20this%20check%20follows%20the%20actual%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22posterior%20conditioning%20length.%20The%20spread%20retains%20parameter%20uncertainty%20and%20process%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22randomness.%20The%20ordering%20view%20uses%20the%20same%20prefix%2C%20with%20at%20most%2020%20lags%20and%20at%20least%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22five%20observed%20days%20per%20lag%3B%20below%2021%20days%20it%20reports%20insufficient%20history.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22A%20shuffled%20prefix%20is%20a%20teaching%20intervention%2C%20not%20another%20model%20simulation.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22Agreement%20on%20these%20checks%20does%20not%20establish%20model%20adequacy%20or%20calibrated%20inference.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22No%20latent%20state%20is%20filtered%20and%20no%20continuation%20forecast%20is%20generated.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(_control%20%2B%20%22**Compare%20mechanisms%3A**%20which%20features%20differ%20from%20the%20data-fitted%20IID%20Gaussian%20control%3F%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22Which%20features%20does%20the%20volatility%20model%20still%20fail%20to%20reproduce%3F%20A%20Gaussian%20control%20is%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22fitted%20after%20seeing%20these%20returns%2C%20whereas%20blue%20replicas%20use%20the%20displayed%20approximate%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22parameter%20posterior.%20Neither%20shaded%20range%20is%20a%20simultaneous%20path%20or%20joint-feature%20test.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22All%20model%20and%20Gaussian%20histories%20remain%20in%20the%20comparisons.%22)%2C%0A%20%20%20%20%20%20%20%20%5D)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(json%2C%20trajectory)%3A%0A%20%20%20%20aggregate_report%2C%20aggregate_images%2C%20aggregate_problem%20%3D%20None%2C%20%7B%7D%2C%20None%0A%20%20%20%20_folder%20%3D%20trajectory.ASSETS%20%2F%20%22results%22%20%2F%20%22trajectories%22%20%2F%20%22closeout-20261031%22%0A%20%20%20%20if%20_folder.is_dir()%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20_folder.resolve().is_relative_to(trajectory.ASSETS.resolve())%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22aggregate%20evidence%20must%20remain%20within%20tutorial%2Fassets%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_accepted%20%3D%20json.loads((_folder%20%2F%20%22ACCEPTED.json%22).read_text())%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20_name%20in%20(%22closeout-summary.json%22%2C%20%22figure-metadata.json%22%2C%20%22drift-learning.png%22%2C%20%22marginal-coverage.png%22)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_path%20%3D%20_folder%20%2F%20_name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(not%20_path.resolve().is_relative_to(trajectory.ASSETS.resolve())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20or%20trajectory.asset_digest(_path)%20!%3D%20_accepted%5B%22source_sha256%22%5D%5B_name%5D)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22packaged%20aggregate%20evidence%20hash%20differs%3A%20%22%20%2B%20_name)%0A%20%20%20%20%20%20%20%20%20%20%20%20_report%20%3D%20json.loads((_folder%20%2F%20%22closeout-summary.json%22).read_text())%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(_report.get(%22format%22)%20!%3D%20%22trajectory_workshop_closeout_summary_v1%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20or%20_report.get(%22scientific_acceptance%22)%20is%20not%20False)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22unexpected%20aggregate%20evidence%20scope%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_catalogue%20%3D%20trajectory.catalogue()%5B%22artifacts%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20set(_report%5B%22models%22%5D)%20!%3D%20set(_catalogue)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22aggregate%20report%20and%20trajectory%20catalogue%20model%20sets%20differ%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20_model%2C%20_record%20in%20_report%5B%22models%22%5D.items()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(_record%5B%22task_sha256%22%5D%20!%3D%20_catalogue%5B_model%5D%5B%22task_sha256%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20or%20_record%5B%22model_sha256%22%5D%20!%3D%20_catalogue%5B_model%5D%5B%22checkpoint_sha256%22%5D)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22aggregate%20evidence%20belongs%20to%20a%20different%20task%2Fcheckpoint%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20aggregate_report%20%3D%20_report%0A%20%20%20%20%20%20%20%20%20%20%20%20aggregate_images%20%3D%20%7B%22drift%22%3A%20_folder%20%2F%20%22drift-learning.png%22%2C%20%22coverage%22%3A%20_folder%20%2F%20%22marginal-coverage.png%22%7D%0A%20%20%20%20%20%20%20%20except%20(OSError%2C%20ValueError%2C%20KeyError)%20as%20_error%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20aggregate_problem%20%3D%20str(_error)%0A%20%20%20%20return%20aggregate_images%2C%20aggregate_problem%2C%20aggregate_report%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20aggregate_images%2C%0A%20%20%20%20aggregate_problem%2C%0A%20%20%20%20aggregate_report%2C%0A%20%20%20%20cache_task%2C%0A%20%20%20%20lesson_md%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20parameter_labels%2C%0A)%3A%0A%20%20%20%20_contents%20%3D%20%5Blesson_md(%22%23%23%23%205.2%20Saved%20final-cohort%20evidence%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22**Learning%20information%20and%20reporting%20reliable%20uncertainty%20are%20different%20achievements.**%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Recovery%20asks%20whether%20estimates%20improve%20over%20a%20prior-only%20baseline.%20Calibration%20asks%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22whether%20nominal%2090%25%20intervals%20contain%20truth%20about%2090%25%20of%20the%20time%20across%20independent%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22histories%20drawn%20from%20the%20prior%20and%20simulator.%20One%20posterior%20plot%20cannot%20establish%20either.%22)%5D%0A%20%20%20%20if%20aggregate_report%20is%20None%3A%0A%20%20%20%20%20%20%20%20_contents.append(mo.callout(mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Final-cohort%20diagnostics%20are%20unavailable%20in%20this%20copy.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%20(aggregate_problem%20or%20%22The%20selected%20history%20remains%20an%20illustration.%22))%2C%20kind%3D%22warn%22))%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_record%20%3D%20aggregate_report%5B%22models%22%5D%5Bcache_task%5B%22model%22%5D%5D%0A%20%20%20%20%20%20%20%20_records%20%3D%20list(aggregate_report%5B%22models%22%5D.values())%0A%20%20%20%20%20%20%20%20_failures%20%3D%20sum(not%20_entry%5B%22calibration_pass%22%5D%20for%20_entry%20in%20_records)%0A%20%20%20%20%20%20%20%20_contents.extend(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.callout(mo.md(f%22**%7B_failures%7D%20of%20%7Blen(_records)%7D%20supplied%20estimators%20failed%20the%20final%20%22%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%20%20%22marginal-calibration%20screen.**%20Lower%20estimation%20error%20and%20fast%20inference%20%22%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%20%20%22do%20not%20establish%20accurate%20intervals.%20Heston%20also%20has%20the%20drift%20point-mass%20limitation.%22)%2C%20kind%3D%22warn%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.image(aggregate_images%5B%22coverage%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22Black%20outlines%20mark%20failed%20coverage%20checks.%20For%20the%20selected%20model%2C%20nominal%2090%25%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22coverage%20ranges%20from%20**%7B100%20*%20_record%5B'coverage90_range'%5D%5B0%5D%3A.2f%7D%25%20to%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7B100%20*%20_record%5B'coverage90_range'%5D%5B1%5D%3A.2f%7D%25**%20across%20parameters%20and%20histories.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22A%20narrower%20interval%20can%20be%20informative%20and%20still%20too%20narrow.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.accordion(%7B%22Recovery%2C%20individual%20failures%20and%20evaluation%20design%22%3A%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22The%20checks%20use%20**%7B_record%5B'cases'%5D%3A%2C%7D%20independent%20test%20histories%20per%20model**%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22**%7B_record%5B'draws'%5D%7D%20draws%20per%20history**%2C%20and%20twelve%20frozen%20history%20lengths.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22These%20are%20separate%20from%20the%20four%20displayed%20validation%20histories.%20The%20independent%20unit%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22is%20a%20whole%20history%3B%20its%20nested%20prefixes%20are%20dependent.%20These%20reserved%20tests%20have%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22been%20examined%2C%20so%20new%20acceptance%20work%20needs%20fresh%20data.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(%5B%7B%22observed%20days%22%3A%20_cell%5B%22days%22%5D%2C%20%22parameter%22%3A%20parameter_labels.get(_cell%5B%22parameter%22%5D%2C%20_cell%5B%22parameter%22%5D)%2C%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%20%20%20%22coverage%20of%20nominal%2090%25%20interval%22%3A%20f%22%7B100%20*%20_cell%5B'coverage90'%5D%3A.2f%7D%25%22%2C%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%20%20%20%22screen%20criterion%22%3A%20_cell%5B%22criterion%22%5D.replace(%22_%22%2C%20%22%20%22)%7D%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%20%20for%20_cell%20in%20_record%5B%22failed_coverage_cells%22%5D%5D%2C%20selection%3DNone%2C%20pagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22These%20are%20the%20original%20joint-screen%20decisions%2C%20not%20tests%20selected%20after%20viewing%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22the%20figures.%20Heston%20drift%20uses%20an%20undercoverage%20screen%20only%3A%20central%20intervals%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22for%20posteriors%20with%20point%20masses%20can%20legitimately%20overcover.%20Even%20successful%20marginal%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22checks%20would%20not%20establish%20conditional%20accuracy%20or%20correct%20joint%20dependence.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.image(aggregate_images%5B%22drift%22%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20mo.md(%22**Recovery%3A**%20compare%20mean%20squared%20error%20with%20always%20returning%20the%20prior%20mean.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%22Below%20one%20means%20improvement%3B%20near%20one%20means%20little%20improvement.%20Each%20model%20has%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%22its%20own%20prior%20and%20data.%20The%20table%20summarizes%20five-year%20histories.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20mo.ui.table(%5B%7B%22parameter%22%3A%20parameter_labels.get(_name%2C%20_name)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22MSE%20%2F%20prior-mean%20baseline%20MSE%22%3A%20float(_ratio)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22estimation-error%20screen%22%3A%20_record%5B%22five_year_risk_labels%22%5D%5B_name%5D.replace(%22_%22%2C%20%22%20%22)%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_name%2C%20_ratio%20in%20_record%5B%22five_year_mse_to_prior_mean_ratio%22%5D.items()%5D%2C%20selection%3DNone%2C%20pagination%3DFalse)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20mo.md(f%22%7Bsum(_entry%5B'execution_pass'%5D%20for%20_entry%20in%20_records)%7D%20estimators%20passed%20execution%20checks%3B%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20f%22%7Bsum(_entry%5B'risk_pass'%5D%20for%20_entry%20in%20_records)%7D%20passed%20their%20estimation-error%20screen.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%20%20%20%20%22Those%20results%20do%20not%20override%20the%20calibration%20failures.%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%5D)%7D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20mo.md(%22**Try%20it%3A**%20name%20a%20parameter%20whose%20estimation%20error%20improves%2C%20then%20find%20a%20failed%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%20%20%20%20%20%20%22coverage%20check.%20Explain%20how%20both%20can%20be%20true.%22)%2C%0A%20%20%20%20%20%20%20%20%5D)%7D)%5D)%0A%20%20%20%20mo.vstack(_contents)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(lesson_md%2C%20lesson_section%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20lesson_section(%22Use%22%2C%20%22Identify%20what%20must%20be%20added%20to%20turn%20parameter%20inference%20into%20a%20continuation%20forecast.%22%2C%20stage%3D6)%2C%0A%20%20%20%20%20%20%20%20lesson_md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%206.1%20What%20would%20a%20continuation%20forecast%20need%3F%0A%0A%20%20%20%20%20%20%20%20Independent%20replicated%20histories%20check%20the%20fitted%20model%20from%20its%20origin.%0A%20%20%20%20%20%20%20%20Predicting%20the%20next%20part%20of%20the%20observed%20history%20additionally%20needs%20its%0A%20%20%20%20%20%20%20%20current%20hidden%20state%3B%20rough%20Bergomi%20also%20needs%20past-shock%20memory.%20The%20GRU%0A%20%20%20%20%20%20%20%20summary%20is%20not%20a%20joint%20state%E2%80%93parameter%20posterior%2C%20so%20these%20results%20are%0A%20%20%20%20%20%20%20%20not%20state-conditioned%20forecasts%20of%20subsequent%20returns%2C%20VaR%20or%20expected%0A%20%20%20%20%20%20%20%20shortfall.%0A%0A%20%20%20%20%20%20%20%20**Joint%20across%20parameters%20is%20different%20from%20joint%20across%20time.**%20We%0A%20%20%20%20%20%20%20%20already%20learn%20one%20joint%20posterior%20over%20all%20four%2C%20five%20or%20seven%20fixed%0A%20%20%20%20%20%20%20%20parameters.%20The%20separate%20density%20plots%20are%20marginals%20of%20those%20same%0A%20%20%20%20%20%20%20%20paired%20draws%3B%20they%20are%20not%20independently%20trained%20parameter%20estimates.%0A%20%20%20%20%20%20%20%20Keeping%20those%20rows%20together%20preserves%20parameter%20dependence%20when%20we%0A%20%20%20%20%20%20%20%20simulate%20outcomes.%20It%20does%20not%20supply%20a%20posterior%20over%20the%20hidden%0A%20%20%20%20%20%20%20%20variance%20trajectory.%0A%0A%20%20%20%20%20%20%20%20For%20example%2C%20one%20rough%20Bergomi%20posterior%20row%20might%20be%0A%20%20%20%20%20%20%20%20%24(H%2C%5Ceta%2C%5Crho%2C%5Cmu)%3D(0.1%2C1.2%2C-0.7%2C0.05)%24.%20It%20is%20one%20plausible%0A%20%20%20%20%20%20%20%20**combination**.%20Plotting%20H%20alone%20hides%20the%20other%20coordinates%20in%20the%0A%20%20%20%20%20%20%20%20display%3B%20it%20does%20not%20train%20a%20separate%20H%20estimator.%20Taking%20H%20from%20one%0A%20%20%20%20%20%20%20%20row%20and%20%CE%B7%20from%20another%20would%20create%20combinations%20that%20the%20joint%0A%20%20%20%20%20%20%20%20posterior%20did%20not%20necessarily%20support.%0A%0A%20%20%20%20%20%20%20%20**Which%20inference%20question%20did%20we%20train%3F**%20This%20distinction%20matters%20more%0A%20%20%20%20%20%20%20%20than%20whether%20an%20encoder%20happens%20to%20be%20recurrent%3A%0A%0A%20%20%20%20%20%20%20%20%7C%20Question%20%7C%20Target%20distribution%20%7C%20Present%20estimator%20%7C%0A%20%20%20%20%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%20%20%20%20%7C%20Static%20parameter%20inference%20%7C%20%24p(%5CTheta%5Cmid%20r_%7B1%3At%7D)%24%20%7C%20Yes%3A%20one%20joint%20parameter%20vector%20shared%20across%20the%20history%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Marginal%20state%20filtering%20%7C%20%24p(V_t%5Cmid%20r_%7B1%3At%7D)%24%20%7C%20No%3A%20the%20latent%20state%20is%20not%20a%20training%20target%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Joint%20trajectory%20smoothing%20%7C%20%24p(V_%7B1%3AT%7D%5Cmid%20r_%7B1%3AT%7D)%24%20%7C%20No%3A%20past%20and%20future%20observations%20would%20inform%20an%20entire%20latent%20path%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Conditional%20continuation%20%7C%20%24p(r_%7BT%2B1%3AT%2Bh%7D%5Cmid%20r_%7B1%3AT%7D)%24%20%7C%20Needs%20a%20suitable%20joint%20state%E2%80%93parameter%20posterior%20or%20a%20directly%20trained%20predictive%20model%20%7C%0A%0A%20%20%20%20%20%20%20%20**Why%20didn't%20we%20train%20a%20state%20estimator%3F**%20We%20chose%20one%20teaching%20target%3A%0A%20%20%20%20%20%20%20%20fixed%20parameters%20given%20an%20ordered%20return%20history.%20Keeping%20the%20parameter%0A%20%20%20%20%20%20%20%20target%20from%20the%20option%20lessons%20lets%20us%20focus%20on%20what%20changes%20when%20the%0A%20%20%20%20%20%20%20%20observations%20become%20a%20sequence.%20The%20training%20loss%0A%20%20%20%20%20%20%20%20compares%20inferred%20parameters%20with%20their%20generating%20values%3B%20it%20never%20asks%0A%20%20%20%20%20%20%20%20the%20network%20to%20recover%20the%20terminal%20variance%20or%20latent%20shocks.%20Those%0A%20%20%20%20%20%20%20%20states%20exist%20in%20simulation%2C%20so%20adding%20them%20is%20possible.%20It%20is%20a%20different%0A%20%20%20%20%20%20%20%20inference%20task%20that%20needs%20its%20own%20targets%2C%20training%20design%20and%20validation.%0A%20%20%20%20%20%20%20%20BayesFlow%20itself%20does%20not%20restrict%20us%20to%20parameter%20inference.%20Marginalizing%0A%20%20%20%20%20%20%20%20hidden%20paths%20while%20inferring%20static%20parameters%20is%20not%20the%20same%20task%20as%0A%20%20%20%20%20%20%20%20marginal%20state%20filtering.%20Our%20flow%20retains%20dependence%20between%20the%0A%20%20%20%20%20%20%20%20components%20of%20%24%5CTheta%24%3B%20it%20does%20not%20return%20independent%20parameter%20marginals.%0A%0A%20%20%20%20%20%20%20%20With%20continuous-time%20Heston%2C%20a%20joint%20posterior%20over%20parameters%20and%20today's%20variance%0A%20%20%20%20%20%20%20%20would%20supply%20a%20Markov%20state%20from%20which%20to%20continue.%20For%20rough%20Bergomi%2C%0A%20%20%20%20%20%20%20%20today's%20variance%20alone%20does%20not%20summarize%20how%20past%20shocks%20affect%20future%0A%20%20%20%20%20%20%20%20variance.%20We%20would%20need%20a%20suitable%20memory%20representation%2C%20a%20validated%0A%20%20%20%20%20%20%20%20finite-factor%20approximation%2C%20or%20a%20model%20trained%20directly%20for%20future%0A%20%20%20%20%20%20%20%20returns%20conditional%20on%20the%20past.%20A%20GRU%20summary%20is%20not%20automatically%20a%0A%20%20%20%20%20%20%20%20calibrated%20posterior%20over%20any%20of%20these%20states.%0A%20%20%20%20%20%20%20%20State%20estimation%20need%20not%20itself%20be%20neural%3A%20another%20route%20is%20a%0A%20%20%20%20%20%20%20%20conventional%20filter%20conditional%20on%20each%20parameter%20draw.%20This%20lesson%0A%20%20%20%20%20%20%20%20currently%20implements%20neither%20that%20filter%20nor%20a%20learned%20state%20posterior.%0A%0A%20%20%20%20%20%20%20%20**Takeaways**%0A%0A%20%20%20%20%20%20%20%201.%20Ordered%20returns%20are%20the%20data%3B%20latent%20variance%20and%20innovations%20are%20hidden.%0A%20%20%20%20%20%20%20%202.%20A%20recurrent%20summary%20and%20conditional%20flow%20learn%20a%20joint%20parameter%20distribution.%0A%20%20%20%20%20%20%20%203.%20Random%20prefixes%20and%20masks%20let%20one%20estimator%20use%20different%20amounts%20of%20history.%0A%20%20%20%20%20%20%20%204.%20Prior%20prediction%2C%20replicated-history%20fit%2C%20recovery%20and%20calibration%20ask%20different%20questions.%0A%20%20%20%20%20%20%20%205.%20A%20parameter%20point%20hides%20uncertainty%3B%20retain%20paired%20posterior%20draws%20when%20using%20the%20result.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.accordion(%7B%22What%20the%20BayesFlow%20smoothing%20example%20actually%20changes%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20The%20official%20%5Bbivariate%20smoothing%20tutorial%5D(https%3A%2F%2Fbayesflow.org%2Fv2.0.14%2F_examples%2FBivariate_Smoothing.html)%0A%20%20%20%20%20%20%20%20(%5Bpinned%20source%20notebook%5D(https%3A%2F%2Fgithub.com%2Fbayesflow-org%2Fbayesflow%2Fblob%2Fv2.0.14%2Fexamples%2FBivariate_Smoothing.ipynb))%0A%20%20%20%20%20%20%20%20infers%20a%20**time-varying%20latent%20trajectory**%2C%20not%20one%20fixed%20parameter%20vector.%0A%20%20%20%20%20%20%20%20It%20uses%20all%20observations%20to%20learn%20a%20full%20joint%20smoother%2C%0A%0A%20%20%20%20%20%20%20%20%24%24q(z_%7B1%3AT%7D%5Cmid%20r_%7B1%3AT%7D)%3D%0A%20%20%20%20%20%20%20%20%20%20%5Cprod_%7Bt%3D1%7D%5ET%20q(z_t%5Cmid%20z_%7B1%3At-1%7D%2Cr_%7B1%3AT%7D).%24%24%0A%0A%20%20%20%20%20%20%20%20Its%20encoder%20returns%20a%20sequence%20of%20representations.%20An%20**autoregressive%0A%20%20%20%20%20%20%20%20decoder**%20then%20conditions%20each%20latent-state%20draw%20on%20the%20previously%20drawn%0A%20%20%20%20%20%20%20%20states.%20That%20is%20a%20new%20target%2C%20decoder%2C%20training%20loss%20and%20validation%20task%3B%0A%20%20%20%20%20%20%20%20it%20is%20not%20merely%20another%20name%20for%20our%20causal%20GRU%20summary.%0A%0A%20%20%20%20%20%20%20%20Here%20the%20GRU%20reads%20the%20observed%20prefix%20and%20emits%20one%20summary%20for%20a%0A%20%20%20%20%20%20%20%20static-parameter%20density.%20Adding%20a%20sequence%20encoder%20is%20the%20central%0A%20%20%20%20%20%20%20%20representation%20change%20from%20flat%20option%20quotes.%20The%20time%20design%2C%0A%20%20%20%20%20%20%20%20parameter%20transforms%20and%20conditional-flow%20architecture%20also%20differ%20in%0A%20%20%20%20%20%20%20%20the%20displayed%20workflows.%20A%20recurrent%20encoder%20alone%20does%20not%20make%20this%0A%20%20%20%20%20%20%20%20an%20autoregressive%20posterior%20over%20latent%20states.%0A%0A%20%20%20%20%20%20%20%20Learning%20curve%20coefficients%20instead%20of%20supplying%20them%20is%20orthogonal%0A%20%20%20%20%20%20%20%20to%20this%20choice.%20Either%20a%20fixed-curve%20or%20an%20inferred-curve%20model%20could%0A%20%20%20%20%20%20%20%20support%20parameter%20inference%2C%20filtering%20or%20smoothing%20with%20suitable%0A%20%20%20%20%20%20%20%20training%20targets%20and%20checks.%20Existing%20weights%20implement%20only%20the%20task%0A%20%20%20%20%20%20%20%20for%20which%20they%20were%20trained.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%20%22Replicated%20histories%2C%20filtering%20and%20continuations%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20An%20independent%20replicate%20averages%20%24p(r%5E%7B%5Crm%20rep%7D_%7B1%3AT%7D%5Cmid%5CTheta)%24%20over%0A%20%20%20%20%20%20%20%20%24p(%5CTheta%5Cmid%20r_%7B1%3AT%7D)%24.%20A%20conditional%20continuation%20instead%20needs%0A%0A%20%20%20%20%20%20%20%20%24%24p(r_%7BT%2B1%3AT%2Bh%7D%5Cmid%20r_%7B1%3AT%7D)%3D%0A%20%20%20%20%20%20%20%20%20%20%5Cint%20p(r_%7BT%2B1%3AT%2Bh%7D%5Cmid%20z_T%2C%5CTheta)%5C%2C%0A%20%20%20%20%20%20%20%20%20%20p(z_T%2C%5CTheta%5Cmid%20r_%7B1%3AT%7D)%5C%2Cdz_T%5C%2Cd%5CTheta.%24%24%0A%0A%20%20%20%20%20%20%20%20Here%20%24z_T%24%20includes%20hidden%20state%20and%2C%20for%20rough%20Bergomi%2C%20memory.%20Filtering%0A%20%20%20%20%20%20%20%20infers%20that%20state%20from%20past%20observations.%20This%20network%20infers%20fixed%0A%20%20%20%20%20%20%20%20parameters%20after%20averaging%20over%20hidden%20paths.%0A%0A%20%20%20%20%20%20%20%20A%20parameter%20posterior%20and%20a%20conditional%20state%20filter%20could%20be%20combined%0A%20%20%20%20%20%20%20%20through%0A%0A%20%20%20%20%20%20%20%20%24%24p(%5CTheta%2Cz_T%5Cmid%20r_%7B1%3AT%7D)%3D%0A%20%20%20%20%20%20%20%20%20%20p(z_T%5Cmid%5CTheta%2Cr_%7B1%3AT%7D)p(%5CTheta%5Cmid%20r_%7B1%3AT%7D).%24%24%0A%0A%20%20%20%20%20%20%20%20Sample%20a%20parameter%20vector%2C%20then%20a%20state%20conditional%20on%20that%20**same**%0A%20%20%20%20%20%20%20%20vector%20and%20history.%20Independently%20sampling%20the%20two%20marginal%20posteriors%0A%20%20%20%20%20%20%20%20would%20discard%20their%20dependence%20and%20can%20change%20the%20predictive%20result.%0A%20%20%20%20%20%20%20%20The%20same%20principle%20explains%20why%20we%20keep%20parameter%20coordinates%20paired%0A%20%20%20%20%20%20%20%20when%20generating%20replicated%20histories.%20Marginalizing%20hidden%20paths%20in%20parameter%0A%20%20%20%20%20%20%20%20inference%20does%20not%20make%20the%20parameter%20posterior%20factorize.%0A%0A%20%20%20%20%20%20%20%20Heston's%20continuous-time%20state%20is%20its%20variance.%20Exact%20continuation%20of%20our%0A%20%20%20%20%20%20%20%20full-truncation%20numerical%20scheme%20also%20retains%20its%20signed%20auxiliary%0A%20%20%20%20%20%20%20%20variance%3B%20replacing%20it%20with%20its%20positive%20part%20loses%20numerical%20state.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%20%22How%20does%20amortized-fractals%20compare%3F%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20The%20%5Bexpanded%20MMAR%20tutorials%5D(https%3A%2F%2Fgithub.com%2Fstefanradev93%2Famortized-fractals)%0A%20%20%20%20%20%20%20%20also%20train%20**joint%20parameter-only**%20estimators%3A%20four%20coordinates%20in%0A%20%20%20%20%20%20%20%20the%20univariate%20model%2C%2013%20in%20the%20multivariate%20model%20and%2016%20with%20its%0A%20%20%20%20%20%20%20%20Hurst%20extension.%20Their%20one-dimensional%20posterior%20plots%20are%20views%20of%0A%20%20%20%20%20%20%20%20joint%20draws%2C%20just%20as%20ours%20are.%20Their%20practical%20applications%0A%20%20%20%20%20%20%20%20are%20more%20developed%3A%20rolling%20risk%20estimates%2C%20stock%20screening%20and%0A%20%20%20%20%20%20%20%20allocation%20backtests.%20Their%20scenario%20code%20draws%20fresh%20cascade%20weights%2C%0A%20%20%20%20%20%20%20%20a%20fresh%20cascade%20phase%20and%20new%20innovations%20after%20inferring%20parameters.%0A%20%20%20%20%20%20%20%20It%20does%20not%20infer%20the%20observed%20window's%20terminal%20cascade%20state%20and%0A%20%20%20%20%20%20%20%20continue%20that%20same%20latent%20realization.%0A%0A%20%20%20%20%20%20%20%20%7C%20%7C%20This%20trajectory%20lesson%20%7C%20amortized-fractals%20%7C%0A%20%20%20%20%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%20%20%20%20%7C%20Inferred%20quantity%20%7C%20Parameters%20of%20a%20physical%20return%20model%20%7C%20MMAR%20parameters%2C%20including%20extensions%20for%20multiple%20assets%20and%20a%20fractional%20driver%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Time%20structure%20%7C%20Daily%20prefixes%20of%20one%20declared%20task%20%7C%20Fixed%20return%20windows%3B%20rolling-window%20applications%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Scenario%20calculation%20%7C%20Independent%20histories%20from%20the%20model's%20origin%20%7C%20New%20cascades%2Fphases%20and%20return%20innovations%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Filtered%20state%20continuation%20%7C%20Not%20trained%20%7C%20Not%20implemented%20in%20the%20inspected%20scenario%20helpers%20%7C%0A%0A%20%20%20%20%20%20%20%20The%20stock%20screener%20applies%20separate%20joint-parameter%20fits%20to%20individual%0A%20%20%20%20%20%20%20%20assets.%20Those%20independent%20asset%20fits%20do%20not%20specify%20cross-asset%0A%20%20%20%20%20%20%20%20dependence.%20The%20multivariate%20MMAR%20instead%20trains%20a%20joint%20model%20with%0A%20%20%20%20%20%20%20%20correlated%20innovations%20and%20shared%20cascade%20structure.%20Joint%20dependence%0A%20%20%20%20%20%20%20%20across%20parameter%20coordinates%2C%20across%20assets%20and%20across%20latent%20times%0A%20%20%20%20%20%20%20%20are%20three%20different%20modeling%20choices.%0A%0A%20%20%20%20%20%20%20%20The%20MMAR%20applications%20can%20still%20be%20evaluated%20prospectively%3A%20infer%20from%0A%20%20%20%20%20%20%20%20past%20data%2C%20choose%20a%20risk%20estimate%20or%20allocation%2C%20then%20score%20it%20on%20later%0A%20%20%20%20%20%20%20%20observations.%20This%20tests%20the%20usefulness%20of%20that%20restart-based%20rule%3B%20it%0A%20%20%20%20%20%20%20%20does%20not%20turn%20it%20into%20a%20state-conditioned%20continuation.%20A%20random%20phase%0A%20%20%20%20%20%20%20%20inside%20a%20finite%20cascade%20window%20is%20also%20not%2C%20by%20itself%2C%20a%20law%20for%20evolving%0A%20%20%20%20%20%20%20%20that%20cascade%20beyond%20the%20window.%0A%0A%20%20%20%20%20%20%20%20Inspect%20the%20source%0A%20%20%20%20%20%20%20%20%5Bforward%20scenario%20helper%5D(https%3A%2F%2Fgithub.com%2Fstefanradev93%2Famortized-fractals%2Fblob%2F069d5dc5943dbe85505849f2fa8bfb563617ff97%2Fmmar%2Funivariate.py%23L115)%2C%0A%20%20%20%20%20%20%20%20%5Brolling%20risk%20calculation%5D(https%3A%2F%2Fgithub.com%2Fstefanradev93%2Famortized-fractals%2Fblob%2F069d5dc5943dbe85505849f2fa8bfb563617ff97%2Fmmar%2Frisk.py%23L55)%0A%20%20%20%20%20%20%20%20and%20%5Ballocation%20backtest%5D(https%3A%2F%2Fgithub.com%2Fstefanradev93%2Famortized-fractals%2Fblob%2F069d5dc5943dbe85505849f2fa8bfb563617ff97%2Fmmar%2Fallocation.py%23L130).%0A%20%20%20%20%20%20%20%20The%20Hurst%20extension%20likewise%20resimulates%20a%20fractional%20driver%3B%20it%20does%0A%20%20%20%20%20%20%20%20not%20condition%20its%20future%20innovations%20on%20the%20observed%20past.%0A%20%20%20%20%20%20%20%20%22%22%22)%7D)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(cache_report%2C%20mo)%3A%0A%20%20%20%20mo.accordion(%7B%22Source%20and%20reproducibility%20details%22%3A%20mo.md(%0A%20%20%20%20%20%20%20%20%22The%20supplied%20examples%20use%20a%2064-unit%20causal%20GRU%2C%20a%2032-value%20summary%20and%20six%20spline%20%22%0A%20%20%20%20%20%20%20%20%22coupling%20layers.%20Saved%20example%20observations%20and%20paired%20draws%20are%20verified%20against%20%22%0A%20%20%20%20%20%20%20%20%22their%20task%20and%20checkpoint%20identities%3B%20final-test%20diagnostics%20describe%20a%20separate%20cohort.%20%20%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20f%22Checkpoint%20SHA-256%3A%20%60%7Bcache_report%5B'checkpoint_sha256'%5D%7D%60%20%20%5Cn%22%0A%20%20%20%20%20%20%20%20f%22Task%20SHA-256%3A%20%60%7Bcache_report%5B'task_sha256'%5D%7D%60%20%20%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%22An%20exported%20HTML%20file%20is%20a%20static%20preview.%20Run%20the%20notebook%20in%20marimo%20for%20controls%2C%20%22%0A%20%20%20%20%20%20%20%20%22optional%20training%20and%20new%20posterior%20calculations.%22)%7D)%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
235e8d037e5ef7820a6250a68d5c16b7