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);




