Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
initial version for bucket analysis (#410)
Browse files Browse the repository at this point in the history
* initial version for bucket analysis
---------

Co-authored-by: printhellohetal <printhellohetal@gmail.com>
  • Loading branch information
HuifangYeo and printhellohetal authored May 24, 2023
1 parent 335a875 commit 83e80a6
Show file tree
Hide file tree
Showing 15 changed files with 3,778 additions and 2,057 deletions.
1,061 changes: 541 additions & 520 deletions README.md

Large diffs are not rendered by default.

895 changes: 458 additions & 437 deletions notebooks/01-use-cases/README.md

Large diffs are not rendered by default.

483 changes: 252 additions & 231 deletions notebooks/01-use-cases/finance/README.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions notebooks/01-use-cases/finance/quantitative-strategy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<p align="center">
<img src="https://data.atoti.io/notebooks/banners/logo.png" alt="atoti logo">
</p>

<p align="center">
<a href="https://github.com/atoti/atoti/discussions"><img src="https://img.shields.io/github/discussions/atoti/atoti" alt="GitHub Discussion"></a>
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fatoti%2Fnotebooks&count_bg=%23FF7375&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false" alt="Hits"></a>
<a href="https://stackoverflow.com/questions/tagged/atoti"><img src="https://img.shields.io/badge/StackOverflow-atoti-f58024.svg" alt="stackoverflow"></a>
</p>


## Financial use cases for Quantitative Strategy


<table>



<tr>
<td><b>Notebooks</b></td>
<td><b>Related media</b></td>
</tr>
<tr>
<td rowspan="1"><a href="https://github.com/atoti/notebooks/blob/main/notebooks/01-use-cases/finance/quantitative-strategy/bucket-analysis/main.ipynb">&nbsp;bucket-analysis&nbsp;</a></td>
<td>&nbsp</td>
</tr>
</table>


<br/>
<p align="center">
Reach out to <a href="https://www.activeviam.com/contact-us/"><img src="https://data.atoti.io/notebooks/banners/ActiveViam-RVB-150dpi.png" alt="atoti logo" width="150px" /></a> for more information.
</p>
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 notebooks/01-use-cases/finance/quantitative-strategy/bucket-analysis/main.ipynb

Large diffs are not rendered by default.

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)
2 changes: 1 addition & 1 deletion notebooks/01-use-cases/other-industries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<td><a href="https://www.atoti.io/articles/iot-device-traffic-to-demonstrate-office-personnel-traffic/?utm_source=github">📰&nbsp;IoT device traffic to demonstrate office personnel traffic</a></td>
</tr>
<tr>
<td rowspan="1"><a href="https://github.com/atoti/notebooks/blob/main/notebooks/01-use-cases/other-industries/monte-carlo-pi/main.ipynb">&nbsp;monte-carlo-pi&nbsp;</a></td>
<td rowspan="1"><a href="https://github.com/atoti/notebooks/blob/main/notebooks/01-use-cases/other-industries/monte-carlo-pi/nan">&nbsp;monte-carlo-pi&nbsp;</a></td>
<td>&nbsp</td>
</tr>
<tr>
Expand Down
Loading

0 comments on commit 83e80a6

Please sign in to comment.