timeseries-julia-python

random julia and python scripts analyzing stock timeseries data

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

template.jl

(1774B)


      1 using Dates
      2 
      3 const Ticker = String
      4 
      5 struct Market 
      6     symbol::Ticker
      7     description::String
      8     source::String
      9 
     10     function Market(symbol::String, description::String, source::String)
     11         new(symbol, description, source)
     12     end
     13 end
     14 
     15 Market(symbol::String) = Market(symbol, "", "")
     16 
     17 function search_market(query::String, by_description = true)::Array{Market}
     18     [Market("AAPL")]
     19 end
     20 
     21 abstract type Resolution end
     22 struct Minutely <: Resolution end
     23 struct Hourly <: Resolution end
     24 struct Daily <: Resolution end
     25 struct Weekly <: Resolution end
     26 struct Monthly <: Resolution end
     27 
     28 abstract type FinancialTimeSeries{T <: Resolution, N} end
     29 
     30 struct SingleColumnTimeSeries{T} <: FinancialTimeSeries{T,1}
     31     ta::Int
     32     function SingleColumnTimeSeries{T}() where {T <: Resolution}
     33         # asset input series has a one column only
     34         new()
     35     end
     36 end
     37 
     38 struct OhlcTimeSeries{T} <: FinancialTimeSeries{T,4}
     39     ta::Int
     40     function OhlcTimeSeries{T}() where {T <: Daily}
     41        # assert that input is actually a daily time series
     42        # @assert valid_ohlc(...)
     43        new()
     44     end
     45 end
     46 
     47 Base.propertynames(ts::OhlcTimeSeries) = [:Open, :High, :Low, :Close]
     48 Base.getproperty(ts::OhlcTimeSeries{T}, s::Symbol) where T = SingleColumnTimeSeries{T}() # get H,L,O, or C
     49 
     50 function valid_ohlc(ts::FinancialTimeSeries)
     51     # check if Open, etc columns exist and the values of float32+
     52 end
     53 
     54 
     55 # TimeType can be more specific if it's parametric to the resolution
     56 function daily_ohlc(market::Market, start_date::Date, end_date::Date) 
     57     # query broker
     58     # build timeseries object
     59     # maybe collapse data
     60     OhlcTimeSeries{Daily}()
     61 end
     62 
     63 ema(ts::FinancialTimeSeries{<:Resolution,1}, n::Int) = 0
     64 
     65 ts = daily_ohlc(Market("AAPL"), Date(1990), Date(2000))
     66 ta = ema(ts.Open, 10)
     67