Data Interview Qs - Simple trading simulation

InterviewQs

Simple trading simulation

Python Data Structures Arrays Algorithms Simulation

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

Hi, 

Suppose you want to create a simple trading algorithm which purchases 1 share of SPY (an ETF which tracks the S&P 500) when the opening price is below $285.00 and sells the share when the opening price is above $290.00. At any given time you can only own 1 share of SPY.

Create a Python script that simulates the rules above for Jan 2, 2020 through May 1, 2020. You will need to keep track of your positions (e.g. buying and selling) in a dataframe and below are the requirements for the dataframe columns:

  • buy_date: date the asset was purchased
  • buy_price: price the asset was purchased for
  • sell_date: the date the asset is sold
  • sell_price: price the asset was sold

To help get you started, the code below installs yfinance to your Colab runtime and loads in the historial stock data. You can also make a copy of this Google Colab notebook to get started!

    

#import yahoo finance

pip install yfinance

#import packages

import logging

import sys

import pandas as pd

import datetime

from time import sleep, strftime, time

import math

import yfinance as yf

#get data from yahoo finance

data = yf.download("SPY", start="2020-01-02", end="2020-05-01").reset_index(drop=True)



 

You’ve accumulated 312 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

Older messages

Valid board configurations

Monday, June 27, 2022

Python, Data Structures, Arrays, Algorithms, InterviewQs Valid board configurations Python Data Structures Arrays Algorithms Forward this email to a friend or colleague and challenge them to solve it.

Rejection reasons from binary classification model

Friday, June 24, 2022

Binary Classification, Statistics, Probability Distribution, Machine Learning, InterviewQs Rejection reasons from binary classification model Binary Classification Statistics Probability Distribution

Closest class scores

Wednesday, June 22, 2022

SQL, Database Querying, Cross Join, InterviewQs Closest class scores SQL Database Querying Cross Join Forward this email to a friend or colleague and challenge them to solve it. Hi, Suppose you are

Surveying class cheaters

Monday, June 20, 2022

Python, Bayes' Theorem, Binomial Distribution, Algorithms, PyMC3, InterviewQs Surveying class cheaters Python Bayes' Theorem Binomial Distribution Algorithms PyMC3 Forward this email to a

Maximum sliding subarrays

Friday, June 17, 2022

Python, Data Structures, Arrays, Algorithms, InterviewQs Maximum sliding subarrays Python Data Structures Arrays Algorithms Forward this email to a friend or colleague and challenge them to solve it.

You Might Also Like

Edge 389: Understanding Large Action Models

Tuesday, April 23, 2024

One of the most important concepts in autonomous agents. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Apple World Cup bid ⚽, Meta opens VR OS 🌎, Anthropic's prompt library 🤖

Tuesday, April 23, 2024

Apple is working to secure an exclusive TV deal with FIFA Sign Up |Advertise|View Online TLDR Together With WorkOS TLDR 2024-04-23 WorkOS is the only auth provider your B2B SaaS app needs to start

New Blogs on ThomasMaurer.ch for 04/23/2024

Tuesday, April 23, 2024

View this email in your browser Thomas Maurer Cloud & Datacenter Update This is the update for blog posts on ThomasMaurer.ch. Cloud operations for Windows Server through Azure Arc By Thomas Maurer

Post-Post 🗨️

Tuesday, April 23, 2024

Assessing the post-Twitter climate amid Post.News' shutdown. Here's a version for your browser. Hunting for the end of the long tail • April 22, 2024 Post-Post The demise of Post, one of the

BetterDev #257 - Building a GPS Receiver

Monday, April 22, 2024

Better Dev #257 Apr 22, 2024 Hi all, We come back with a new issue this week. If you like BetterDev, please help spead word out by refer to your friends. Buy me a coffee would be great too. This week I

Tomorrow's Free Notes Class: How to sign up!

Monday, April 22, 2024

Hi there, Tomorrow we will be hosting a Free Notes App Class. This is your last chance to register for tomorrow's live class and learn how to get the most out of your Notes app. Our experienced

Elon’s ‘balls to the wall’ autonomy push

Monday, April 22, 2024

Plus: Amazon ends California drone deliveries and Rippling's founder has a brand-new bag View this email online in your browser By Christine Hall Monday, April 22, 2024 Image Credits: Toru Hanai/

📱 Your iPhone is Now Discoverable by Others — Tips for Building Your First PC

Monday, April 22, 2024

Also: How to Play Windows Games on Your Mac, and More! How-To Geek Logo April 22, 2024 📩 Get expert reviews, the hottest deals, how-to's, breaking news, and more delivered directly to your inbox by

JSK Daily for Apr 22, 2024

Monday, April 22, 2024

JSK Daily for Apr 22, 2024 View this email in your browser A community curated daily e-mail of JavaScript news It Is so Cool to Develop React Native With Expo 1. What are the benefits of Expo?. "

😺 The social walkie-talkie

Monday, April 22, 2024

Hi, hi! It's Monday and it's Earth Day! Don't miss the Cat Nips section below for innovative products in the... Product Hunt Read in browser This newsletter is brought to you by YOU MIGHT