master
SeanChenTaipei 2 years ago
parent bfcbdcf70e
commit 6e70d853b6
  1. 5
      .gitignore
  2. 2
      assets_us.json
  3. 0
      dd.session.sql
  4. 17
      main.py
  5. 63
      sql_script/create_all.sql
  6. 25
      sql_script/create_stockDB.sql
  7. 3
      sql_script/create_strategy.sql

5
.gitignore vendored

@ -2,6 +2,7 @@
.ipynb_checkpoints/
__pycache__/
.DS_Store
.vscode/
tpm/
@ -9,5 +10,7 @@ tpm/
main.old.py
postgres_runner.py
*.ipynb
backup.sql
tickers_sorted_tw.py
tickers_sorted.py
tickers_sorted.py
main_old.py

File diff suppressed because one or more lines are too long

@ -32,7 +32,12 @@ SQL_CONFIG = {
'host': "127.0.0.1",
'port': "5432"
}
# Load Assets
with open('assets_tw.json') as f:
data_tw = json.load(f)
with open('assets_us.json') as f:
data_us = json.load(f)
app = Flask(__name__)
app.config.from_mapping(CONFIGS)
@ -180,13 +185,10 @@ def strategy():
return redirect(url_for('login'))
session['tw'] = 0
# Load Assets
with open('assets_tw.json') as f:
data_tw = json.load(f)
with open('assets_us.json') as f:
data = json.load(f)
print(request.args.get('data'), 666)
return render_template('strategy_tw.html', stockOpts={**data, **data_tw})
return render_template('strategy_tw.html', stockOpts={**data_us, **data_tw})
@ -199,12 +201,9 @@ def strategy_tw():
flash('使用投組功能請先登入。', 'warning')
return redirect(url_for('login'))
session['tw'] = 1
# Load Assets
with open('assets_tw.json') as f:
data = json.load(f)
print(request.args.get('data'), 666)
return render_template('strategy_tw.html', stockOpts=data)
return render_template('strategy_tw.html', stockOpts=data_tw)

@ -0,0 +1,63 @@
DROP TABLE IF EXISTS users;
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(64) UNIQUE NOT NULL,
password VARCHAR(128) NOT NULL,
vip BOOLEAN DEFAULT FALSE
);
INSERT INTO users (username, password)
VALUES ('s@s', 'pbkdf2:sha256:260000$Z5bK5pp0D8HEDAps$abb43b1b1c543ff334de8fb3aeba9c0460c37de5b5363e5210e68b00739d5e2c'),
('R10246002@ntu.edu.tw', 'pbkdf2:sha256:260000$Z5bK5pp0D8HEDAps$abb43b1b1c543ff334de8fb3aeba9c0460c37de5b5363e5210e68b00739d5e2c');
DROP TABLE IF EXISTS stock_price;
DROP TABLE IF EXISTS stock_price_tw;
CREATE TABLE stock_price (
id SERIAL PRIMARY KEY,
ticker VARCHAR(64) NOT NULL,
date DATE NOT NULL,
price REAL NOT NULL,
return REAL NOT NULL
);
-- you need to add ()
CREATE INDEX idx_ticker ON stock_price (ticker);
CREATE TABLE stock_price_tw (
id SERIAL PRIMARY KEY,
ticker VARCHAR(64) NOT NULL,
date DATE NOT NULL,
price REAL NOT NULL,
return REAL NOT NULL
);
-- you need to add ()
CREATE INDEX idx_ticker_tw ON stock_price_tw (ticker);
DROP TABLE IF EXISTS strategy;
CREATE TABLE strategy (
id SERIAL PRIMARY KEY,
date DATE NOT NULL,
name VARCHAR(64) NOT NULL,
username VARCHAR(64) NOT NULL,
competition VARCHAR(64) NOT NULL,
role VARCHAR(20) NOT NULL,
ratio REAL NOT NULL,
annual_ret REAL NOT NULL,
vol REAL NOT NULL,
mdd REAL NOT NULL,
annual_sr REAL NOT NULL,
beta REAL NOT NULL,
alpha REAL NOT NULL,
var10 REAL NOT NULL,
R2 REAL NOT NULL,
tw BOOLEAN DEFAULT TRUE,
comment VARCHAR(255),
assets TEXT[] NOT NULL,
assets_position REAL[] NOT NULL,
notes TEXT[][]
);
CREATE INDEX idx_user ON strategy (username);

@ -1,7 +1,6 @@
DROP TABLE IF EXISTS stock_price;
-- DROP TABLE IF EXISTS stock_price_tw;
-- DROP TABLE IF EXISTS stock_info;
-- DROP TABLE IF EXISTS stock_info_tw;
CREATE TABLE stock_price (
id SERIAL PRIMARY KEY,
@ -21,24 +20,4 @@ CREATE INDEX idx_ticker ON stock_price (ticker);
-- return REAL NOT NULL
-- );
-- -- you need to add ()
-- CREATE INDEX idx_ticker_tw ON stock_price_tw (ticker);
-- CREATE TABLE stock_info_tw (
-- id SERIAL PRIMARY KEY,
-- ticker VARCHAR(64) NOT NULL,
-- last_price REAL NOT NULL,
-- start DATE NOT NULL,
-- end DATE NOT NULL
-- );
-- you need to add ()
-- CREATE INDEX idx_info_tw ON stock_info_tw (ticker);
-- CREATE TABLE stock_info (
-- id SERIAL PRIMARY KEY,
-- ticker VARCHAR(64) NOT NULL,
-- last_price REAL NOT NULL,
-- start DATE NOT NULL,
-- end DATE NOT NULL
-- );
-- you need to add ()
-- CREATE INDEX idx_info ON stock_info (ticker);
-- CREATE INDEX idx_ticker_tw ON stock_price_tw (ticker);

@ -18,7 +18,8 @@ CREATE TABLE strategy (
tw BOOLEAN DEFAULT TRUE,
comment VARCHAR(255),
assets TEXT[] NOT NULL,
assets_position REAL[] NOT NULL
assets_position REAL[] NOT NULL,
notes TEXT[][]
);
CREATE INDEX idx_user ON strategy (username);

Loading…
Cancel
Save