Data Interview Qs - Moving average trading strategy

InterviewQs

Moving average trading strategy

SQL Database Querying Window Function Subquery

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

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/table in SQL fiddle link below):

Table: Prices

Date Open High Low Close
2020-01-02 00:00:00 1875 1898.01 1864.15 1898.01
2020-01-03 00:00:00 1864.5 1886.2 1864.5 1874.97
2020-01-06 00:00:00 1860 1903.69 1860 1902.88
2020-01-07 00:00:00 1904.5 1913.89 1892.04 1906.86

Given this data, you're asked to apply the following trading strategy:

  • Calculate the 10-day moving average of the closing price
  • Then, if the price of the day's open is greater than the 10-day moving average, you will "buy" the stock on open and sell on close for that day.

Write a SQL query to apply this trading strategy and return the total earnings/loss over the period of data provided.

You can view/query the table in an interactive SQL fiddle here.


 

You’ve accumulated 369 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe

Key phrases

Older messages

Selecting computers for a company

Monday, November 7, 2022

Data Analysis, Python, Pandas, Data Manipulation, Data Visualization, External Dataset, Case Study, InterviewQs Selecting computers for a company Data Analysis Python Pandas Data Manipulation Data

Matrix multiplication using nested loops

Friday, November 4, 2022

Python, Data Structures, Algorithms, Matrix Multiplication, InterviewQs Matrix multiplication using nested loops Python Data Structures Algorithms Matrix Multiplication Forward this email to a friend

Evaluating lottery system

Wednesday, November 2, 2022

Statistics, Hypergeometric Distribution, Probability, InterviewQs Evaluating lottery system Statistics Hypergeometric Distribution Probability Forward this email to a friend or colleague and challenge

Highest performing students by college program

Monday, October 31, 2022

SQL, Database Querying, Subquery, Case Statement, InterviewQs Highest performing students by college program SQL Database Querying Subquery Case Statement Forward this email to a friend or colleague

Multicollinearity in linear regression

Friday, October 28, 2022

Statistics, Regression, Multicollinearity, PCA, InterviewQs Multicollinearity in linear regression Statistics Regression Multicollinearity PCA Forward this email to a friend or colleague and challenge

You Might Also Like

TikTok threatens shutdown 📱, FCC passes net neutrality 🌐, the robotics renaissance 🤖

Friday, April 26, 2024

ByteDance would rather shut down TikTok than sell the company Sign Up |Advertise|View Online TLDR Together With Plaid TLDR 2024-04-26 6 fintech predictions you need to know for 2024 (Sponsor)

📧 What's inside MMA and how it can help you

Friday, April 26, 2024

What's Inside Modular Monolith Architecture? Hey there! 👋 I wish you an excellent end to the week. What better way to spend the weekend than diving headfirst into a 12+ hour course? Well, maybe

Data Science Weekly - Issue 544

Friday, April 26, 2024

Curated news, articles and jobs related to Data Science, AI, & Machine Learning ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Develop highly relevant search applications using AI

Friday, April 26, 2024

New Elasticsearch and AI training ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ elastic | Search. Observe. Protect A world of AI possibilities door-test 2.png Explore

Stripe makes more changes

Thursday, April 25, 2024

TikTok is in trouble, and net neutrality is back View this email online in your browser By Christine Hall Thursday, April 25, 2024 Welcome back to TechCrunch PM, your home for all things startups,

💎 Issue 414 - From a Lorry Driver to Ruby on Rails Developer at 38

Thursday, April 25, 2024

This week's Awesome Ruby Newsletter Read this email on the Web The Awesome Ruby Newsletter Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular Ruby news, articles and

💻 Issue 414 - JavaScript Features That Most Developers Don’t Know

Thursday, April 25, 2024

This week's Awesome Node.js Weekly Read this email on the Web The Awesome Node.js Weekly Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular Node.js news, articles and

💻 Issue 407 - The Performance Impact of C++'s `final` Keyword

Thursday, April 25, 2024

This week's Awesome .NET Weekly Read this email on the Web The Awesome .NET Weekly Issue » 407 Release Date Apr 25, 2024 Your weekly report of the most popular .NET news, articles and projects

💻 Issue 414 - Everyone Has JavaScript, Right?

Thursday, April 25, 2024

This week's Awesome JavaScript Weekly Read this email on the Web The Awesome JavaScript Weekly Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular JavaScript news, articles

📱 Issue 408 - All web browsers on iOS are just Safari with different design

Thursday, April 25, 2024

This week's Awesome iOS Weekly Read this email on the Web The Awesome iOS Weekly Issue » 408 Release Date Apr 25, 2024 Your weekly report of the most popular iOS news, articles and projects Popular