CS代考 9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
Walleye Capital / Quantic – Pandas Coding Test
Below, you will be asked to complete a series of coding tasks of ascending complexity. Please consider the following criteria:
High quality code is legible, standard-conformant, testable, well-documented, and of course correct.

Copyright By PowCoder代写 加微信 powcoder

You may import any additional libraries or look up definitions, APIs, etc. as you deem necessary.
Feel free to skip any questions you get stuck on, although some of them are necessary to do the later questions.
This is your opportunity to demonstrate your research intuition and creativity! Make the most of it.
When you are done, please download the .ipynb from Google Colab and send it back to me via e-mail.
Introduction / Setup
import numpy as np
import pandas as pd
import seaborn as sns
import statsmodels.api as sm
import statsmodels.formula.api as smf
from tqdm import tqdm
# feel free to import anything else you might want.
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 1/8

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
import requests, zipfile, io
def get_zipped_data(zipname, filename):
r = requests.get(f’https://github.com/wwang-walleye/walleye-coding- z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall()
return pd.read_csv(z.open(filename))
univ = get_zipped_data(‘ct-data-2-univ.zip’, ‘coding_test_univ.csv’) brtn = get_zipped_data(‘ct-data-2-brtn.zip’, ‘coding_test_brtn.csv’)
Below, please find two dataframes as follows:
univ is a dataframe which specifies an investment universe over 5 years of contiguous trading days. The columns have the following definitions:
1. date – hopefully self-explanatory.
2. secid – a unique identifier for a given company (analogous to ticker).
3. gic2 – a discrete variable indicating sector membership. All secid with the same value
for gic2 are members of the same sector.
4. mktcap_usd – the market cap of the company, in $mm
5. fcfev – Last Twelve Months Free Cash Flow to Enterprise Value 6. ebitmargin – Last Twelve Months EBIT Margin
7. ebitdatoast Last Twelve Months EBITDA / Total Assets
The rows matching each date in univ indicate that a given secid is a constituent of the universe on that date .
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 2/8

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
univ.head()
date secid gic2 mktcap_usd
fcfev ebitmargin ebitdatoast
0 2016-01-04
1 2016-01-04
2 2016-01-04
3 2016-01-04
4 2016-01-04
0 20 1 40 2 25 3 10 4 35
90313.900134 10833.064304 16774.036628
8677.376308 37762.666869
0.023822 NaN 0.036039 -0.191412 0.044087
0.2316 0.268525 0.4576 0.021690 0.0939 0.225384
-0.2960 0.063772 0.1018 0.077138
brtn is a dataframe which specifies the trailing 1-day return of a given secid on a given
date . Assume that the data in brtn is complete (i.e., it is not missing any trading days). Note that on a given date, any secid in the brtn dataframe may or may not be in the universe (i.e., the set of stocks in univ is a subset of the set of stocks in brtn on any given date).
brtn.head()
0 2016-01-04 1 2016-01-04 2 2016-01-04 3 2016-01-04 4 2016-01-04
date secid
-0.026300 -0.016818 -0.025832
0.017681 0.001805
Basic pandas operations (2 points each)
Please write some code to perform the following basic tasks:
1. Print the data types in univ and brtn . Does anything look off? If so, fix that issue in- place (i.e., mutate univ and brtn accordingly).
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 3/8

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
2. Set an appropriate index on univ and brtn , and then sort by the index. Do this in- place (i.e., overwrite univ and brtn ).
3. Count the number of securities in univ on each date.
4. Count the number of securities in each sector ( gic2 ) on each date.
5. Plot the number of securities in each sector through time in an appropriate way.
6. Compute the average return for each stock in the universe on each date. A simple
arithmetic mean here suffices.
More complex tasks (4 points each)
1. Write a function that does the following:
A. Given a date dt , finds the subset of stocks in univ on dt .
B. Finds all rows in brtn matching the date range ( dt – 1 year , dt ).
C. Returns a dataframe of all daily returns matching the universe in 1.1 over the dates
# Print the dtypes for both dataframes.
# Do any of the data types look inappropriate? If so, please fix them.
# Set an appropriate index on univ and brtn, then sort by this index.
# A good index should uniquely identify every row.
# Show the number of securities in univ on each date
# Show the number of securities in each sector on each date
# Plot the number of securities in each sector over time.
# Compute the average return for all stocks in `univ` by date.
matching 1.2 .
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 4/8

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
2. Write a function that computes the 1-year daily beta as of dt for every stock in univ against the equally-weighted universe (i.e., the average return). Beta is a measure of risk, and it indicates how much a stock’s returns covary with the universe’s returns. The formula for beta is:
3. Compute the 1-year total return for each stock in the universe as of some dt . Make a chart comparing this total return figure to the betas you produced by running
get_betas() .
# trailing year’s daily returns for the univ as of `dt`
def get_univ_brtn(dt: pd.Timestamp, lookback: int = 252) -> pd.DataFram “”” Returns the trailing returns over some lookback window as of a
Parameters
———-
dt : pd.Timestamp
ub : pd.DataFrame or pd.Series
ub = get_univ_brtn(pd.Timestamp(‘2018-06-27’)) ub
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 5/8
)𝐵(𝑟𝑎 𝑉/)𝐵 ,𝐴(𝑟𝑎𝑣𝑜𝐶 = )𝐵 ,𝐴(𝑎𝑡𝑒𝐵

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
# compute 1-year trailing beta to the universe as of `dt`
def get_betas(univ_brtn: pd.DataFrame) -> pd.Series:
“”” Returns the 1-year trailing beta to the cross-sectional mean.
Parameters
———-
univ_brtn: pd.DataFrame
betas : pd.Series
The beta of each security to the daily cross-sectional mean in
betas = get_betas(ub)
Price Momentum (10 points)
1. Write a function that produces some price momentum signals: A. Trailing compound returns over prior 10 days
B. Trailing compound return over the trailing 252 days
# plot the betas on a given date against the trailing 1-year return as
2. Write another function that adjusts a signal (eg, 252-day momentum) for beta and sector ( gic2 ) in a way that you think is reasonable.
def calculate_compound_return(dt: pd.Timestamp, lookback: int) -> pd.Se “”” 1.1 “””
def calculate_momentum(dt: pd.Timestamp) -> pd.Series: “”” 1.2 “””
Putting it together (20 points in total)
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 6/8

Putting it together (20 points in total)
9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
1. In addition to the price momentum signals you just calculated, consider the other data items made available in the univ dataframe, or that you can calculate in conjunction with the brtn dataframe. Can you think of any interesting or effective signals you can calculate from this data? Be creative!
A. Write a function that takes dt as an argument and returns a DataFrame with all of your signals.
2. Applying a group of signals in an investment process can be tricky. One way to decide whether we should buy or sell a given security conditioned on several signals that might disagree is to aggregate all the signals into a single number. Can you think of a good way to do this? Be creative!
A. Write a function make_alpha() that takes a dataframe of signals as an argument and returns a Series alpha that you think predicts stock returns.
3. Find the last date of each month in univ and calculate make_alpha() for each of those dates; combine all the relevant data into a single dataframe.
4. Perform some exploratory analysis on the data set you’ve created. This is your opportunity to be creative! What can you tell us about these signals? Some suggestions below … if you are applying with many years of experience consider these less than optional:
A. Plot descriptive information about these signals.
B. Calculate the returns of these signals (in a reasonable and correct way).
C. Describe the signals with metrics you find informative (sharpe, turnover, etc.)
D. Add new normalizations, neutralizations, time series operations, etc. that are
economically interesting.
5. What are some limitations with the research process we’ve conducted so far? What are
some things you would do differently, given more resources and/or time?
def make_signals(dt: pd.Timestamp) -> pd.DataFrame: “”” 1.1 “””
def make_alpha(signals: pd.DataFrame) -> pd.Series: “”” 1.2 “””
signals = make_signals(pd.Timestamp(‘2018-06-27’)) signals[‘alpha’] = make_alpha(signals)
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 7/8

9/13/22, 10:33 PM Copy_of_walleye_signal_coding_test_v2 – Jupyter Notebook
# Produce the set of month-end dates
# Create a dataframe with the signals as of each month-end date
# Do some additional analysis — what can you tell us about the signal
localhost:8889/notebooks/Downloads/Copy_of_walleye_signal_coding_test_v2.ipynb# 8/8

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com