QQMN534 FINAL Independent Coursework Questions

5QQMN534: Algorithmic
Independent Final Assignment Questions (75% Total Weight)

Individual Assignment: Information
• Start Date: 31/03/2023 10am
• End date: 28/04/2023 10am
• Part A: Practical Coding: 3 questions. 70%
• Part B: Theory: 3 questions 30%
• Questions have sub marks.
• Total mark is scored out of 100.
Content covered:
• Practical Python coding knowledge from workshops 1-10 and practical coding workshops Weeks 1 – 9.
General Expectations:
• Expectation is to use good practice such as commenting and correct code formatting.
• The program should work and display correct outputs.
• Demonstrate good knowledge to solve problems.
• Minimise duplicate code.
• Demonstrate efficient, well structured code design.

Individual Assignment: Submission
• Individual submissions are to be submitted on KEATS. For this assessment you must submit TWO items (Part A and Part B) to the submission link provided below. One submission to be made per individual.
• Part A Practical: You must submit a .zip file. This .zip file must include the PARTA_5QQMN534_question1_final_template.py and PARTA_5QQMN534_question2_final_template.py and PARTA_5QQMN534_question3_final_template.py (all code solutions) and a .docx word or pdf file with screenshots of your code as well. Also include in this zip file any generated images or excel results. Please save each result in a folder. For example your folder would be. Results. Name your result outputs correctly. E.g. 1f_result.xlsx. Name the .zip file like this. E.g. candidateID_5QQMN534_PartA_solutions.zip
• Part B Theory: You must submit a separate word or PDF file. Please use the cover sheet document provided, complete the cover sheet (add your candidate number) and on the pages following the cover sheet. Please call this file for example: candidateID_5QQMN534_PartB_Solutions.pdf OR candidateID_5QQMN534_PartB_Solutions.docx
• Please note that when uploading your work, you will receive a notification that Turnitin has failed for the .zip folder but this is expected and your work is still accessible to the marker and will be counted as received. Once you receive this error message, there is no further action you need to take.
• Please note that your Part B Theory word or PDF file should be acknowledged by Turnitin and so if you receive an error message for both uploads, contact

Individual Assignment: Submission
• Submit your work WELL before the deadline. If your work is slow to upload because you have left it until the last few minutes and you miss the deadline, this will not be acceptable grounds for late submission
• After submission, check your submission: go back into the submission link and view your submission – make sure it has submitted successfully, and you have submitted the document you meant to submit
• If you experience technical difficulties and are unable to upload your assessment by the deadline, please collate evidence of the technical issue and submit a mitigating circumstances form (MCF). Remember that the evidence must clearly show timestamps and proof that you attempted to upload your assessment before the deadline
• In line with King’s College London Academic Regulations (Regulation 4.27) your work must be submitted on time. Students who submit their work within 24-hours after the deadline, these will be marked but 10 raw marks will be deducted from the coursework mark. If the deduction takes a student below the pass mark, the coursework mark will be capped at the pass mark. Work submitted after the 24-hour deadline will receive a mark of 0.

Submission: How to create a .zip file help
• Mac: https://support.apple.com/en-gb/guide/mac-help/mchlp2528/mac
• PC: https://support.microsoft.com/en-us/windows/zip-and-unzip-files-8d28fa72-f2f9-712f-67df- f80cf89fd4e5#:~:text=To%20zip%20(compress)%20a%20file,created%20in%20the%20same%20location

Zipping for PC: Part A
1. PARTA_5QQMN534_question1_final_template.py and PARTA_5QQMN534_question2_final_template.py and PARTA_5QQMN534_question3_final_template.py and results folder.
2. Right click send to compress (zipped) folder.
3. You must submit a .zip file. This .zip file must include the PARTA_5QQMN534_question1_final_template.py and PARTA_5QQMN534_question2_final_template.py and PARTA_5QQMN534_question3_final_template.py (all code solutions) and a .docx word or pdf file with screenshots of your code as well. Also include in this zip file any generated images or excel results. Please save each result in a folder. For example your folder would be called. Results. Very important, please name your result outputs correctly. E.g. 1f_result.xlsx. Etc.
4. The results should be clearly labelled in your Results folder for each exercise.
5. Name the .zip file like this. E.g. candidateID_5QQMN534_I_PartA_solutions.zip
6. Submit the .zip file on KEATS to Submission Link provided also with your part B theory answers word or pdf file.

Part A Practical Coding (70%)
• Part A Exercise data and .py code templates for each question for Part A is located in:
• PARTA_5QQMN534_question123_code_templates.zip and PARTA_5QQMN534_question123_data.zip on KEATS.
• Please download this and extract.

Part A: Question1: Resampling Returns Data (20 marks)
a) Read in the msft_returns.xlsx file provided in Q1_data folder into a DataFrame and name the variable returns. (0.5 mark)
b) Calculate the Simple Returns of the MSFT Adjusted Close Data in a New Column called sim_ret (0.5 mark)
c) Calculate the log returns of the MSFT Adjusted Close Data in a New Column called _log_ret (0.5 mark)
d) Calculate the cumulative returns from the daily log returns in a new column called cum_ret_log (0.5 mark)
e) Calculate the cumulative returns from the daily simple returns in a new column called cum_ret_sim (0.5 mark)
f) Check cum_ret_log total cumulative return and cum_ret_sim total cumulative returns are the same value. Round to four decimal places. Print out a confirmation to
screen. (1 mark)
g) Calculate monthly returns from daily log returns to six decimal places. Print out the last five rows to screen. (1 mark)
h) Calculate monthly returns from simple returns to six decimal places. Print out the last five rows to screen. (1 mark)
i) Save the Monthly Log and Simple Returns DataFrames to separate excel files. Note: Results in part g and h should be the same. (0.5 mark)
j) Calculate the Monthly Total Cumulative Return from the Monthly Returns and check it is equal to the Total cumulative Daily Returns. Round to four decimal places. Print out this confirmation and print out the last five rows to screen. (1 mark)
k) Save the Monthly Return Log, Monthly Ret Simple, Monthly Cumulative Return into a new DataFrame called monthly_rets (1 mark)
l) Plot the monthly returns for year 2000 and year 2020 in a bar chart in separate graphs. (2 marks)
m) Calculate descriptive statistics for each month on all years and save the results to a DataFrame. Note: Each year includes all monthly returns January to December. Years should be the index. Months should be the columns. Plot the mean, std in a bar graph and then plot the min and max in another bar graph. (4 marks)
n) Calculate the annual yearly return and provide code for a double check that the cumulative yearly return = daily cumulative return. (2 marks)
o) Calculate the descriptive statistics on all months for each year. Note results should be different from part m. (1 mark)
p) How many total monthly returns outliers have there been that are greater or less than 20%? How many negative and how many positive outliers? What dates did these outliers occur on? Print results to screen. (3 marks)
Code Help
Part A: Q2: Strategy Analysis (25 marks)
You are a research analyst for AlphaMasterFOF a ‘fund of funds’. This is a type of fund that invests in other hedge funds.
Your fund is considering investing in a strategy that has been trading for several years. The live performance record of the strategy is in the file ‘Strategy_returns.xlsx’.
The returns of the S&P 500, are in ‘SP 500 returns.xlsx’.
The values of a relevant index, the HFRI Macro CTA index, are in ‘hfri_index.xlsx’.
The mandate for the allocation is as follows:
• Strategy Annual Sharpe Ratio over 0.8
• Low correlation with the S&P 500
• Low Beta and high Alpha compared to the S&P 500
• High correlation with the CTA index
• Strategy Annual return standard deviation volatility between 15% and 25%
• Strategy employing good risk management, evidenced by a stable annual volatility year on year (YoY).

Part A: Q2: Strategy Analysis (25 marks)
a) Load the “strategy_returns.xlsx” file in Q2_data folder . Save this as a DataFrame variable called strat_ret (0.5 marks)
b) Calculate the skew and kurtosis on the strategy returns. Plot a histogram of returns and comment on the strategy returns distribution. Round results to four
decimal places. (1.5 marks)
c) Calculate the daily mean, standard deviation and Sharpe Ratio. Assume daily risk free is zero. Print results to screen. Format outputs to correct units. Round results
to four decimal places. (1.5 marks)
d) Calculate the annual mean, standard deviation and Sharpe Ratio. Assume annual risk free is zero. Assume 252 days per year. Print results to screen. Format
outputs to correct units. Round results to four decimal places. (1.5 marks)
e) Calculate the daily rolling volatility starting from day 252.Then extract this statistic on the 2nd January each year from 2015 to 2021. Then annualise this value. Assume 252 days per year. Create a DataFrame. The Index as 2nd January each year 2015 to 2021 as Dates, daily rolling volatility on that date, third column annual volatility. Print DataFrame to screen. (4 marks)
f) Plot a well formatted displayed bar graph of the Annual Volatility from part e. Show the y axis range from 15% to 20%. (2 marks)
g) Complete an if statement to check if the average annual volatility between 2015 and 2021 from part e is between the lower 15% and upper 25% standard
deviation thresholds as specified by mandate. (1 mark)
h) Load the “SP500_returns.xlsx” file in Q2_data folder. Create a new DataFrame called returns_2 and match the returns of the strategy and S&P500 returns using
the dates from the strategy as the index. Set S&P 500 returns that are nan as zero. (1 marks)
i) Run an OLS regression between the strategy returns and S&P500 market benchmark returns. State which is the dependent and independent variable in a comment. Save all model results to a DataFrame. Extract Beta, Alpha and R-Squared from regression results to variables. Annualise the alpha. N = 252 days. Calculate the correlation. Round result values to four decimal places and print to screen. (3 marks)
j) Load the “hfri_index.xlsx” file in Q2_data folder. Calculate the HFRI simple percentage returns. Create an Index for your strategy daily returns rebasing to begin with 1. Create a new DataFrame called returns_3 and match the rebased index of the strategy and HFRI index using the monthly dates from the HFRI. Note: There should be no NaN’s in the matched DataFrame. Hint: If the strategy rebased dates do not match the HFRI monthly dates exactly in the index you will need to get the last monthly value from the strategy rebased dates. (4 marks)
k) Run an OLS regression between strategy returns and HFRI market benchmark returns. State which is the dependent and independent variable in a comment. Save model results to a DataFrame. Extract Beta, Alpha and R-Squared from regression results to variables. Annualise the alpha. N = 252 days. Calculate the correlation. Round result values to four decimal places and print to screen. Note: HFRI price indexes are monthly. (3 marks)
l) Discuss the difference in results between part i and k in a comment. Is the strategy meeting the mandate requirements? Maximum 300 words. (2 marks)

Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics1 (25 marks)
• Do not use libraries for the RSI technical indicator.
• Write the mathematics for the Wilder Smoothing RSI indicator yourself.
• Write the functions and mathematics for portfolio metrics
• Use log returns
a) Load the FB data from the excel file provided in folder Q3_Data. (0.5 mark)
b) Load the SPY data from the excel file provided in folder Q3_Data. (0.5 mark)
c) Extract FB Adjusted Close and create a new DataFrame called close. (0.5 mark)
d) Write a function to calculate Wilder’s smoothing RSI on the FB Adjusted Close (See Screenshot
to right for mathematics). Save these results to the DataFrame called close. (4 marks)
e) Calculate the signals based off the below condition: (2 marks)
• RSI<30=BUY • RSI>70=SELL
*Note: 30 & 70 are the default parameters.
N = 14 (setting default window)
f) Plot the RSI signal and graph adjusted stock close price in separate plots. Save graph. (2 marks)
程序代写 CS代考 加微信: cstutorcs
Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics2 (25 marks)
g) Calculate the log returns for adjusted close for the stock and the benchmark. (0.5 mark)
h) Calculate the strategy returns. The basic idea is that the algorithm can only set up a position in the stock given today’s market data (e.g., just before the close). The
position then earns tomorrow’s return. (0.5 mark)
i) Calculate cumulative returns for buy and hold the stock, the strategy and the benchmark. Double check your result with various approaches. (1 mark) j) Plot cumulative returns from the log returns for buy and hold the stock, the strategy and the benchmark. (0.5 mark)
k) Calculate descriptive statistics on the stock, the strategy and benchmark returns. Save to a DataFrame. (0.5 mark)
l) Optimise the RSI with the below condition ranges: (3 marks)
• rsi_buy between 0 and 30 with increment 1
• rsi_sell between 70 and 100 with increment 1
• n_window between 2 and 21 with increment 1
• Hint: Due to computational time, test optimal parameters with increment 10 first.
• Time the optimisation in seconds and minutes and print to screen.
• The optimised results should generate a DataFrame showing the RSI Buy, RSI Sell, N Window, market returns, strategy returns and outperformance.
• Note: Outperformance is Strategy Returns – Market Returns
m) Sort the optimised parameter results on outperformance. Save results to an excel file. (0.5 mark) n) Extract the optimal parameters (0.5 mark)
o) Rerun the optimal parameter strategy. Plot the RSI and signals and cumulative return graphs. Re-calculate the cumulative performances using the optimal parameters. (2 marks)

Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics3 (25 marks)
p) Isolate the optimal strategy returns and calculate the below performance statistics on this strategy and the benchmark: Assume risk free = 0 and 252 days per year. Format to 2 decimal places. Write functions and store all results in a DataFrame and save to excel. Do not use a library. (4 marks)
i. Sharpe Ratio
ii. Sortino Ratio
iii. Compound Annual Growth Rate (CAGR)
iv. Annual Volatility
v. Calmar Ratio
vi. Maximum Drawdown
vii. Skewness (4dp)
viii. Kurtosis (4dp)
q) Calculate the number of total trades, long trades and short trades for the optimal strategy. Save as a DataFrame. (2 marks) r) Plot a histogram of the optimal strategy returns vs benchmark returns. (0.5 mark)
Computer Science Tutoring
Part B Theory Questions (30 marks)
Question 4: (10 marks)
a) Explain and discuss the RSI optimal trading strategy statistic results compared to the benchmark obtained in Question3. (2.5 marks)
b) Explain how would you adapt your code to backtest on multiple stocks efficiently? (2.5 marks)
c) If you backtested the RSI strategy on multiple stocks would you use the optimal parameter for each stock or would you decide on a single parameter set that would be used across all stocks and equal weight the strategy returns? Explain. (2.5 marks)
d) If you devised a logical single parameter set for back tested returns for three strategies: (SMA, Bollinger and RSI). Could you use the efficient frontier portfolio optimisation technique to find optimal strategy weights for a multi-strategy portfolio. Explain. (2.5 marks)
Question 5: (10 marks)
What statistics would you calculate on a backtested strategy portfolio returns? Explain and discuss.
Question 6: (10 marks)
Explain simple and log returns. Explain how both are used to calculate cumulative returns. Discuss why this is important in portfolio management return calculations.