Question: -- Create the tables for the S&P 500 database. create table history ( symbol text, day date, open numeric, high numeric, low numeric, close numeric,
-- Create the tables for the S&P 500 database.
create table history ( symbol text, day date, open numeric, high numeric, low numeric, close numeric, volume integer, adjclose numeric );
create table sp500 ( symbol text, security text, sector text, subindustry text, address text, state text );
-- Populate the tables insert into history select * from bob.history; insert into sp500 select * from bob.sp500;
-- Familiarize yourself with the tables. select * from history; select * from sp500;
-- Exercise 1:
-- 1. Find for each symbol and day the pct change from the previous business day. -- Order descending by pct change. Use adjclose.
-- Write your query here.
-- 2. -- Many traders believe in buying stocks in an uptrend -- in order to maximize their chance of profit. -- Let us check this strategy. -- Find for each symbol on Oct 1, 2015 -- the pct change 20 trading days earlier and 20 trading days later. -- Order descending by pct change with respect to 20 trading days earlier. -- Use adjclose.
-- Expected result --symbol,pct_change,pct_change2 --TE,26.0661102331371252,3.0406725557250169 --TAP,24.6107784431137725,5.1057184046131667 --CVC,24.4688922610015175,-0.67052727826882048156 --...
-- Write your query here.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
