-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup to run on floydhub
- Loading branch information
Showing
4 changed files
with
756 additions
and
227 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,129 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Import to Postgres\n", | ||
"\n", | ||
"Load the prices and fundamentals into postgres." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```shell\n", | ||
"DB_NAME=stocks pgfutter csv prices.csv\n", | ||
"DB_NAME=stocks pgfutter csv --fields \"ticker_indicator,date,value\" fundamentals.csv\n", | ||
"```\n", | ||
"\n", | ||
"Setup the prices table.\n", | ||
"\n", | ||
"```sql\n", | ||
"ALTER TABLE import.prices\n", | ||
"SET SCHEMA public;\n", | ||
"\n", | ||
"ALTER TABLE prices ALTER COLUMN \"date\" \n", | ||
"SET DATA TYPE date \n", | ||
"USING date::date;\n", | ||
"\n", | ||
"CREATE INDEX idx_prices_date \n", | ||
"ON prices(date);\n", | ||
"```\n", | ||
"\n", | ||
"Setup the fundamentals materialized view.\n", | ||
"\n", | ||
"```sql\n", | ||
"ALTER TABLE import.fundamentals ALTER COLUMN \"date\" \n", | ||
"SET DATA TYPE date \n", | ||
"USING date::date;\n", | ||
"\n", | ||
"CREATE MATERIALIZED VIEW fundamentals AS\n", | ||
"SELECT split_part(ticker_indicator, '_', 1) as ticker, date, value as epsdil \n", | ||
"FROM import.fundamentals\n", | ||
"WHERE ticker_indicator LIKE '%EPSDIL_MRT';\n", | ||
"\n", | ||
"CREATE INDEX idx_fundamentals_date \n", | ||
"ON fundamentals(date);\n", | ||
"\n", | ||
"CREATE INDEX idx_fundamentals_ticker \n", | ||
"ON fundamentals(ticker);\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Query and Export\n", | ||
"\n", | ||
"Export the prices with fundamentals. This took about 40 minutes." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```sql\n", | ||
"COPY \n", | ||
"\n", | ||
"(SELECT p.*, \n", | ||
"\n", | ||
"CASE p.epsdil::numeric\n", | ||
"\tWHEN 0 THEN 0\n", | ||
"\tELSE p.adj_close::numeric / p.epsdil::numeric\n", | ||
"END as pe\n", | ||
"\n", | ||
"FROM (\n", | ||
"\tSELECT prices.adj_close, prices.date, prices.ticker,\n", | ||
"\t(\n", | ||
"\t\tSELECT fundamentals.epsdil\n", | ||
"\t\tFROM fundamentals\n", | ||
"\t\tWHERE prices.ticker = fundamentals.ticker\n", | ||
"\t\tAND prices.date >= fundamentals.date \n", | ||
"\t\tORDER BY fundamentals.date DESC\n", | ||
"\t\tLIMIT 1\n", | ||
"\t)\n", | ||
"\tFROM prices\n", | ||
"\tWHERE prices.adj_close IS NOT NULL AND prices.adj_close != ''\n", | ||
") p\n", | ||
"WHERE p.epsdil IS NOT NULL AND p.epsdil != ''\n", | ||
")\n", | ||
"\n", | ||
"TO 'prices.csv' (format CSV);\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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,5 @@ | ||
## Run on floydhub | ||
|
||
```shell | ||
floyd run --gpu --mode jupyter --env tensorflow-1.0 | ||
``` |
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 @@ | ||
tqdm |
Oops, something went wrong.