Skip to content

Commit

Permalink
Update regular update sql
Browse files Browse the repository at this point in the history
  • Loading branch information
chenditc committed Aug 8, 2022
1 parent acbb276 commit 161946c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ bash daily_update.sh
docker run -v /<some output directory>:/output -it --rm chenditc/investment_data bash daily_update.sh && bash dump_qlib_bin.sh && cp ./qlib_bin.tar.gz /output/
```

## Extract tar file to qlib directory
```
tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=2
```

# Initiative
1. Try to fill in missing data by combining data from multiple data source. For example, delist company's data.
Expand Down
15 changes: 9 additions & 6 deletions tushare/regular_update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ where tradedate = (select max(tradedate) from ts_a_stock_eod_price) group by sym

/* Fill in new stock price */
/* Fill in stock where w stock does not exists */
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose)
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose, amount)
select ts_a_stock_eod_price.tradedate,
missing_table.w_symbol as symbol,
ts_a_stock_eod_price.high,
ts_a_stock_eod_price.low,
ts_a_stock_eod_price.open,
ts_a_stock_eod_price.close,
ts_a_stock_eod_price.volume,
ROUND(ts_a_stock_eod_price.adjclose, 2)
ROUND(ts_a_stock_eod_price.adjclose, 2),
ts_a_stock_eod_price.amount
FROM ts_a_stock_eod_price,
(
select distinct(link_symbol) as w_missing_symbol, w_symbol from ts_link_table
Expand All @@ -26,15 +27,16 @@ WHERE ts_a_stock_eod_price.symbol = missing_table.w_missing_symbol;
UPDATE ts_link_table SET adj_ratio=1 WHERE adj_ratio is NULL;

/* Fill in index price from ts */
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose)
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose, amount)
select ts_raw_table.tradedate,
ts_link_table.w_symbol as symbol,
ts_raw_table.high,
ts_raw_table.low,
ts_raw_table.open,
ts_raw_table.close,
ts_raw_table.volume,
ROUND(ts_raw_table.adjclose / ts_link_table.adj_ratio, 2) as adjclose
ROUND(ts_raw_table.adjclose / ts_link_table.adj_ratio, 2) as adjclose,
ts_raw_table.amount
FROM (
SELECT * FROM ts_a_stock_eod_price
WHERE tradedate >
Expand All @@ -47,15 +49,16 @@ WHERE tradedate >
LEFT JOIN ts_link_table ON ts_raw_table.symbol = ts_link_table.link_symbol;

/* Fill in stock price from ts */
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose)
INSERT IGNORE INTO final_a_stock_eod_price (tradedate, symbol, high, low, open, close, volume, adjclose, amount)
select ts_raw_table.tradedate,
ts_link_table.w_symbol as symbol,
ts_raw_table.high,
ts_raw_table.low,
ts_raw_table.open,
ts_raw_table.close,
ts_raw_table.volume,
ROUND(ts_raw_table.adjclose / ts_link_table.adj_ratio, 2) as adjclose
ROUND(ts_raw_table.adjclose / ts_link_table.adj_ratio, 2) as adjclose,
ts_raw_table.amount
FROM (
SELECT * FROM ts_a_stock_eod_price
WHERE tradedate > (
Expand Down

0 comments on commit 161946c

Please sign in to comment.