Optional dataset conversion functions for integration with the Clojure data science ecosystem.
REQUIRES: Add tech.v3.dataset to your deps.edn: {:deps {tech.v3.dataset/tech.v3.dataset {:mvn/version "8.003"}}}
WORKS AUTOMATICALLY WITH:
FOR CLOJASK USERS: clojask uses a different paradigm (lazy parallel processing) and is not directly supported. To convert to clojask format:
(require '[clojask.api :as ck]) (def df (-> (yf/fetch-historical "AAPL" :period "1mo") (ck/dataframe))) ; Convert plain maps to clojask
EXAMPLES:
;; Basic dataset conversion (require '[clj-yfinance.dataset :as yfd]) (yfd/historical->dataset "AAPL" :period "1mo")
;; Works 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]))
;; Works with noj notebooks (require '[scicloj.noj.v1.api :as noj]) (noj/view (yfd/historical->dataset "AAPL" :period "1mo"))
;; Works with datajure (R-like syntax) (require '[datajure.dplyr :as dplyr]) (-> (yfd/historical->dataset "AAPL" :period "1mo") (dplyr/mutate :returns '(/ close (lag close))) (dplyr/filter '(> returns 0.01)))
;; Multi-ticker analysis (yfd/multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")
Optional dataset conversion functions for integration with the Clojure data science ecosystem.
REQUIRES: Add tech.v3.dataset to your deps.edn:
{:deps {tech.v3.dataset/tech.v3.dataset {:mvn/version "8.003"}}}
WORKS AUTOMATICALLY WITH:
- tech.v3.dataset (direct support - columnar data structure)
- tablecloth (wrapper around tech.v3.dataset with friendly API)
- noj (meta-library bundling tablecloth + tech.v3.dataset + visualization)
- datajure (tidyverse-like syntax using tech.v3.dataset internally)
FOR CLOJASK USERS:
clojask uses a different paradigm (lazy parallel processing) and is not directly
supported. To convert to clojask format:
(require '[clojask.api :as ck])
(def df (-> (yf/fetch-historical "AAPL" :period "1mo")
(ck/dataframe))) ; Convert plain maps to clojask
EXAMPLES:
;; Basic dataset conversion
(require '[clj-yfinance.dataset :as yfd])
(yfd/historical->dataset "AAPL" :period "1mo")
;; Works 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]))
;; Works with noj notebooks
(require '[scicloj.noj.v1.api :as noj])
(noj/view (yfd/historical->dataset "AAPL" :period "1mo"))
;; Works with datajure (R-like syntax)
(require '[datajure.dplyr :as dplyr])
(-> (yfd/historical->dataset "AAPL" :period "1mo")
(dplyr/mutate :returns '(/ close (lag close)))
(dplyr/filter '(> returns 0.01)))
;; Multi-ticker analysis
(yfd/multi-ticker->dataset ["AAPL" "GOOGL" "MSFT"] :period "1y")(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. Returns nil if both dividends and splits are empty.
Dividend columns: :timestamp (int64), :amount (float64) Split columns: :timestamp (int64), :numerator (int64), :denominator (int64)
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.
Returns nil if both dividends and splits are empty.
Dividend columns: :timestamp (int64), :amount (float64)
Split columns: :timestamp (int64), :numerator (int64), :denominator (int64)
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]) (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]) (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 |