{"spec_id":"line-stock-comparison","library":"makie","language":"julia","code":"# anyplot.ai\n# line-stock-comparison: Stock Price Comparison Chart\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 89/100 | Created: 2026-05-23\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# Theme tokens\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\nconst IMPRINT = [\n    colorant\"#009E73\",  # 1 — brand green  (NVDA)\n    colorant\"#C475FD\",  # 2 — purple       (AAPL)\n    colorant\"#AE3030\",  # 3 — red          (AMZN)\n    colorant\"#4467A3\",  # 4 — sky blue     (SPY)\n]\n\n# Data: 252 trading days (~1 year) for 4 assets, normalized to 100\nconst N_DAYS  = 252\nconst TICKERS = [\"NVDA\", \"AAPL\", \"AMZN\", \"SPY\"]\n\n# (daily drift, daily volatility) — geometric Brownian motion\nconst GBM_PARAMS = [\n    (0.0018, 0.038),   # NVDA: high-growth tech, elevated vol\n    (0.0007, 0.019),   # AAPL: steady large-cap\n    (0.0005, 0.023),   # AMZN: moderate growth, higher vol\n    (0.0003, 0.012),   # SPY:  broad-market benchmark\n]\n\nprices = Matrix{Float64}(undef, N_DAYS, 4)\nfor (j, (μ, σ)) in enumerate(GBM_PARAMS)\n    p = fill(100.0, N_DAYS)\n    for i in 2:N_DAYS\n        p[i] = p[i-1] * (1.0 + μ + σ * randn())\n    end\n    prices[:, j] = p\nend\n\ndays = 1:N_DAYS\n\n# Approximate month tick positions (≈21 trading days per month, 2024)\nmonth_ticks  = [1, 22, 43, 64, 85, 106, 127, 148, 169, 190, 211, 232]\nmonth_labels = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\",\n                \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\n\n# Semi-transparent colors for grid and reference line\nink_r = Float32(red(INK))\nink_g = Float32(green(INK))\nink_b = Float32(blue(INK))\ngrid_col = RGBAf(ink_r, ink_g, ink_b, 0.15f0)\nref_col  = RGBAf(ink_r, ink_g, ink_b, 0.40f0)\n\n# Figure\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"line-stock-comparison · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"2024 (Daily Close)\",\n    ylabel             = \"Rebased Performance (Start = 100)\",\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    xgridvisible       = false,\n    ygridcolor         = grid_col,\n    xminorgridvisible  = false,\n    yminorgridvisible  = false,\n    xticks             = (month_ticks, month_labels),\n)\n\n# Horizontal reference line at 100 (common starting point)\nhlines!(ax, [100.0]; color = ref_col, linewidth = 1.2, linestyle = :dash)\n\n# Stock series lines\nfor j in 1:4\n    lines!(ax, days, prices[:, j];\n        color     = IMPRINT[j],\n        linewidth = 2.5,\n        label     = TICKERS[j],\n    )\nend\n\n# End-of-series value labels (final rebased performance)\nxlims!(ax, 1, N_DAYS + 25)\nfor j in 1:4\n    final_val = prices[end, j]\n    text!(ax, N_DAYS + 3, final_val;\n        text     = string(round(Int, final_val)),\n        color    = IMPRINT[j],\n        fontsize = 11,\n        align    = (:left, :center),\n    )\nend\n\n# Legend (right column, external to plot)\nLegend(fig[1, 2], ax;\n    labelcolor      = INK,\n    framevisible    = false,\n    backgroundcolor = ELEVATED_BG,\n    labelsize       = 12,\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}