<jupyter_start><jupyter_text>Risky BusinessThis activity will involve calculating daily return data, standard deviation, annualized standard deviation, and Sharpe ratios as you analyze the risk and return metrics of each cryptocurrency in the portfolio.Instructions:1. Import the required libraries and dependencies.2. Using the `read_csv` function and the `Path` module, read the `crypto_portfolio.csv` file into a Pandas DataFrame. Be sure to set a `DateTimeIndex`. Review the DataFrame by using both the `head` and the `tail` function.3. Using the Pandas `pct_change` function together with `dropna`, calculate the daily returns for the cryptocurrency portfolio DataFrame.4. Calculate the summary statistics for the DataFrame of cryptocurrency daily returns by calling the Pandas `describe` function.5. Create a box plot that visualizes the spread of the daily return values for each cryptocurrency.6. Answer the following question: based on the summary statistics and the box plot visualization, which cryptocurrency has the smallest spread and which has the largest?7. Calculate the annualized average daily return values. Then use the Pandas `sort_values` function to sort the values from smallest to largest.    > **Hint** To calculate the annualized average daily returns, multiply the mean for each cryptocurrency’s daily return value by the number of trading days in the year (252).8. Calculate the annualized standard deviations for the DataFrame of cryptocurrency daily returns. Sort the values from smallest to largest.    > **Hint** To calculate the annualized standard deviations, multiply the standard deviation of each cryptocurrency’s daily return value by the square root of the number of the number of trading days (`np.sqrt(252)`).9. Calculate the Sharpe ratio for each cryptocurrency. Sort the Sharpe ratios from smallest to largest.    > **Hint** To calculate the Sharpe ratio, divide the annualized average return by the annualized standard deviation.10. Plot the Sharpe ratios in a bar chart.11. Answer the following questions: Based on the risk and return metrics that you calculated, what cryptocurrency do you recommend that your firm invest in, and why? What’s your second choice?References:[Pandas std function](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.std.html)[NumPy sqrt function](https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html)[Pandas plot.bar function](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.bar.html)  Step 1: Import the required libraries and dependencies.<jupyter_code># Import the Pandas library
import pandas as pd

# Import the NumPy library
import numpy as np

# Import the Path module from the Pathlib library
from pathlib import Path

# Import the %matplotlib inline dependency
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Step 2: Using the `read_csv` function and the `Path` module, read the `crypto_portfolio.csv` file into a Pandas DataFrame. Be sure to set a `DateTimeIndex`. Review the DataFrame by using both the `head` and the `tail` function.<jupyter_code># Using the read_csv function and the Path module, read in the "crypto_portfolio.csv" file from the Resources folder
# Set the "Date" as the index column
# Be sure to set the DatetimeIndex using the parse_dates and infer_datetime_format parameters
crypto_portfolio_csvpath = Path('./Resources/crypto_portfolio.csv')
crypto_portfolio_df = pd.read_csv(crypto_portfolio_csvpath, index_col='Date', parse_dates=True, infer_datetime_format=True)

# Review the import by displaying both the head and tail functions
display(crypto_portfolio_df.head())
display(crypto_portfolio_df.tail())<jupyter_output><empty_output><jupyter_text>Step 3: Using the Pandas `pct_change` function together with `dropna`, calculate the daily returns for the cryptocurrency portfolio DataFrame.<jupyter_code># Using the Pandas pct_change function in conjunction with the dropna function, create the crypto daily returns DataFrame
crypto_daily_returns = crypto_portfolio_df.pct_change().dropna()

# Review the first 5 rows of the crypto daily returns DataFrame 
crypto_daily_returns.head()<jupyter_output><empty_output><jupyter_text>Step 4: Calculate the summary statistics for the DataFrame of cryptocurrency daily returns by calling the Pandas `describe` function.<jupyter_code># Generate summary statistics for the crypto daily returns DataFrame using the Pandas describe function
crypto_daily_returns.describe()<jupyter_output><empty_output><jupyter_text>Step 5: Create a box plot that visualizes the spread of the daily return values for each cryptocurrency.<jupyter_code># Using the Pandas plot function with the kind paramater set to the value box, visualize the spread of the crypto daily returns DataFrame
crypto_daily_returns.plot(kind='box', figsize=(15, 10), title='Cryptocurrency Daily Returns', ylabel='Daily Returns')<jupyter_output><empty_output><jupyter_text>Step 6: Answer the following question: based on the summary statistics and the box plot visualization, which cryptocurrency has the smallest spread and which has the largest? **Question:** Based on the summary statistics and the box plot visualization, which of the cryptocurrencies has the smallest spread, and which has the largest?**Answer:** Based on the summary statistics and the box plot visualization, XLM has the largest spread and BTC has the smallest spread.  Step 7: Calculate the annualized average daily return values. Then use the Pandas `sort_values` function to sort the values from smallest to largest.<jupyter_code># The number of trading days is set to 252 for use throughout these calculations
trading_days = 252

# Calculate the annual average daily returns for the crypto currencies
# Use the Pandas mean function to calculate the average daily return for each cryptocurrency 
# Then multiply that value by the number of trading days in a year, using the trading_days variable set above 
annual_average_crypto_returns = crypto_daily_returns.mean() * trading_days

# Sort the annual average returns for the cryptocurrencies from lowest to highest
annual_average_crypto_returns.sort_values()<jupyter_output><empty_output><jupyter_text>Step 8: Calculate the annualized standard deviations for the DataFrame of cryptocurrency daily returns. Sort the values from smallest to largest.<jupyter_code># Calculate the annualized standard deviation for the cryptocurrencies
# Use the Pandas std function to calculate the standard deviation for each cryptocurrency
# Multiply the standard deviation by the square root (using the NumPy sqrt function) of the number of trading days
annual_standard_deviation = crypto_daily_returns.std() * np.sqrt(trading_days)

# Sort the annual standard deviations for the cryptocurrencies from lowest to highest
annual_standard_deviation.sort_values()<jupyter_output><empty_output><jupyter_text>Step 9: Calculate the Sharpe ratio for each cryptocurrency. Sort the Sharpe ratios from smallest to largest.<jupyter_code># Calculate Sharpe ratios by dividing the annual average return of the cryptocurrencies 
# by the annual standard deviation of the cryptocurrencies
crypto_sharpe_ratios = annual_average_crypto_returns / annual_standard_deviation

# Sort the Sharpe ratios for the cryptocurrencies from lowest to highest
crypto_sharpe_ratios.sort_values()<jupyter_output><empty_output><jupyter_text>Step 10: Plot the Sharpe ratios in a bar chart.<jupyter_code># Using the Pandas plot.bar function, visualize the Sharpe ratios for the cryptocurrencies in a bar chart
# Be sure to adjust the figure size and include a title
crypto_sharpe_ratios.plot.bar(figsize=(15, 10), title='Cryptocurrency Sharpe Ratios', ylabel='Sharpe Ratio', rot=0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0558055805580558, 'fraction_numerical': 0.005914877202005915, 'mean_word_length': 6.168663594470046, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 40, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '116974', 'license': 'MIT', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1910, 'n_words': 923, 'path': '01_Risky_Business/risky_business.ipynb', 'repo_name': 'jpweldon/Module_4_Practice', 'size': '7777'}