-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data exploration of the S&P 500 stocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
74
projects/finance/exploring-sp500/test/explore_generated_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}))) |