Skip to content

Commit

Permalink
added exploring-sp500 project
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Jun 20, 2024
1 parent 45b7f81 commit 042d661
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions projects/finance/exploring-sp500/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data exploration of the S&P 500 stocks
2 changes: 2 additions & 0 deletions projects/finance/exploring-sp500/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source:
https://www.kaggle.com/datasets/andrewmvd/sp-500-stocks/
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions projects/finance/exploring-sp500/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:deps {org.scicloj/noj {:mvn/version "1-alpha34"}
org.scicloj/clay {:mvn/version "2-beta11"}}}
61 changes: 61 additions & 0 deletions projects/finance/exploring-sp500/src/explore.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(ns explore
(:require [tablecloth.api :as tc]
[scicloj.noj.v1.vis.hanami :as hanami]
[aerial.hanami.templates :as ht]
[scicloj.kindly.v4.api :as kindly]))

(defonce prices
(-> "data/sp500_stocks.csv.gz"
(tc/dataset {:key-fn keyword})
(tc/rename-columns {(keyword "Adj Close") :Adj-Close})))


(map? prices)

(keys prices)

(-> prices
:Symbol)

(-> prices
:Symbol
distinct)

(-> prices
:Symbol
distinct
count)

(kindly/check = 503)

(-> prices
(tc/group-by [:Symbol]))

(-> prices
(tc/group-by [:Symbol])
(tc/aggregate {:n tc/row-count})
(tc/order-by [:n]))

(-> prices
(tc/group-by [:symbol])
(tc/aggregate {:n tc/row-count})
:n
distinct)



(-> prices
(tc/select-rows (fn [{:keys [Symbol]}]
(= Symbol "ADBE"))))




(-> prices
(tc/select-rows (fn [{:keys [Symbol]}]
(= Symbol "ADBE")))
(tc/select-columns [:Date :Adj-Close])
(hanami/plot ht/line-chart
{:X :Date
:XTYPE :temporal
:Y :Adj-Close}))
74 changes: 74 additions & 0 deletions projects/finance/exploring-sp500/test/explore_generated_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(ns
explore-generated-test
(:require
[tablecloth.api :as tc]
[scicloj.noj.v1.vis.hanami :as hanami]
[aerial.hanami.templates :as ht]
[scicloj.kindly.v4.api :as kindly]
[clojure.test :refer [deftest is]]))


(def
var1
(defonce
prices
(->
"data/sp500_stocks.csv.gz"
(tc/dataset {:key-fn keyword})
(tc/rename-columns {(keyword "Adj Close") :Adj-Close}))))


(def var2 (map? prices))


(def var3 (keys prices))


(def var4 (-> prices :Symbol))


(def var5 (-> prices :Symbol distinct))


(def var6 (-> prices :Symbol distinct count))


(deftest test7 (is (= var6 503)))


(def var8 (-> prices (tc/group-by [:Symbol])))


(def
var9
(->
prices
(tc/group-by [:Symbol])
(tc/aggregate {:n tc/row-count})
(tc/order-by [:n])))


(def
var10
(->
prices
(tc/group-by [:symbol])
(tc/aggregate {:n tc/row-count})
:n
distinct))


(def
var11
(-> prices (tc/select-rows (fn [{:keys [Symbol]}] (= Symbol "ADBE")))))


(def
var12
(->
prices
(tc/select-rows (fn [{:keys [Symbol]}] (= Symbol "ADBE")))
(tc/select-columns [:Date :Adj-Close])
(hanami/plot
ht/line-chart
{:X :Date, :XTYPE :temporal, :Y :Adj-Close})))

0 comments on commit 042d661

Please sign in to comment.