AlgoBulls - Python Developer - Strategy - Coding Assignment 1
AlgoBulls - Python Developer - Strategy - Coding Assignment 1
Coding Assignment
December 2022
Description: You need to code a simple trading strategy in a Jupyter Notebook as per the
given requirements:
1. Define a Class ScriptData which can fetch US Stock data using Alpha Vantage.
[Use this link to get your FREE API Key].
The class should implement the following methods:
a. fetch_intraday_data: (method arguments: script)
Fetches intraday data for given “script” (Example for script: “GOOGL”,
“AAPL”) and stores as it is.
b. convert_intraday_data: (method arguments: script)
Converts fetched intraday data (in point a.) as a pandas DataFrame
(hereafter referred as “df”) with the following columns:
i. timestamp (data type: pandas.Timestamp)
ii. open (data type: float)
iii. high (data type: float)
iv. low(data type: float)
v. close (data type: float)
vi. volume (data type: int)
c. Additional methods for overloading the following operations:
i. getitem
ii. setitem
iii. contains
(The output data may differ for you based on which date you run this code, but the format should be the same)
2. Define a function called indicator1. It should take “df” and ‘timeperiod’ (integer) as
inputs and give another pandas DataFrame as an output with two columns:
a. timestamp: Same as ‘timestamp’ column in ‘df’
b. indicator: Moving Average of the ‘close’ column in ‘df’. The number of
elements to be taken for a moving average is defined by ‘timeperiod’. For
example, if ‘timeperiod’ is 5, then each row in this column will be an average
of total 5 previous values (including current value) of the ‘close’ column.
Some sample code has been given below which shows how the above function will be used:
3. Define a class Strategy, which can do the following, given a script name:
a. Fetch intraday historical day (‘df’) using ScriptData class.
We’ll refer to the ‘close’ column of ‘df’ as close_data.
b. Compute indicator data on ‘close’ of ‘df’ using indicator1 function.
We’ll refer to the ‘indicator’ column of this data as indicator_data.
c. Generate a pandas DataFrame called ‘signals’ with 2 columns:
i. ‘timestamp’: Same as ‘timestamp’ column in ‘df’
ii. ‘signal’: This column can have the following values:
1. BUY (When: If indicator_data cuts close_data upwards)
2. SELL (When: If indicator_data cuts close_data downwards)
3. NO_SIGNAL (When: If indicator_data and close_data don’t cut
each other)
1. Python 3.8+
2. Jupyter Notebook (latest)
3. 3rd party Python modules:
a. alpha_vantage
b. pandas
c. numpy
d. [OPTIONAL] pyalgotrading
Objective:
1. Please come up with a git repo containing a Jupyter Notebook that can
accommodate all the requirements.
2. The Jupyter Notebook should run seamlessly. Just calling the Kernel -> Restart &
Run All option to do all that is necessary. There should be no errors and no
unnecessary code in the notebook.
3. The dependent Python packages must be captured in a requirements.txt file which
can be installed inside a virtualenv easily. The Jupyter Notebook should also be run
after sourcing the virtualenv.
Duration:
The ideal time is 3 days. If you need extra time, please request the same with appropriate
reasoning.
How to submit:
1. Please upload your code on a private GitHub repo and share it with our GitHub
user-id - algobulls-dev, hruturaj-nikam-algobulls. Include the Postman Collection
as well in the repo.
2. Make sure your code is cleaned up as per PEP8 standards, before you do the final
submission. It is ok to keep pushing any number of intermediate code commits.
3. Add sufficient comments for complex logic, before you do the final submission.
4. Include a README that includes basic documentation on how to run the code.
5. Once done, please send a mail to developers@algobulls.com &
hruturaj.nikam@algobulls.com, mentioning your name and GitHub ID, requesting a
review. Attach this coding assignment pdf to the mail as well. We may request you to
set up a screen sharing session for discussion purposes.