Last active
July 5, 2021 22:42
-
-
Save flare9x/eae1d62d0fea33f1acd8a96c783c5ff8 to your computer and use it in GitHub Desktop.
Using Plots Julia Package - Plot Finance OHLC data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CSV, DataFrames, Plots | |
# load data | |
data = CSV.read("D:/Model Book/pattern recognition/data_store/MOXC.csv",header=true) | |
# Prepare data for OHLC plot | |
n = size(data,1) | |
high_p = Float64.(data.high) | |
low_p = Float64.(data.low) | |
open_p = Float64.(data.open) | |
close_p = Float64.(data.close) | |
volume = Float64.(data.volume) | |
# get dimensions of the data (just for subsetting) | |
dim1 = size(data,1) | |
half_dim = Int64.(round(dim1/2,digits=0)) | |
# create OHLC vector for the plot | |
y = OHLC[(open_p[i],high_p[i],low_p[i],close_p[i]) for i = 1:size(high_p,1)] | |
y = y[1750:size(y,1)] # subset OHLC range | |
volume = volume[1750:size(volume,1)] | |
# plot the OHLC chart | |
p1 = ohlc(y,widen=true) | |
p2 = bar(volume, widen=true) | |
plot(p1,p2, layout = (2, 1), link= :x) # link the x axis on the subplots | |
vline!([30]) | |
#annotate!([(7,3,"(7,3)"),(3,7,text("hey", 14, :left, :top, :green))]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment