Colab file link: https://colab.research.google.com/drive/1NMn6RoW30tW5aYenjjz5bq_FwPbS-Bcr?usp=sharing
Task 1: Stock Data Analysis
- Using Python, fetch historical stock data for any 5 stocks from the Nifty 50 index using the
yfinance
library. Use a time range of the last 6 months. - Perform the following analyses on the data: a. Calculate the daily percentage change for each stock. b. Plot the closing prices and daily percentage changes for the 5 stocks. c. Calculate the moving average (20-day) for each stock and plot it against the stock's closing price.
Task 2: Strategy Development
- Develop a simple moving average crossover strategy for one of the 5 stocks. The strategy should involve a short-term moving average (e.g., 50-day) and a long-term moving average (e.g., 200-day).
- Backtest this strategy on the historical data to identify buy and sell signals.
- Calculate the returns generated by the strategy compared to a simple buy-and-hold approach.
Task 3: Risk Management
- Calculate the maximum drawdown for each stock over the 6-month period.
- For the stock you selected in Task 2, implement a stop-loss mechanism. Assume a stop loss of 5%. Re-run the strategy with the stop-loss and compare the performance to the original strategy.