1. Homepage
  2. Programming
  3. 5QQMN534: Algorithmic Finance Coursework: Resampling Returns Data and Strategy Analysis

5QQMN534: Algorithmic Finance Coursework: Resampling Returns Data and Strategy Analysis

Engage in a Conversation
KCL5QQMN534Algorithmic FinanceStrategy AnalysisPython

5QQMN534: Algorithmic

Finance CourseNana.COM

Independent Final Assignment Questions (75% Total Weight) CourseNana.COM

Individual Assignment: Information CourseNana.COM

Deadline: CourseNana.COM

• Practical Python coding knowledge from workshops 1-10 and practical coding workshops Weeks 1 – 9. CourseNana.COM

General Expectations: CourseNana.COM

Zipping for PC: Part A CourseNana.COM

  1. PARTA_5QQMN534_question1_final_template.py and PARTA_5QQMN534_question2_final_template.py and PARTA_5QQMN534_question3_final_template.py and results folder. CourseNana.COM

  2. Right click send to compress (zipped) folder. CourseNana.COM

  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. CourseNana.COM

  4. The results should be clearly labelled in your Results folder for each exercise. CourseNana.COM

  5. Name the .zip file like this. E.g. candidateID_5QQMN534_I_PartA_solutions.zip CourseNana.COM

  6. Submit the .zip file on KEATS to Submission Link provided also with your part B theory answers word or pdf file. CourseNana.COM

Part A Practical Coding (70%) CourseNana.COM

  • Part A Exercise data and .py code templates for each question for Part A is located in: CourseNana.COM

  • PARTA_5QQMN534_question123_code_templates.zip and PARTA_5QQMN534_question123_data.zip on KEATS. CourseNana.COM

  • Please download this and extract. CourseNana.COM

Part A: Question1: Resampling Returns Data (20 marks) CourseNana.COM

  1. a)  Read in the msft_returns.xlsx file provided in Q1_data folder into a DataFrame and name the variable returns. (0.5 mark) CourseNana.COM

  2. b)  Calculate the Simple Returns of the MSFT Adjusted Close Data in a New Column called sim_ret (0.5 mark) CourseNana.COM

  3. c)  Calculate the log returns of the MSFT Adjusted Close Data in a New Column called _log_ret (0.5 mark) CourseNana.COM

  4. d)  Calculate the cumulative returns from the daily log returns in a new column called cum_ret_log (0.5 mark) CourseNana.COM

  5. e)  Calculate the cumulative returns from the daily simple returns in a new column called cum_ret_sim (0.5 mark) CourseNana.COM

  6. 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 CourseNana.COM

    screen. (1 mark) CourseNana.COM

  7. g)  Calculate monthly returns from daily log returns to six decimal places. Print out the last five rows to screen. (1 mark) CourseNana.COM

  8. 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) CourseNana.COM

  9. k)  Save the Monthly Return Log, Monthly Ret Simple, Monthly Cumulative Return into a new DataFrame called monthly_rets (1 mark) CourseNana.COM

  10. l)  From the monthly_rets, isolate and plot the monthly simple returns for year 2000 and year 2020 in separate bar chart graphs. (2 marks) CourseNana.COM

  11. 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. From the descriptive statistics, plot the mean, std in a bar graph and then plot the min and max in another bar graph. 4 marks) CourseNana.COM

  12. n)  Calculate the annual yearly return and provide code for a double check that the cumulative yearly return = daily cumulative return. (2 marks) CourseNana.COM

  13. o)  Calculate the descriptive statistics on all months for each year. Note: Results should be different from part m. The DataFrame index should be months and the CourseNana.COM

    columns are the years. (1 mark) CourseNana.COM

p) Using the DataFrame obtained from part o) How many total monthly returns outliers have there been that are greater than 20% 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) CourseNana.COM

Part A: Q2: Strategy Analysis (25 marks) CourseNana.COM

You are a research analyst for AlphaMasterFOF a ‘fund of funds’. This is a type of fund that invests in other hedge funds. CourseNana.COM

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’. CourseNana.COM

The mandate for the allocation is as follows: CourseNana.COM

Part A: Q2: Strategy Analysis (25 marks) CourseNana.COM

  1. a)  Load the "strategy_returns.xlsx” file in Q2_data folder . Save this as a DataFrame variable called strat_ret (0.5 marks) CourseNana.COM

  2. b)  Calculate the skew and kurtosis on the strategy returns. Print results to screen. Plot a histogram of returns and comment on the strategy returns distribution. CourseNana.COM

    Round results to four decimal places. (1.5 marks) CourseNana.COM

  3. 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 CourseNana.COM

    to four decimal places. (1.5 marks) CourseNana.COM

  4. 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 CourseNana.COM

    outputs to correct units. Round results to four decimal places. (1.5 marks) CourseNana.COM

  5. 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) CourseNana.COM

  6. 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) CourseNana.COM

  7. 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. Save all regression results to a csv or xlsx file. (3 marks) CourseNana.COM

  8. j)  Load the "hfri_index.xlsx” file in Q2_data folder. Calculate the HFRI simple percentage returns. Calculate the cumulative strategy daily returns and rebase this so begins with 1. Create a new DataFrame called returns_3 and match the index of the rebased cumulative strategy returns to the HFRI index returns 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 DataFrame index you will need to get the last monthly value return from the strategy cumulative rebased returns dates. (4 marks) CourseNana.COM

  9. 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. Save all regression results to an cs or xlsx file. (3 marks) CourseNana.COM

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) CourseNana.COM

Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics1 (25 marks) CourseNana.COM

  1. a)  Load the FB data from the excel file provided in folder Q3_Data. (0.5 mark) CourseNana.COM

  2. b)  Load the SPY (benchmark) data from the excel file provided in folder Q3_Data. (0.5 mark) CourseNana.COM

  3. c)  Extract FB Adjusted Close and create a new DataFrame called close(0.5 mark) CourseNana.COM

  4. d)  Write a function to calculate Wilder’s smoothing RSI on the FB Adjusted Close (See Screenshot CourseNana.COM

    to right for mathematics). Use N = 14. Save these results to the DataFrame called close. (4 CourseNana.COM

    marks) CourseNana.COM

  5. e)  Calculate the signals based off the below condition: (2 marks) CourseNana.COM

    • RSI<30=BUY CourseNana.COM

    • RSI>70=SELL
    *Note: 30 & 70 are the default parameters. CourseNana.COM

    N = 14 (setting default window) CourseNana.COM

  6. f)  Plot the RSI signal and graph adjusted stock close price in separate plots. Save graph. (2 marks) CourseNana.COM

Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics2 (25 marks) CourseNana.COM

g) Calculate the log returns for adjusted close for the stock (FB) and the benchmark (SPY). (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 CourseNana.COM

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 and print the final CourseNana.COM

cumulative returns to screen. (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  CourseNana.COM

  • Hint: Due to computational time, test optimal parameters with increment 10 first. CourseNana.COM

  • Time the optimisation in seconds and minutes and print to screen. CourseNana.COM

  • The optimised results should generate a DataFrame showing the RSI Buy, RSI Sell, N Window, market returns, strategy returns and outperformance. CourseNana.COM

  • 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) CourseNana.COM

    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) CourseNana.COM

Part A: Question 3: Wilder’s Smoothing Relative Strength Index (RSI) and Statistics3 (25 marks) CourseNana.COM

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) CourseNana.COM

  1. Sharpe Ratio CourseNana.COM

  2. Sortino Ratio CourseNana.COM

  3. Compound Annual Growth Rate (CAGR) CourseNana.COM

  4. Annual Volatility CourseNana.COM

  5. Calmar Ratio CourseNana.COM

  6. Maximum Drawdown CourseNana.COM

  7. Skewness (4dp) CourseNana.COM

  8. Kurtosis (4dp) CourseNana.COM

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) CourseNana.COM

CourseNana.COM

Part B Theory Questions (30 marks) CourseNana.COM

Question 4: (10 marks) CourseNana.COM

  1. a)  Explain and discuss the RSI optimal trading strategy statistic results compared to the benchmark obtained in Question3. (2.5 marks) CourseNana.COM

  2. b)  Explain how would you adapt your code to backtest on multiple stocks efficiently? (2.5 marks) CourseNana.COM

  3. d)  If you devised a logical single parameter set for back tested returns for three technical analysis trading strategies: (Simple Moving Average (SMA), Bollinger Bands and RSI). Could you use the efficient frontier portfolio optimisation technique to find optimal strategy weights for this multi-strategy portfolio? Explain. (2.5 marks) CourseNana.COM

Question 5: (10 marks)
What statistics would you calculate on a backtested strategy portfolio returns? Explain and discuss. CourseNana.COM

Question 6: (10 marks) CourseNana.COM

Explain simple and log returns. Explain how both are used to calculate cumulative returns. Discuss why this is important in portfolio management return calculations. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
KCL代写,5QQMN534代写,Algorithmic Finance代写,Strategy Analysis代写,Python代写,KCL代编,5QQMN534代编,Algorithmic Finance代编,Strategy Analysis代编,Python代编,KCL代考,5QQMN534代考,Algorithmic Finance代考,Strategy Analysis代考,Python代考,KCLhelp,5QQMN534help,Algorithmic Financehelp,Strategy Analysishelp,Pythonhelp,KCL作业代写,5QQMN534作业代写,Algorithmic Finance作业代写,Strategy Analysis作业代写,Python作业代写,KCL编程代写,5QQMN534编程代写,Algorithmic Finance编程代写,Strategy Analysis编程代写,Python编程代写,KCLprogramming help,5QQMN534programming help,Algorithmic Financeprogramming help,Strategy Analysisprogramming help,Pythonprogramming help,KCLassignment help,5QQMN534assignment help,Algorithmic Financeassignment help,Strategy Analysisassignment help,Pythonassignment help,KCLsolution,5QQMN534solution,Algorithmic Financesolution,Strategy Analysissolution,Pythonsolution,