Optional dataset conversion functions for integration with the Clojure data science ecosystem.
REQUIRES: techascent/tech.ml.dataset on the classpath.
The results are plain tech.v3.dataset datasets, so they work directly with tablecloth, Noj, datajure and anything else built on tech.ml.dataset.
EXAMPLES:
(require '[clj-yfinance.dataset :as yfd]) (yfd/historical->dataset "AAPL" :period "1mo") (yfd/multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")
;; With tablecloth (require '[tablecloth.api :as tc]) (-> (yfd/historical->dataset "AAPL" :period "1mo") (tc/add-column :returns (fn [ds] ...)) (tc/select-columns [:timestamp :close :returns]))
Optional dataset conversion functions for integration with the Clojure data science ecosystem.
REQUIRES: techascent/tech.ml.dataset on the classpath.
The results are plain tech.v3.dataset datasets, so they work directly with
tablecloth, Noj, datajure and anything else built on tech.ml.dataset.
EXAMPLES:
(require '[clj-yfinance.dataset :as yfd])
(yfd/historical->dataset "AAPL" :period "1mo")
(yfd/multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")
;; With tablecloth
(require '[tablecloth.api :as tc])
(-> (yfd/historical->dataset "AAPL" :period "1mo")
(tc/add-column :returns (fn [ds] ...))
(tc/select-columns [:timestamp :close :returns]))(dividends-splits->dataset data-or-ticker)(dividends-splits->dataset ticker & opts)Convert dividends and splits data to separate datasets.
Returns a map with :dividends and :splits keys, each containing a dataset; a key is absent when there are no events of that kind. Returns nil if both are empty. Timestamps come from each event's :date; rows are in date order.
Dividend columns: :timestamp (int64), :amount (float64) Split columns: :timestamp (int64), :numerator (float64), :denominator (float64)
Example: (def data (yf/fetch-dividends-splits "AAPL" :period "10y")) (dividends-splits->dataset data) ;; => {:dividends #tech.v3.dataset<...>, :splits #tech.v3.dataset<...>}
(dividends-splits->dataset "AAPL" :period "5y")
Convert dividends and splits data to separate datasets.
Returns a map with :dividends and :splits keys, each containing a dataset;
a key is absent when there are no events of that kind. Returns nil if both
are empty. Timestamps come from each event's :date; rows are in date order.
Dividend columns: :timestamp (int64), :amount (float64)
Split columns: :timestamp (int64), :numerator (float64), :denominator (float64)
Example:
(def data (yf/fetch-dividends-splits "AAPL" :period "10y"))
(dividends-splits->dataset data)
;; => {:dividends #tech.v3.dataset<...>, :splits #tech.v3.dataset<...>}
(dividends-splits->dataset "AAPL" :period "5y")(historical->dataset data-or-ticker)(historical->dataset ticker & opts)Convert historical OHLCV data to tech.v3.dataset with proper column types.
Accepts either:
Returns tech.v3.dataset with typed columns:
Returns nil if data is empty or fetch fails.
Examples: (historical->dataset "AAPL" :period "1mo") (historical->dataset "TSLA" :period "1y" :interval "1d")
;; Convert already-fetched data (def data (yf/fetch-historical "AAPL" :period "1mo")) (historical->dataset data)
Convert historical OHLCV data to tech.v3.dataset with proper column types. Accepts either: - (ticker & opts) - fetches data then converts - (data-map) - converts already-fetched data Returns tech.v3.dataset with typed columns: - :timestamp (int64) - Unix epoch seconds - :open, :high, :low, :close, :adj-close (float64) - :volume (int64) Returns nil if data is empty or fetch fails. Examples: (historical->dataset "AAPL" :period "1mo") (historical->dataset "TSLA" :period "1y" :interval "1d") ;; Convert already-fetched data (def data (yf/fetch-historical "AAPL" :period "1mo")) (historical->dataset data)
(info->dataset data-or-ticker)(info->dataset ticker & _opts)Convert ticker info to single-row dataset.
Returns a single-row dataset containing ticker metadata. Returns nil if fetch fails.
Useful for combining multiple ticker info into a comparison table:
Example: (info->dataset "AAPL")
;; Compare multiple tickers (require '[tech.v3.dataset :as ds]) (apply ds/concat (map info->dataset ["AAPL" "GOOGL" "MSFT"]))
Convert ticker info to single-row dataset. Returns a single-row dataset containing ticker metadata. Returns nil if fetch fails. Useful for combining multiple ticker info into a comparison table: Example: (info->dataset "AAPL") ;; Compare multiple tickers (require '[tech.v3.dataset :as ds]) (apply ds/concat (map info->dataset ["AAPL" "GOOGL" "MSFT"]))
(multi-ticker->dataset tickers & opts)Fetch historical data for multiple tickers and combine into single dataset.
Returns a dataset with all tickers combined, including a :ticker column to identify each row's source ticker.
Returns nil if all fetches fail or all data is empty.
Columns: :ticker (string), :timestamp (int64), :open/:high/:low/:close/:adj-close (float64), :volume (int64)
Example: (multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y") (multi-ticker->dataset ["AAPL" "TSLA"] :period "1mo" :interval "1h")
;; Use with tablecloth for grouped operations (require '[tablecloth.api :as tc]) (-> (multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y") (tc/group-by [:ticker]) (tc/add-column :returns (fn [ds] ...)))
Fetch historical data for multiple tickers and combine into single dataset.
Returns a dataset with all tickers combined, including a :ticker column
to identify each row's source ticker.
Returns nil if all fetches fail or all data is empty.
Columns: :ticker (string), :timestamp (int64), :open/:high/:low/:close/:adj-close (float64), :volume (int64)
Example:
(multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")
(multi-ticker->dataset ["AAPL" "TSLA"] :period "1mo" :interval "1h")
;; Use with tablecloth for grouped operations
(require '[tablecloth.api :as tc])
(-> (multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")
(tc/group-by [:ticker])
(tc/add-column :returns (fn [ds] ...)))(prices->dataset prices-map)Convert price map to dataset with ticker and price columns.
Takes a map of {ticker price} (as returned by fetch-prices) and converts to a dataset with :ticker (string) and :price (float64) columns.
Returns nil if prices map is empty.
Example: (def prices (yf/fetch-prices ["AAPL" "GOOGL" "MSFT"])) (prices->dataset prices) ;; => tech.v3.dataset with columns [:ticker :price]
Convert price map to dataset with ticker and price columns.
Takes a map of {ticker price} (as returned by fetch-prices) and converts
to a dataset with :ticker (string) and :price (float64) columns.
Returns nil if prices map is empty.
Example:
(def prices (yf/fetch-prices ["AAPL" "GOOGL" "MSFT"]))
(prices->dataset prices)
;; => tech.v3.dataset with columns [:ticker :price]cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |