This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version for bucket analysis (#410)
* initial version for bucket analysis --------- Co-authored-by: printhellohetal <printhellohetal@gmail.com>
- Loading branch information
1 parent
335a875
commit 83e80a6
Showing
15 changed files
with
3,778 additions
and
2,057 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
notebooks/01-use-cases/finance/quantitative-strategy/README.md
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
Binary file added
BIN
+304 KB
notebooks/01-use-cases/finance/quantitative-strategy/bucket-analysis/content/content.mv.db
Binary file not shown.
Binary file added
BIN
+341 KB
...cases/finance/quantitative-strategy/bucket-analysis/img/atoti-data-pipeline.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+205 KB
...ks/01-use-cases/finance/quantitative-strategy/bucket-analysis/img/data_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+322 KB
...ases/finance/quantitative-strategy/bucket-analysis/img/python-data-pipeline.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,573 changes: 1,573 additions & 0 deletions
1,573
notebooks/01-use-cases/finance/quantitative-strategy/bucket-analysis/main.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
notebooks/01-use-cases/finance/quantitative-strategy/bucket-analysis/utils/data_model.py
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,72 @@ | ||
import atoti as tt | ||
import pandas as pd | ||
|
||
|
||
def table_creation(session): | ||
txn_tbl = session.read_csv( | ||
"s3://data.atoti.io/notebooks/bucket-exploration/initial_transactions.csv", | ||
table_name="Transaction", | ||
keys=["TransactionId", "Ticker", "DateTime"], | ||
types={ | ||
"DateTime": tt.type.STRING, | ||
"PurchaseDate": tt.type.STRING, | ||
"Timestamp": tt.type.STRING, | ||
}, | ||
) | ||
|
||
|
||
def cube_creation(session): | ||
txn_tbl = session.tables["Transaction"] | ||
cube = session.create_cube(txn_tbl, name="TxnCube", mode="no_measures") | ||
|
||
# cube.shared_context["queriesResultLimit.intermediateLimit"] = -1 | ||
# cube.shared_context["queriesResultLimit.transientLimit"] = -1 | ||
|
||
|
||
def create_model(session): | ||
table_creation(session) | ||
cube_creation(session) | ||
|
||
|
||
def enrich_cube(session): | ||
txn_tbl = session.tables["Transaction"] | ||
|
||
sector_tbl = session.read_csv( | ||
"s3://data.atoti.io/notebooks/bucket-exploration/constituents.csv", | ||
table_name="Sector", | ||
keys=["Symbols"], | ||
) | ||
|
||
hist_tbl = session.read_csv( | ||
"s3://data.atoti.io/notebooks/bucket-exploration/bucketed_historical_pricing.csv", | ||
table_name="HistoricalPricing", | ||
keys=["Ticker", "DateTime"], | ||
types={"DateTime": tt.type.STRING}, | ||
) | ||
|
||
txn_tbl.join(sector_tbl, txn_tbl["Ticker"] == sector_tbl["Symbols"]) | ||
txn_tbl.join( | ||
hist_tbl, | ||
(txn_tbl["Ticker"] == hist_tbl["Ticker"]) | ||
& (txn_tbl["DateTime"] == hist_tbl["DateTime"]), | ||
) | ||
|
||
|
||
def create_measures(session): | ||
cube = session.cubes["TxnCube"] | ||
hist_tbl = session.tables["HistoricalPricing"] | ||
h, l, m = cube.hierarchies, cube.levels, cube.measures | ||
|
||
m["Volume"] = tt.agg.sum(hist_tbl["Volume"]) | ||
m["High"] = tt.agg.max(hist_tbl["High"]) | ||
m["Low"] = tt.agg.min(hist_tbl["Low"]) | ||
m["Open"] = tt.agg.single_value(hist_tbl["Open"]) | ||
|
||
for _m in ["Volume", "High", "Low", "Open"]: | ||
m[_m].folder = "HistoricalMetrics" | ||
|
||
|
||
def load_transactions(session, df): | ||
txn_tbl = session.tables["Transaction"] | ||
|
||
txn_tbl.load_pandas(df) |
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
Oops, something went wrong.