LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.
Streamlit turns a Python script into a page of widgets and charts without a separate front end. The lesson uses it to draw geometric Brownian motion paths from the qfin library, with sliders for the inputs. A starting-price slider runs from 0 to 100, begins at 50, and moves in steps of 5. The page is a line chart of one path per column. It is a small interactive tool, on the order of twenty lines, and it is not a multi-route application of the kind Flask or Django would host.
Why it matters
A simulator with hard-coded inputs has to be edited and rerun to answer "what if volatility is higher?" A slider answers that by rerunning the script with the new value and redrawing the chart. Streamlit's bargain is that the widget and the chart live in the same file as the simulation. The lesson's contrast is explicit. If you need a full set of GET and POST routes, use the Flask or Django material. If you need to poke at a model, a Streamlit script is enough.
The idea in plain words
Install qfin and Streamlit. The script imports pandas, Streamlit, and geometric Brownian motion from qfin's simulations. A with-block on st.echo, with the code location set to below, shows the widget code on the page and runs it. Inside that block each parameter is a slider. The one written out in full is the initial price: label, minimum 0, maximum 100, starting value 50, step 5. The lesson says to repeat that pattern for the other inputs of the simulator and does not read out their bounds.
The simulation writes into a dataframe. A loop runs n times. Each pass calls the geometric Brownian motion routine and stores the returned path as a column. The call divides the drift slider and the volatility slider by 100, because the lesson says qfin wants those inputs in decimal form while the sliders are quoted in percent. The time step is 1/252. The horizon passed in is the horizon slider divided by 12, so that control is being read as a count of months. After the loop, st.line_chart receives the dataframe. From the project folder the command is streamlit run, followed by the script name. The lesson's file is named as a Streamlit example script. The tool serves the page, and moving a slider redraws the fan.
How to use it
Create the script, save it, and run the streamlit command against that filename. The browser view has the sliders and the chart. Raising the volatility slider spreads the paths. Raising the drift slider tilts them. Lengthening the horizon extends them. Lowering volatility makes the drift easier to see, which is the comparison the lesson suggests you try. The echo block is optional for a private tool. It is how the lesson keeps the widget code visible under the controls.
The path routine is the library's, not a new derivation. The app's job is the wiring: slider values in, a column per path, a line chart out. Choosing n sets how many lines appear. The lesson leaves n as one of the parameters inside the same pattern.
What usually goes wrong
Forgetting the division by 100 feeds a percent where the routine expects a decimal. A slider sitting on 30 becomes a volatility of 30 instead of 0.30, and the chart explodes. Forgetting the division by 12 on the horizon feeds a month count in as a year count and stretches the fan.
A full step of 1/252 paired with a horizon that is not in years will not match the 252-step comment. The lesson's combination is a yearly step size and a horizon converted from months.
Streamlit reruns the file from top to bottom on each widget change. A slow path count delays every slider move. The lesson's chart is a classroom fan, not a large Monte Carlo. If the page is meant to be a production dashboard with many routes, the lesson points you back to Flask or Django instead of adding that structure here.
The echo block displays the code below the widgets only when the location argument says so. A typo in the script name passed to streamlit run starts nothing. The command is typed in the folder that contains the file.
Questions people ask
What does the price slider allow?
Values from 0 to 100, starting at 50, in steps of 5, labeled as the initial stock price.
Why divide drift and volatility by 100?
The sliders are in percent. The lesson divides by 100 before calling qfin, which expects the decimal form.
How is the page started?
With streamlit run and the script filename, from the directory that contains the file. The library serves the chart and the sliders.