Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OHLC charts #89

Merged
merged 7 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/chart/gallery/ohlc_candle.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
data = [
[~N[2023-12-28 00:00:00], "AAPL", 34049900, 194.14, 194.66, 193.17, 193.58],
[~N[2023-12-27 00:00:00], "AAPL", 48087680, 192.49, 193.50, 191.09, 193.15],
[~N[2023-12-26 00:00:00], "AAPL", 28919310, 193.61, 193.89, 192.83, 193.05],
[~N[2023-12-25 00:00:00], "AAPL", 37149570, 195.18, 195.41, 192.97, 193.60],
[~N[2023-12-24 00:00:00], "AAPL", 46482550, 196.10, 197.08, 193.50, 194.68],
[~N[2023-12-23 00:00:00], "AAPL", 52242820, 196.90, 197.68, 194.83, 194.83],
[~N[2023-12-22 00:00:00], "AAPL", 40714050, 196.16, 196.95, 195.89, 196.94],
[~N[2023-12-21 00:00:00], "AAPL", 55751860, 196.09, 196.63, 194.39, 195.89]
]

test_data = Dataset.new(data, ["Date", "Ticker", "Volume", "Open", "High", "Low", "Close"])

options = [
mapping: %{datetime: "Date", open: "Open", high: "High", low: "Low", close: "Close"},
style: :candle,
title: "AAPL"
]

Contex.Plot.new(test_data, Contex.OHLC, 500, 400, options)
|> Contex.Plot.titles("Apple Stock Price", "")
|> Contex.Plot.axis_labels("", "")
|> Contex.Plot.plot_options(%{})
30 changes: 30 additions & 0 deletions lib/chart/gallery/ohlc_charts.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule Contex.Gallery.OHLCCharts do
import Contex.Gallery.Sample, only: [graph: 1]

@moduledoc """
A gallery of OHLC Charts.

> #### Have one to share? {: .warning}
>
> Do you have an interesting plot you want to
> share? Something you learned the hard way that
> should be here, or that's just great to see?
> Just open a ticket on GitHub and we'll post it here.


"""

@doc """
Some OHLC charts.


#{graph(title: "A simple candle OHLC chart",
file: "ohlc_candle.sample")}

#{graph(title: "A simple tick OHLC chart",
file: "ohlc_tick.sample")}


"""
def plain(), do: 0
end
23 changes: 23 additions & 0 deletions lib/chart/gallery/ohlc_tick.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
data = [
[~N[2023-12-28 00:00:00], "AAPL", 34049900, 193.58, 194.14, 194.66, 193.17],
[~N[2023-12-27 00:00:00], "AAPL", 48087680, 193.15, 192.49, 193.50, 191.09],
[~N[2023-12-26 00:00:00], "AAPL", 28919310, 193.05, 193.61, 193.89, 192.83],
[~N[2023-12-25 00:00:00], "AAPL", 37149570, 193.60, 195.18, 195.41, 192.97],
[~N[2023-12-24 00:00:00], "AAPL", 46482550, 194.68, 196.10, 197.08, 193.50],
[~N[2023-12-23 00:00:00], "AAPL", 52242820, 194.83, 196.90, 197.68, 194.83],
[~N[2023-12-22 00:00:00], "AAPL", 40714050, 196.94, 196.16, 196.95, 195.89],
[~N[2023-12-21 00:00:00], "AAPL", 55751860, 195.89, 196.09, 196.63, 194.39]
]

test_data = Dataset.new(data, ["Date", "Ticker", "Volume", "Close", "Open", "High", "Low"])

options = [
mapping: %{datetime: "Date", open: "Open", high: "High", low: "Low", close: "Close"},
style: :tick,
title: "AAPL"
]

Contex.Plot.new(test_data, Contex.OHLC, 500, 400, options)
|> Contex.Plot.titles("Apple Stock Price", "")
|> Contex.Plot.axis_labels("", "")
|> Contex.Plot.plot_options(%{})
Loading
Loading