Skip to content

Commit

Permalink
added dev project
Browse files Browse the repository at this point in the history
  • Loading branch information
wizard50 committed Oct 12, 2024
1 parent e450506 commit 6f23bd0
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/calendar/dev/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:paths ["src" "test"]
:deps {io.github.clojure-quant/quanta {:local/root "../" :deps/manifest :deps}
}

}
28 changes: 28 additions & 0 deletions lib/calendar/dev/src/dev/calendar_helper.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns dev.calendar-helper
(:require [tick.core :as t]
[ta.calendar.calendars :refer [calendars]]
[ta.helper.date :refer [at-time same-date?]]
[ta.calendar.helper :refer [next-day-at-midnight time-open?]]
[dev.utils :refer [to-utc]]))

(def dt (to-utc "2024-02-08T23:59:00"))
(def next-day (t/>> dt (t/new-duration 1 :days)))

(at-time (t/date next-day)
(t/new-time 0 0 0) "UTC")
;=> #time/zoned-date-time"2024-02-09T00:00Z[UTC]"

(next-day-at-midnight {:timezone "UTC"} dt)
;=> #time/zoned-date-time"2024-02-09T00:00Z[UTC]"

(time-open? (:eu calendars) (to-utc "2024-10-11T16:00:00"))
;=> true
(time-open? (:eu calendars) (t/instant))


(time-open? (:us calendars) (to-utc "2024-10-11T16:00:00"))
;=> false
(time-open? (:us calendars) (t/instant))

(t/time (to-utc "2024-10-11T16:00:00"))
(t/time (t/instant))
108 changes: 108 additions & 0 deletions lib/calendar/dev/src/dev/calendar_seq.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
(ns dev.calendar-seq
(:require
[tick.core :as t]
[ta.calendar.core :refer [trailing-window calendar-seq fixed-window
close->open-dt open->close-dt]]
[ta.calendar.calendars :refer [calendars]]
[dev.utils :refer [to-utc]]))


(->> (t/in (t/date-time "2024-10-01T16:20:00") "America/New_York")
(calendar-seq :forex :d)
(take 15))
;=>
;(#time/zoned-date-time"2024-09-30T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-03T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-04T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-07T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-08T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-09T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-10T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-11T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-14T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-15T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-16T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-17T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-18T16:30-04:00[America/New_York]")

(->> (t/in (t/date-time "2024-10-01T17:32:00") "America/New_York")
(calendar-seq :forex :h)
(take 15))
;=>
;(#time/zoned-date-time"2024-10-01T16:30-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T18:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T19:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T20:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T21:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T22:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T23:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T00:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T01:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T02:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T03:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T04:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T05:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T06:00-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-02T07:00-04:00[America/New_York]")

(->> (t/in (t/date-time "2024-10-01T17:32:00") "America/New_York")
(calendar-seq :forex :m)
(take 15))
;=>
;(#time/zoned-date-time"2024-10-01T17:32-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:33-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:34-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:35-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:36-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:37-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:38-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:39-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:40-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:41-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:42-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:43-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:44-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:45-04:00[America/New_York]"
; #time/zoned-date-time"2024-10-01T17:46-04:00[America/New_York]")

(->> (t/in (t/date-time "2024-02-09T00:00:00") "America/New_York")
(calendar-seq :forex :h4)
(take 15))
;=>
;(#time/zoned-date-time"2024-02-08T21:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-09T01:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-09T05:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-09T09:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-09T13:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T21:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-12T01:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-12T05:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-12T09:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-12T13:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-12T21:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-13T01:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-13T05:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-13T09:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-13T13:00-05:00[America/New_York]")

(->> (t/in (t/date-time "2024-02-11T06:00:00") "America/New_York")
(calendar-seq :forex :m15)
(take 15))
;=>
;(#time/zoned-date-time"2024-02-09T16:30-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T17:15-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T17:30-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T17:45-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T18:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T18:15-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T18:30-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T18:45-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T19:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T19:15-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T19:30-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T19:45-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T20:00-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T20:15-05:00[America/New_York]"
; #time/zoned-date-time"2024-02-11T20:30-05:00[America/New_York]")
65 changes: 65 additions & 0 deletions lib/calendar/dev/src/dev/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(ns dev.core
(:require
[tick.core :as t]
[ta.calendar.calendars :refer [calendars]]
[ta.calendar.interval :refer [intervals]]
[ta.calendar.core :refer [close->open-dt open->close-dt current-close2]]
[dev.utils :refer [to-utc]]))

(current-close2 [:crypto :m]
(t/in (t/date-time "2024-02-08T23:59:30") "UTC"))
;=> #time/zoned-date-time"2024-02-08T23:59Z[UTC]"

(current-close2 [:crypto :m]
(t/in (t/date-time "2024-02-08T23:59:59") "UTC"))
;=> #time/zoned-date-time"2024-02-08T23:59Z[UTC]"

(current-close2 [:crypto :m]
(t/in (t/date-time "2024-02-09T00:00:00") "UTC"))
;=> #time/zoned-date-time"2024-02-08T23:59:59.999999999Z[UTC]"

(let [calendar (:us calendars)
interval (:m intervals)
prior-open-dt (:prior-open interval)]
(prior-open-dt calendar (t/in (t/date-time "2024-02-06T17:00") "America/New_York")))
;=> #time/zoned-date-time"2024-02-06T16:59-05:00[America/New_York]"

; TODO: bug
(let [calendar (:forex calendars)
interval (:h intervals)
prior-open-dt (:prior-open interval)]
(prior-open-dt calendar (t/in (t/date-time "2024-02-08T16:30") "America/New_York")))
;=> #time/zoned-date-time"2024-02-02T15:30-05:00[America/New_York]"

; TODO: bug
(let [calendar (:forex calendars)
interval (:h intervals)
prior-open-dt (:prior-open interval)]
(prior-open-dt calendar (t/in (t/date-time "2024-02-06T17:00") "America/New_York")))
;=> #time/zoned-date-time"2024-02-02T15:30-05:00[America/New_York]"

; TODO bug
(let [calendar (:forex calendars)
interval (:h intervals)
next-open-dt (:next-open interval)]
(next-open-dt calendar (t/in (t/date-time "2024-02-06T15:30") "America/New_York")))
;=> #time/zoned-date-time"2024-02-07T17:00-05:00[America/New_York]"

; TODO bug
(let [calendar (:forex calendars)
interval (:h intervals)
prior-close-dt (:prior-close interval)]
(prior-close-dt calendar (t/in (t/date-time "2024-02-06T17:00") "America/New_York")))
;=> #time/zoned-date-time"2024-02-06T16:00-05:00[America/New_York]"

(let [calendar (:forex calendars)
interval (:h intervals)
prior-close-dt (:prior-close interval)]
(prior-close-dt calendar (t/in (t/date-time "2024-02-06T16:00") "America/New_York")))
;=> #time/zoned-date-time"2024-02-06T15:00-05:00[America/New_York]"

(let [calendar (:us calendars)
interval (:d intervals)
next-close-dt (:next-close interval)]
(next-close-dt calendar (t/in (t/date-time "2024-02-06T15:30") "America/New_York")))
;=> #time/zoned-date-time"2024-02-06T17:00-05:00[America/New_York]"
129 changes: 129 additions & 0 deletions lib/calendar/dev/src/dev/open_close_conversion.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
(ns dev.open-close-conversion
(:require
[ta.calendar.core :refer [close->open-dt open->close-dt]]
[dev.utils :refer [to-utc]]
[tick.core :as t]
[ta.calendar.core :refer [fixed-window]]))

;2024-02-08 => Thu
(close->open-dt [:us :m] (t/in (t/date-time "2024-02-09T12:34") "America/New_York"))
;=> #time/zoned-date-time"2024-02-09T12:33-05:00[America/New_York]"

(close->open-dt [:us :m] (t/in (t/date-time "2024-02-08T17:00") "America/New_York"))
;=> #time/zoned-date-time"2024-02-08T16:59-05:00[America/New_York]"

(close->open-dt [:us :d] (t/in (t/date-time "2024-02-08T17:00") "America/New_York"))
;=> #time/zoned-date-time"2024-02-08T09:00-05:00[America/New_York]"

; edge cases - day close crypto
(open->close-dt [:crypto :m] (to-utc "2024-02-08T23:58:00"))
;=> #time/zoned-date-time"2024-02-08T23:59Z[UTC]"

(open->close-dt [:crypto :m] (to-utc "2024-02-08T23:59:00"))
;=> #time/zoned-date-time"2024-02-08T23:59:59.999999999Z[UTC]"

(open->close-dt [:crypto :m] (to-utc "2024-02-09T00:00:00"))
;=> #time/zoned-date-time"2024-02-09T00:01Z[UTC]"

(close->open-dt [:crypto :m] (to-utc "2024-02-08T23:59:59.999999999"))
;=> #time/zoned-date-time"2024-02-08T23:59Z[UTC]"

;;
;; 16:25 - 16:30
(def open-dt-window-crypto-m__16-25 (fixed-window [:crypto :m] {:start (to-utc "2024-02-09T16:25:00")
:end (to-utc "2024-02-09T16:29:00")}))
(vec open-dt-window-crypto-m__16-25)
;=>
;[#time/zoned-date-time"2024-02-09T16:29Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:28Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:27Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:26Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:25Z[UTC]"]

(map #(open->close-dt [:crypto :m] %) open-dt-window-crypto-m__16-25)
;=>
;(#time/zoned-date-time"2024-02-09T16:30Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:29Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:28Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:27Z[UTC]"
; #time/zoned-date-time"2024-02-09T16:26Z[UTC]")


;;
;; 00:00 - 00:05
(def open-dt-window-crypto-m__00-00 (-> (fixed-window [:crypto :m] {:start (to-utc "2024-02-09T00:00:00")
:end (to-utc "2024-02-09T00:04:00")})
(concat [(to-utc "2024-02-09T00:00:00")])
(vec)))
; NOTE: we are generating the date-times with close iterator functions. 00:00 is no close time, this is why its missing and we have to add it explicit
(vec (concat open-dt-window-crypto-m__00-00))
;=>
;[#time/zoned-date-time"2024-02-09T00:04Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:03Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:02Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:01Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:00Z[UTC]"]

(map #(open->close-dt [:crypto :m] %) open-dt-window-crypto-m__00-00)
;=>
;(#time/zoned-date-time"2024-02-09T00:05Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:04Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:03Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:02Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:01Z[UTC]")


;;
;; 23:55 - 23:59:59.999
(def open-dt-window-crypto-m__23-55 (fixed-window [:crypto :m] {:start (to-utc "2024-02-08T23:55:00")
:end (to-utc "2024-02-08T23:59:00")}))
(vec open-dt-window-crypto-m__23-55)
;=>
;[#time/zoned-date-time"2024-02-08T23:59Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:58Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:57Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:56Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:55Z[UTC]"]

(map #(open->close-dt [:crypto :m] %) open-dt-window-crypto-m__23-55)
;=>
;(#time/zoned-date-time"2024-02-08T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:59Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:58Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:57Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:56Z[UTC]")


;;
;; 23:55 - 00:05
; NOTE: we are generating the date-times with close iterator functions. 00:00 is no close time, this is why its missing and we have to add it explicit
(def open-dt-window-crypto-m__23-55-00-05 (concat (fixed-window [:crypto :m] {:start (to-utc "2024-02-09T00:00:00")
:end (to-utc "2024-02-09T00:04:00")})
[(to-utc "2024-02-09T00:00:00")]
(fixed-window [:crypto :m] {:start (to-utc "2024-02-08T23:55:00")
:end (to-utc "2024-02-08T23:59:00")})))
(vec open-dt-window-crypto-m__23-55-00-05)
;=>
;[#time/zoned-date-time"2024-02-09T00:04Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:03Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:02Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:01Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:59Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:58Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:57Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:56Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:55Z[UTC]"]

(map #(open->close-dt [:crypto :m] %) open-dt-window-crypto-m__23-55-00-05)
;=>
;(#time/zoned-date-time"2024-02-09T00:05Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:04Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:03Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:02Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:01Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:59Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:58Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:57Z[UTC]"
; #time/zoned-date-time"2024-02-08T23:56Z[UTC]")
5 changes: 5 additions & 0 deletions lib/calendar/dev/src/dev/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns dev.utils
(:require [tick.core :as t]))

(defn to-utc [dt-str]
(t/in (t/date-time dt-str) "UTC"))

0 comments on commit 6f23bd0

Please sign in to comment.