Total value of trades
Suppose you're given the following table showing open, high, low, and close prices for a stock on a given date (preview of the schema, full schema in link below):
Given this, calculate the 20-day moving average of the closing price. Then, if the price of the day's open is greater than the 20-day moving average, you will "buy" the stock and sell on close for that day. Using this strategy, write a SQL query to calculate the total value of these trades.
You can view/query the table in an interactive SQL fiddle here.
Subscribe to premium account to see the solution.Get premium now