timeseries-julia-python

random julia and python scripts analyzing stock timeseries data

git clone https://9o.is/git/timeseries-julia-python.git

sample.jl

(1637B)


      1 using Indicators
      2 using PyPlot
      3 using Dates
      4 using Random
      5 
      6 # Generate some toy sample data
      7 Random.seed!(1)
      8 n = 250
      9 Open = 100.0 .+ cumsum(randn(n))
     10 High = Open .+ rand(n)
     11 Low = Open .- rand(n)
     12 Close = 100.0 .+ cumsum(randn(n))
     13 for i = 1:n
     14 	if Close[i] > High[i]
     15 		Close[i] = High[i]
     16 	elseif Close[i] < Low[i]
     17 		Close[i] = Low[i]
     18 	end
     19 end
     20 OHLC = [Open High Low Close]
     21 HLC = [High Low Close]
     22 HL = [High Low]
     23 t = collect(today():Day(1):today()+Day(n-1))
     24 
     25 # Overlays
     26 subplot(411)
     27 plot(t, Close, lw=2, c="k", label="Random Walk")
     28 # grid(ls="-", c=[0.8,0.8,0.8])
     29 # plot(t, sma(Close,n=40), c=[1,0.5,0], label="SMA (40)")
     30 # plot(t, ema(Close,n=10), c=[0,1,1], label="EMA (10)")
     31 # plot(t, wma(Close,n=20), c=[1,0,1], label="WMA (20)")
     32 # plot(t, psar(HL),   "bo", label="Parabolic SAR")
     33 # legend(loc="best", frameon=false)
     34 
     35 # # MACD
     36 # subplot(412)
     37 # plot(t, macd(Close)[:,1], label="MACD", c=[1,0.5,1])
     38 # plot(t, macd(Close)[:,2], label="Signal", c=[0.5,0.25,0.5])
     39 # bar(t, macd(Close)[:,3], align="center", label="Histogram", color=[0,0.5,0.5], alpha=0.25)
     40 # plot([t[1],t[end]], [0,0], ls="--", c=[0.5,0.5,0.5])
     41 # grid(ls="-", c=[0.8,0.8,0.8])
     42 # legend(loc="best", frameon=false)
     43 #
     44 # # RSI
     45 # subplot(413)
     46 # plot(t, rsi(Close), c=[0.5,0.5,0], label="RSI")
     47 # grid(ls="-", c=[0.8,0.8,0.8])
     48 # plot([t[1],t[end]], [30,30], c="g")
     49 # plot([t[1],t[end]], [70,70], c="r")
     50 # legend(loc="best", frameon=false)
     51 
     52 # ADX
     53 # subplot(414)
     54 # plot(t, adx(HLC)[:,1], "g-", label="DI+")
     55 # plot(t, adx(HLC)[:,2], "r-", label="DI-")
     56 # plot(t, adx(HLC)[:,3], c=[0,0,1], lw=2, label="ADX")
     57 # grid(ls="-", c=[0.8,0.8,0.8])
     58 # legend(loc="best", frameon=false)
     59 
     60 tight_layout()