Liking cljdoc? Tell your friends :D

clojure-backtesting.yahoo

Yahoo Finance as a data source, through clj-yfinance.

Three steps, each usable on its own:

(download-yahoo! "data/tech" ["AAPL" "MSFT" "NVDA" "SPY"] :start "2015-01-01") (build-yahoo-dataset! "data/tech") (load-yahoo-dataset "data/tech")

download-yahoo! saves what Yahoo returns, unchanged, as one snapshot per security and download under <dir>/raw; nothing is lost by building, and later downloads add snapshots rather than replace them, so the fundamentals history grows beyond the few years Yahoo shows at a time. build-yahoo-dataset! turns the snapshots into the backtester's layout (see clojure-backtesting.yahoo.build), offline. load-yahoo-dataset loads prices as the main dataset and the point-in-time fundamentals (see clojure-backtesting.fundamentals).

Yahoo only has securities that still trade, so a universe picked today leaves out the companies that failed or were taken over since: results carry survivorship bias. Its statements cover about four fiscal years and five quarters, and its values are as restated today, not as first reported.

Yahoo Finance as a data source, through clj-yfinance.

Three steps, each usable on its own:

  (download-yahoo! "data/tech" ["AAPL" "MSFT" "NVDA" "SPY"] :start "2015-01-01")
  (build-yahoo-dataset! "data/tech")
  (load-yahoo-dataset "data/tech")

download-yahoo! saves what Yahoo returns, unchanged, as one snapshot per
security and download under <dir>/raw; nothing is lost by building, and
later downloads add snapshots rather than replace them, so the
fundamentals history grows beyond the few years Yahoo shows at a time.
build-yahoo-dataset! turns the snapshots into the backtester's layout
(see clojure-backtesting.yahoo.build), offline. load-yahoo-dataset
loads prices as the main dataset and the point-in-time fundamentals (see
clojure-backtesting.fundamentals).

Yahoo only has securities that still trade, so a universe picked today
leaves out the companies that failed or were taken over since: results
carry survivorship bias. Its statements cover about four fiscal years
and five quarters, and its values are as restated today, not as first
reported.
raw docstring

build-yahoo-dataset!clj

(build-yahoo-dataset! dir & {:keys [out-dir] :as opts})

Builds main/, fundamentals.edn and dataset.edn from the snapshots in

<dir>/raw, into `dir` or the directory given as :out-dir. Takes the options of clojure-backtesting.yahoo.build/build-dataset! as well. Prints the warnings and returns the dataset description.

Builds main/, fundamentals.edn and dataset.edn from the snapshots in
<dir>/raw, into `dir` or the directory given as :out-dir. Takes the
options of clojure-backtesting.yahoo.build/build-dataset! as well.
Prints the warnings and returns the dataset description.
sourceraw docstring

dataset-infoclj

(dataset-info dir)

The description build-yahoo-dataset! wrote to <dir>/dataset.edn.

The description build-yahoo-dataset! wrote to <dir>/dataset.edn.
sourceraw docstring

default-fieldsclj

The Yahoo statement fields downloaded unless :fields says otherwise: the inputs of the ratios in clojure-backtesting.fundamentals and of most textbook factors.

The Yahoo statement fields downloaded unless :fields says otherwise:
the inputs of the ratios in clojure-backtesting.fundamentals and of most
textbook factors.
sourceraw docstring

download-yahoo!clj

(download-yahoo!
  dir
  tickers
  &
  {:keys [start fundamentals? fields concurrency pause-ms force?]
   :or {fundamentals? true fields default-fields concurrency 2 pause-ms 300}})

Downloads tickers from Yahoo Finance into <dir>/raw, one snapshot per security, plus the exchange rates needed to state foreign-currency fundamentals in each security's trading currency. A security already downloaded today (UTC) is skipped unless :force? is true, so an interrupted download can simply be run again. Prices run up to today (end them earlier with build-yahoo-dataset!'s :end). Options: :start yyyy-MM-dd start of the price history (all of it by default) :fundamentals? also fetch statements and earnings dates (true) :fields Yahoo statement fields (default-fields), or :all for clj-yfinance's whole catalog :concurrency securities downloaded at once (2; Yahoo rate-limits) :pause-ms wait between requests per thread (300) :force? download again even if done today Returns {:downloaded [...] :skipped [...] :failed {ticker error} :fx [...]}.

Downloads `tickers` from Yahoo Finance into <dir>/raw, one snapshot per
security, plus the exchange rates needed to state foreign-currency
fundamentals in each security's trading currency. A security already
downloaded today (UTC) is skipped unless :force? is true, so an
interrupted download can simply be run again. Prices run up to today
(end them earlier with build-yahoo-dataset!'s :end). Options:
  :start            yyyy-MM-dd start of the price history (all of it by default)
  :fundamentals?    also fetch statements and earnings dates (true)
  :fields           Yahoo statement fields (default-fields), or :all for
                    clj-yfinance's whole catalog
  :concurrency      securities downloaded at once (2; Yahoo rate-limits)
  :pause-ms         wait between requests per thread (300)
  :force?           download again even if done today
Returns {:downloaded [...] :skipped [...] :failed {ticker error} :fx [...]}.
sourceraw docstring

fetch-snapshotclj

(fetch-snapshot ticker {:keys [start fundamentals? fields pause-ms]})

Downloads one security from Yahoo: daily bars with dividends and splits and, for equities when fundamentals?, the statements (fields, Yahoo names), the earnings history and the earnings announcement dates. Waits pause-ms between requests. Returns the snapshot map; failures are recorded under :errors.

Downloads one security from Yahoo: daily bars with dividends and splits
and, for equities when `fundamentals?`, the statements (`fields`, Yahoo
names), the earnings history and the earnings announcement dates. Waits
`pause-ms` between requests. Returns the snapshot map; failures are
recorded under :errors.
sourceraw docstring

load-yahoo-datasetclj

(load-yahoo-dataset dir)

Loads a built Yahoo dataset: its prices as the main dataset and its fundamentals. A Compustat-style dataset loaded before is unloaded, since it belongs to another universe. Returns a description of the date range.

Loads a built Yahoo dataset: its prices as the main dataset and its
fundamentals. A Compustat-style dataset loaded before is unloaded, since
it belongs to another universe. Returns a description of the date range.
sourceraw docstring

yahoo-dataset!clj

(yahoo-dataset! dir tickers & {:as opts})

Downloads tickers into dir, builds the dataset and loads it, in one call. Takes the options of download-yahoo! and build-yahoo-dataset!.

Downloads `tickers` into `dir`, builds the dataset and loads it, in one
call. Takes the options of download-yahoo! and build-yahoo-dataset!.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close