{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Monte Carlo Simulation of a Stock Price over 1 Year Horizon",
"data": {
"sequence": {
"start": 0,
"stop": 25000,
"step": 1,
"as": "index"
}
},
"transform": [
{
"calculate": "floor(datum.index / 250)",
"as": "scenario"
},
{
"calculate": "datum.index % 250",
"as": "t"
},
{
"calculate": "50 * exp((0.03 - 0.05 * 0.05 / 2) * datum.t / 250 + 0.05 * sqrt(datum.t / 250) * sampleNormal(0, 1))",
"as": "price"
},
{
"calculate": "datum.t == 10 ? datum.price : null",
"as": "price_t10"
},
{
"calculate": "datum.t == 99 ? datum.price : null",
"as": "price_t100"
},
{
"calculate": "datum.t == 249 ? datum.price : null",
"as": "price_t250"
}
],
"hconcat": [
{
"width": 250,
"height": 250,
"title": "Simulation of a Stock Price over 1 Year Horizon",
"mark": {
"type": "line",
"opacity": 0.1
},
"encoding": {
"x": {
"field": "t",
"type": "quantitative",
"title": "Time Step"
},
"y": {
"field": "price",
"type": "quantitative",
"title": "Stock Price",
"scale": {
"domain": [
35,
65
]
}
},
"color": {
"field": "scenario",
"type": "nominal",
"scale": {
"scheme": "category20"
},
"legend": null
},
"detail": {
"field": "scenario"
}
}
},
{
"width": 250,
"height": 250,
"title": "T=10 Value Distribution",
"transform": [
{
"filter": "datum.price_t10 != null"
}
],
"mark": "bar",
"encoding": {
"x": {
"field": "price_t10",
"type": "quantitative",
"bin": {
"maxbins": 20
},
"title": "Stock Price",
"scale": {
"domain": [
35,
65
]
}
},
"y": {
"aggregate": "count",
"title": "Frequency"
}
}
},
{
"width": 250,
"height": 250,
"title": "T=1 Value Distribution",
"transform": [
{
"filter": "datum.price_t100 != null"
}
],
"mark": "bar",
"encoding": {
"x": {
"field": "price_t100",
"type": "quantitative",
"bin": {
"maxbins": 20
},
"title": "Stock Price",
"scale": {
"domain": [
35,
65
]
}
},
"y": {
"aggregate": "count",
"title": "Frequency"
}
}
},
{
"width": 250,
"height": 250,
"title": "T=250 Value Distribution",
"transform": [
{
"filter": "datum.price_t250 != null"
}
],
"mark": "bar",
"encoding": {
"x": {
"field": "price_t250",
"type": "quantitative",
"bin": {
"maxbins": 20
},
"title": "Stock Price",
"scale": {
"domain": [
35,
65
]
}
},
"y": {
"aggregate": "count",
"title": "Frequency"
}
}
}
]
}