Skip to content

Commit 042d661

Browse files
committed
added exploring-sp500 project
1 parent 45b7f81 commit 042d661

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data exploration of the S&P 500 stocks
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source:
2+
https://www.kaggle.com/datasets/andrewmvd/sp-500-stocks/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{:deps {org.scicloj/noj {:mvn/version "1-alpha34"}
2+
org.scicloj/clay {:mvn/version "2-beta11"}}}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(ns explore
2+
(:require [tablecloth.api :as tc]
3+
[scicloj.noj.v1.vis.hanami :as hanami]
4+
[aerial.hanami.templates :as ht]
5+
[scicloj.kindly.v4.api :as kindly]))
6+
7+
(defonce prices
8+
(-> "data/sp500_stocks.csv.gz"
9+
(tc/dataset {:key-fn keyword})
10+
(tc/rename-columns {(keyword "Adj Close") :Adj-Close})))
11+
12+
13+
(map? prices)
14+
15+
(keys prices)
16+
17+
(-> prices
18+
:Symbol)
19+
20+
(-> prices
21+
:Symbol
22+
distinct)
23+
24+
(-> prices
25+
:Symbol
26+
distinct
27+
count)
28+
29+
(kindly/check = 503)
30+
31+
(-> prices
32+
(tc/group-by [:Symbol]))
33+
34+
(-> prices
35+
(tc/group-by [:Symbol])
36+
(tc/aggregate {:n tc/row-count})
37+
(tc/order-by [:n]))
38+
39+
(-> prices
40+
(tc/group-by [:symbol])
41+
(tc/aggregate {:n tc/row-count})
42+
:n
43+
distinct)
44+
45+
46+
47+
(-> prices
48+
(tc/select-rows (fn [{:keys [Symbol]}]
49+
(= Symbol "ADBE"))))
50+
51+
52+
53+
54+
(-> prices
55+
(tc/select-rows (fn [{:keys [Symbol]}]
56+
(= Symbol "ADBE")))
57+
(tc/select-columns [:Date :Adj-Close])
58+
(hanami/plot ht/line-chart
59+
{:X :Date
60+
:XTYPE :temporal
61+
:Y :Adj-Close}))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
(ns
2+
explore-generated-test
3+
(:require
4+
[tablecloth.api :as tc]
5+
[scicloj.noj.v1.vis.hanami :as hanami]
6+
[aerial.hanami.templates :as ht]
7+
[scicloj.kindly.v4.api :as kindly]
8+
[clojure.test :refer [deftest is]]))
9+
10+
11+
(def
12+
var1
13+
(defonce
14+
prices
15+
(->
16+
"data/sp500_stocks.csv.gz"
17+
(tc/dataset {:key-fn keyword})
18+
(tc/rename-columns {(keyword "Adj Close") :Adj-Close}))))
19+
20+
21+
(def var2 (map? prices))
22+
23+
24+
(def var3 (keys prices))
25+
26+
27+
(def var4 (-> prices :Symbol))
28+
29+
30+
(def var5 (-> prices :Symbol distinct))
31+
32+
33+
(def var6 (-> prices :Symbol distinct count))
34+
35+
36+
(deftest test7 (is (= var6 503)))
37+
38+
39+
(def var8 (-> prices (tc/group-by [:Symbol])))
40+
41+
42+
(def
43+
var9
44+
(->
45+
prices
46+
(tc/group-by [:Symbol])
47+
(tc/aggregate {:n tc/row-count})
48+
(tc/order-by [:n])))
49+
50+
51+
(def
52+
var10
53+
(->
54+
prices
55+
(tc/group-by [:symbol])
56+
(tc/aggregate {:n tc/row-count})
57+
:n
58+
distinct))
59+
60+
61+
(def
62+
var11
63+
(-> prices (tc/select-rows (fn [{:keys [Symbol]}] (= Symbol "ADBE")))))
64+
65+
66+
(def
67+
var12
68+
(->
69+
prices
70+
(tc/select-rows (fn [{:keys [Symbol]}] (= Symbol "ADBE")))
71+
(tc/select-columns [:Date :Adj-Close])
72+
(hanami/plot
73+
ht/line-chart
74+
{:X :Date, :XTYPE :temporal, :Y :Adj-Close})))

0 commit comments

Comments
 (0)