Skip to content

Commit

Permalink
Train based on eps
Browse files Browse the repository at this point in the history
Setup to run on floydhub
  • Loading branch information
jperl committed Mar 25, 2017
1 parent 640e008 commit 2e7b395
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 227 deletions.
129 changes: 129 additions & 0 deletions Preprocess Stock Data.ipynb
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
}
5 changes: 5 additions & 0 deletions README.md
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
```
1 change: 1 addition & 0 deletions floyd_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tqdm
Loading

0 comments on commit 2e7b395

Please sign in to comment.