Skip to content

Instantly share code, notes, and snippets.

@dralletje
Last active March 20, 2025 10:52
Show Gist options
  • Save dralletje/99b08c2ed3c8736b96806747ba675bc6 to your computer and use it in GitHub Desktop.
Save dralletje/99b08c2ed3c8736b96806747ba675bc6 to your computer and use it in GitHub Desktop.
# ╔═╡ 0518f61d-daa5-4d9d-a953-d05d8e1f2870
import HypertextLiteral: @htl
# ╔═╡ 35f8353a-6fd6-4d66-8a76-17b3c51bc1ad
import Printf: @sprintf
# ╔═╡ 938f5064-ace6-4614-a6ec-b1b555d4fb1e
function displayround(number::Number; digits::Number)
@htl """
<div style=$(Dict(
"text-align" => "right"
))>
$(@sprintf("%.*f", digits, number))
</div>
"""
end
# ╔═╡ f1633586-bcef-4e5e-a97d-1accba94dfa4
function displaytable(columns::Pair...)
@assert(
length(columns) > 0,
"Need at least one column!!"
)
column_length = length(columns[begin].second)
@assert(
all(columns) do column
length(column.second) == column_length
end,
"All columns should have the same length"
)
data = zip([column.second for column in columns]...)
@htl """
<table>
<thead>
<tr>
$(map(columns) do pair
@htl "<th style=$(Dict(
"white-space" => "nowrap",
))>$(pair.first)</th>"
end)
</tr>
</thead>
<tbody>
<tr>
$(map(data) do row
@htl "<tr>
$(map(row) do cell
@htl "<td style=$(Dict(
"font-size" => "0.9rem",
"white-space" => "nowrap",
))>$(cell)</td>"
end)
</tr>"
end)
</tr>
</tbody>
</table>
"""
end
# ╔═╡ 9ea26373-3edf-4faa-9de6-c8a2b4682a21
displaytable(
md"$\frac{\text{VaR}(w)}{\partial w_i}$" => [
0.628,
0.173,
0.369,
0.9000001,
],
md"$\frac{\text{ES}(w)}{\partial w_i}$" => [
-0.898,
0.662,
0.654,
pi
] |> table -> displayround.(table, digits=2)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment