Skip to content
This repository was archived by the owner on May 31, 2023. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We try to minimize dependencies to make it easy to install and run locally.
Join us on [Discord](https://discord.gg/qBWD5Sus3d) for any question you might have.
Use [Github Issues](https://github.com/Tyruiop/syncretism/issues) for bug reports & feature requests.

## Crawler `/datops-crawler`
## Crawler `/syncretism-crawler`

This crawlers targets **Yahoo Finance** market data to extract options related information.

Expand Down
4 changes: 2 additions & 2 deletions syncretism-crawler/resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
;; Where to save the options data
:save-path "options"

;; Risk free interest rate (ask google)
:risk-free 0.0154
;; St. Louis FRED api key
:fred-api-key "ENTER KEY"
}
1 change: 1 addition & 0 deletions syncretism-crawler/src/syncretism/crawler/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
(if (= "--init" (first args))
(db/init-db)
(do
(shared/rfr-crawler)
(options/init-queue)
(future (fundamentals/crawler))
(future (options/crawler)))))
Expand Down
39 changes: 37 additions & 2 deletions syncretism-crawler/src/syncretism/crawler/shared.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,55 @@
[clojure.data.csv :as csv]
[taoensso.timbre :as timbre :refer [info warn error]]
[taoensso.timbre.appenders.core :as appenders]
[miner.ftp :as ftp]))
[miner.ftp :as ftp]
[clojure.data.json :as json]
[clj-http.client :as http]))

(def state
(atom
{;; possible status: `:running`, `:paused`, `:terminate`
:fundamentals-status :paused
:options-status :running}))
:options-status :running
:rfr-status :running}))

(timbre/merge-config!
{:appenders {:println {:enabled? false}
:spit (appenders/spit-appender {:fname "opts-crawler.log"})}})

(def config (-> "resources/config.edn" slurp read-string))

;; rfr returns historical rfr data from St. Louis FRED (for later use)
(defn rfr
[]
(-> (str "https://api.stlouisfed.org/fred/series/observations?series_id=DGS10&api_key=" (:fred-api-key @config) "&file_type=json")
http/get
:body
(json/read-str :key-fn keyword)))

(defn rfr-crawler
[]
(def risk-free-rate (atom "Not Crawled"))
(case (:rfr-status @state)
:running
(do
(println (format "Gathering the Risk Free Rate"))
(try
(reset! risk-free-rate (atom rfr))
(catch Exception e (warn "Error with Risk Free Rate")))
(Thread/sleep (* 24 60 60 1000))
(recur))

:paused
(do
(Thread/sleep (* 10 1000))
(recur))

:terminate
(do
(info "Terminating Risk Free Rate crawler.")
:done))
)

;; GETTING SYMBOLS LIST
;; --------------------
;; All date is sourced from http://www.nasdaqtrader.com/trader.aspx?id=symboldirdefs
Expand Down
12 changes: 5 additions & 7 deletions syncretism/src/syncretism/greeks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
(:require
[fastmath.random :as fr]))

;; Risk free interest rate,
(def rfr 0.0154)
(def cdf-normal (fn [x] (fr/cdf (fr/distribution :normal) x)))

(defn calc-annual-yield
Expand All @@ -22,13 +20,13 @@
(defn calc-d1
[{s0 :stock-price q :yield X :strike t :t v :impliedVolatility :as data}]
(/ (+ (Math/log (/ s0 X))
(* t (+ (- rfr q) (/ (Math/pow v 2) 2))))
(* t (+ (- risk-free-rate q) (/ (Math/pow v 2) 2))))
(* v (Math/sqrt t))))
(defn calc-d2 [d1 v t] (- d1 (* v (Math/sqrt t))))

(defn calc-premium
[{opt-type :opt-type X :strike s0 :stock-price eqt :eqt d1 :d1 d2 :d2 t :t q :yield}]
(let [xert (* X (Math/exp (- (* rfr t))))
(let [xert (* X (Math/exp (- (* risk-free-rate t))))
s0eqt (* s0 eqt)]
(cond (= opt-type "C")
(- (* s0eqt (cdf-normal d1)) (* xert (cdf-normal d2)))
Expand Down Expand Up @@ -57,7 +55,7 @@
(let [p1 (- (/
(* s0 v eqt (Math/exp (- (/ (* d1 d1) 2))))
(* 2 (Math/sqrt t) (Math/sqrt (* 2 Math/PI)))))
p2 (* rfr X (Math/exp (- (* rfr t))))
p2 (* risk-free-rate X (Math/exp (- (* risk-free-rate t))))
p3 (* q s0 eqt)]
(*
(/ 1 365)
Expand All @@ -75,7 +73,7 @@

(defn calc-rho
[{opt-type :opt-type X :strike t :t d2 :d2}]
(let [xtert (* X t (Math/exp (- (* rfr t))))]
(let [xtert (* X t (Math/exp (- (* risk-free-rate t))))]
(cond (= opt-type "C")
(/ (* xtert (cdf-normal d2)) 100)

Expand All @@ -99,6 +97,6 @@
[:rho (calc-rho full-data)]
[:premium (calc-premium full-data)]
[:dividendYield q]
[:rfr rfr]]
[:rfr risk-free-rate]]
(filter #(-> % last Double/isNaN not))
(into {}))))