<jupyter_start><jupyter_text>Crypto ArbitrageIn this Challenge, you'll take on the role of an analyst at a high-tech investment firm. The vice president (VP) of your department is considering arbitrage opportunities in Bitcoin and other cryptocurrencies. As Bitcoin trades on markets across the globe, can you capitalize on simultaneous price dislocations in those markets by using the powers of Pandas?For this assignment, you’ll sort through historical trade data for Bitcoin on two exchanges: Bitstamp and Coinbase. Your task is to apply the three phases of financial analysis to determine if any arbitrage opportunities exist for Bitcoin.This aspect of the Challenge will consist of 3 phases.1. Collect the data.2. Prepare the data.3. Analyze the data.    Import the required libraries and dependencies.<jupyter_code>#imports the necessary libraries and dependencies: pandas(calculations library), Path(necessary for file imports) and %matplotlib inline (so graphs can appear in the notebook)
import pandas as pd
from pathlib import Path
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Collect the DataTo collect the data that you’ll need, complete the following steps:Instructions. 1. Using the Pandas `read_csv` function and the `Path` module, import the data from `bitstamp.csv` file, and create a DataFrame called `bitstamp`. Set the DatetimeIndex as the Timestamp column, and be sure to parse and format the dates.2. Use the `head` (and/or the `tail`) function to confirm that Pandas properly imported the data.3. Repeat Steps 1 and 2 for `coinbase.csv` file.  Step 1: Using the Pandas `read_csv` function and the `Path` module, import the data from `bitstamp.csv` file, and create a DataFrame called `bitstamp`. Set the DatetimeIndex as the Timestamp column, and be sure to parse and format the dates.<jupyter_code># Read in the CSV file called "bitstamp.csv" using the Path module. 
# The CSV file is located in the Resources folder.
# Set the index to the column "Date"
# Set the parse_dates and infer_datetime_format parameters

#imports bitstamp.csv into a dataframe called bitstamp with all the required specifications for setting column, parsing dates, and infering date/time format
bitstamp = pd.read_csv("./Resources/bitstamp.csv", index_col = "Timestamp" , parse_dates = True, infer_datetime_format= True)<jupyter_output><empty_output><jupyter_text>Step 2: Use the `head` (and/or the `tail`) function to confirm that Pandas properly imported the data.<jupyter_code># Use the head (and/or tail) function to confirm that the data was imported properly.
# YOUR CODE HERE

#prints the top 5 rows of the bitstamp dataframe using the head function
bitstamp.head()<jupyter_output><empty_output><jupyter_text>Step 3: Repeat Steps 1 and 2 for `coinbase.csv` file.<jupyter_code># Read in the CSV file called "coinbase.csv" using the Path module. 
# The CSV file is located in the Resources folder.
# Set the index to the column "Timestamp"
# Set the parse_dates and infer_datetime_format parameters

#imports coinbase.csv into a dataframe called coinbase with all the required specifications for setting column, parsing dates, and infering date/time format
coinbase = pd.read_csv("./Resources/coinbase.csv", index_col = "Timestamp" , parse_dates = True, infer_datetime_format= True)
# Use the head (and/or tail) function to confirm that the data was imported properly.
# YOUR CODE HERE

#prints the top 5 rows of the coinbase dataframe using the head function
coinbase.head()<jupyter_output><empty_output><jupyter_text>Prepare the DataTo prepare and clean your data for analysis, complete the following steps:1. For the bitstamp DataFrame, replace or drop all `NaN`, or missing, values in the DataFrame.2. Use the `str.replace` function to remove the dollar signs ($) from the values in the Close column.3. Convert the data type of the Close column to a `float`.4. Review the data for duplicated values, and drop them if necessary.5. Repeat Steps 1–4 for the coinbase DataFrame.  Step 1: For the bitstamp DataFrame, replace or drop all `NaN`, or missing, values in the DataFrame.<jupyter_code># For the bitstamp DataFrame, replace or drop all NaNs or missing values in the DataFrame
# YOUR CODE HERE

#drops all the NaNs from the bitstamp dataframe using the dropna function
bitstamp = bitstamp.dropna()<jupyter_output><empty_output><jupyter_text>Step 2: Use the `str.replace` function to remove the dollar signs ($) from the values in the Close column.<jupyter_code># Use the str.replace function to remove the dollar sign, $
# YOUR CODE HERE

#This line of code replaces all the "$" with "" from the "Close" column of our DataFrame to allow us to convert the data type to float and be capable of analyzing it
bitstamp["Close"] = bitstamp["Close"].str.replace("$","")<jupyter_output>C:\Users\EdgarPocaterra-Susma\anaconda3\envs\dev\lib\site-packages\ipykernel_launcher.py:5: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will *not* be treated as literal strings when regex=True.
  """<jupyter_text>Step 3: Convert the data type of the Close column to a `float`.<jupyter_code># Convert the Close data type to a float
# YOUR CODE HERE

#This line of code replaces changes the data type of the "Close" column from str to float
bitstamp["Close"] = bitstamp["Close"].astype("float")<jupyter_output><empty_output><jupyter_text>Step 4: Review the data for duplicated values, and drop them if necessary.<jupyter_code># Review the data for duplicate values, and drop them if necessary
# YOUR CODE HERE

#This line of code finds and sums any duplicated values in the DataFrame, in this case we have no duplicates so no further action is needed
bitstamp.duplicated().sum()<jupyter_output><empty_output><jupyter_text>Step 5: Repeat Steps 1–4 for the coinbase DataFrame.<jupyter_code># Repeat Steps 1–4 for the coinbase DataFrame
# YOUR CODE HERE

#drops all the NaNs from the bitstamp dataframe using the dropna function
coinbase = coinbase.dropna()

#This line of code replaces all the "$" with "" from the "Close" column of our DataFrame to allow us to convert the data type to float and be capable of analyzing it
coinbase["Close"] = coinbase["Close"].str.replace("$","")

#This line of code replaces changes the data type of the "Close" column from str to float
coinbase["Close"] = coinbase["Close"].astype("float")

#This line of code finds and sums any duplicated values in the DataFrame,in this case we have no duplicates so no further action is needed
coinbase.duplicated().sum()<jupyter_output>C:\Users\EdgarPocaterra-Susma\anaconda3\envs\dev\lib\site-packages\ipykernel_launcher.py:8: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will *not* be treated as literal strings when regex=True.<jupyter_text>Analyze the DataYour analysis consists of the following tasks: 1. Choose the columns of data on which to focus your analysis.2. Get the summary statistics and plot the data.3. Focus your analysis on specific dates.4. Calculate the arbitrage profits.  Step 1: Choose columns of data on which to focus your analysis.Select the data you want to analyze. Use `loc` or `iloc` to select the following columns of data for both the bitstamp and coinbase DataFrames:* Timestamp (index)* Close<jupyter_code># Use loc or iloc to select `Timestamp (the index)` and `Close` from bitstamp DataFrame

#creates a new dataframe called bitstamp_sliced with only the "Close" column using the .loc function
bitstamp_sliced = bitstamp.loc[:,["Close"]]

# Review the first five rows of the DataFrame
# YOUR CODE HERE

#prints the top 5 rows of the bitstamp_sliced dataframe using the head function
bitstamp_sliced.head()
# Use loc or iloc to select `Timestamp (the index)` and `Close` from bitstamp DataFrame

#creates a new dataframe called coinbase_sliced with only the "Close" column using the .loc function
coinbase_sliced = coinbase.loc[:,["Close"]]

# Review the first five rows of the DataFrame
# YOUR CODE HERE

#prints the top 5 rows of the coinbase_sliced dataframe using the head function
coinbase_sliced.head()<jupyter_output><empty_output><jupyter_text>Step 2: Get summary statistics and plot the data.Sort through the time series data associated with the bitstamp and coinbase DataFrames to identify potential arbitrage opportunities. To do so, complete the following steps:1. Generate the summary statistics for each DataFrame by using the `describe` function.2. For each DataFrame, create a line plot for the full period of time in the dataset. Be sure to tailor the figure size, title, and color to each visualization.3. In one plot, overlay the visualizations that you created in Step 2 for bitstamp and coinbase. Be sure to adjust the legend and title for this new visualization.4. Using the `loc` and `plot` functions, plot the price action of the assets on each exchange for different dates and times. Your goal is to evaluate how the spread between the two exchanges changed across the time period that the datasets define. Did the degree of spread change as time progressed?<jupyter_code># Generate the summary statistics for the bitstamp DataFrame
# YOUR CODE HERE

#returns summary statistics of bitstamp_sliced dataframe using describe function
bitstamp_sliced.describe()
# Generate the summary statistics for the coinbase DataFrame
# YOUR CODE HERE

#returns summary statistics of coinbase_sliced dataframe using describe function
coinbase_sliced.describe()
# Create a line plot for the bitstamp DataFrame for the full length of time in the dataset 
# Be sure that the figure size, title, and color are tailored to each visualization
# YOUR CODE HERE

#plots the bitstamp_sliced dataframe in line format and with a specific size, color and title
bitstamp_sliced.plot(kind="line" , figsize=(6, 4), title="Bitstamp Closing Prices", color="blue")
# Create a line plot for the coinbase DataFrame for the full length of time in the dataset 
# Be sure that the figure size, title, and color are tailored to each visualization
# YOUR CODE HERE

#plots the coinbase_sliced dataframe in line format and with a specific size, color and title
coinbase_sliced.plot(kind="line" , figsize=(6, 4), title="Coinbase Closing Prices", color="orange")
# Overlay the visualizations for the bitstamp and coinbase DataFrames in one plot
# The plot should visualize the prices over the full lenth of the dataset
# Be sure to include the parameters: legend, figure size, title, and color and label
# YOUR CODE HERE

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title
bitstamp_sliced["Close"].plot(legend=True, figsize=(15, 7), title="Bitstamp v. Coinbase", color="blue", label="Bitstamp")
coinbase_sliced["Close"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")

# Using the loc and plot functions, create an overlay plot that visualizes 
# the price action of both DataFrames for a one month period early in the dataset
# Be sure to include the parameters: legend, figure size, title, and color and label
# YOUR CODE HERE

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title (for a specific date range)
bitstamp_sliced["Close"].loc["2018-01-01":"2018-01-31"].plot(legend=True, figsize=(15, 7), title="Exchange Comparison (Earlier Time Period - Jan 2018) ", color="blue", label="Bitstamp")
coinbase_sliced["Close"].loc["2018-01-01":"2018-01-31"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")
# Using the loc and plot functions, create an overlay plot that visualizes 
# the price action of both DataFrames for a one month period later in the dataset
# Be sure to include the parameters: legend, figure size, title, and color and label 
# YOUR CODE HERE

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title (for a specific date range)
bitstamp_sliced["Close"].loc["2018-03-01":"2018-03-31"].plot(legend=True, figsize=(15, 7), title="Exchange Comparison (Later Time Period - March 2018) ", color="blue", label="Bitstamp")
coinbase_sliced["Close"].loc["2018-03-01":"2018-03-31"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")<jupyter_output><empty_output><jupyter_text>**Question** Based on the visualizations of the different time periods, has the degree of spread change as time progressed?**Answer** We see that in the earlier period (Jan 2018) there is more spreads to be made, especially later in the month ( around Jan 29 2018), when we visualize our later period (March 2018) we see that there are very few moments in which the price differs and the difference is not substantial.  Step 3: Focus Your Analysis on Specific DatesFocus your analysis on specific dates by completing the following steps:1. Select three dates to evaluate for arbitrage profitability. Choose one date that’s early in the dataset, one from the middle of the dataset, and one from the later part of the time period.2. For each of the three dates, generate the summary statistics and then create a box plot. This big-picture view is meant to help you gain a better understanding of the data before you perform your arbitrage calculations. As you compare the data, what conclusions can you draw?<jupyter_code># Create an overlay plot that visualizes the two dataframes over a period of one day early in the dataset. 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label` 
# YOUR CODE HERE

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title (for a specific date)
bitstamp_sliced["Close"].loc["2018-01-16"].plot(legend=True, figsize=(15, 7), title="January 16th 2018 Exchange Comparison", color="blue", label="Bitstamp")
coinbase_sliced["Close"].loc["2018-01-16"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")
# Using the early date that you have selected, calculate the arbitrage spread 
# by subtracting the bitstamp lower closing prices from the coinbase higher closing prices

#creates a new dataframe called arbitrage_spread_early by substracting the "Close" column of coinbase_sliced from the "Close" column of bitstamp_sliced for a specific date, in this case Jan 16 2018
arbitrage_spread_early = coinbase_sliced["Close"].loc["2018-01-16"] - bitstamp_sliced["Close"].loc["2018-01-16"]

# Generate summary statistics for the early DataFrame

#returns summary statistics of arbitrage_spread_early dataframe using describe function
arbitrage_spread_early.describe()
# Visualize the arbitrage spread from early in the dataset in a box plot

#creates a box plot of the arbitrage_spread_early dataframe
arbitrage_spread_early.plot(kind = "box", title="Arbitrage Spread - Early Date - Jan 16 2018")
# Create an overlay plot that visualizes the two dataframes over a period of one day from the middle of the dataset. 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label` 

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title (for a specific date)
bitstamp_sliced["Close"].loc["2018-02-24"].plot(legend=True, figsize=(15, 7), title="February 24th 2018 Exchange Comparison", color="blue", label="Bitstamp")
coinbase_sliced["Close"].loc["2018-02-24"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")
# Using the date in the middle that you have selected, calculate the arbitrage spread 
# by subtracting the bitstamp lower closing prices from the coinbase higher closing prices

#creates a new dataframe called arbitrage_spread_middle by substracting the "Close" column of coinbase_sliced from the "Close" column of bitstamp_sliced for a specific date, in this case Feb 24 2018
arbitrage_spread_middle = coinbase_sliced["Close"].loc["2018-02-24"]- bitstamp_sliced["Close"].loc["2018-02-24"]

# Generate summary statistics 

#returns summary statistics of arbitrage_spread_middle dataframe using describe function
arbitrage_spread_middle.describe()
# Visualize the arbitrage spread from the middle of the dataset in a box plot

#creates a box plot of the arbitrage_spread_middle dataframe
arbitrage_spread_middle.plot(kind = "box", title="Arbitrage Spread - Middle Date - Feb 24 2018")
# Create an overlay plot that visualizes the two dataframes over a period of one day from late in the dataset. 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label` 

#plots an overlayed plot of both the bitstamp_sliced and coinbase_sliced dataframes in line format and with a specific size, color, labels and title (for a specific date)
bitstamp_sliced["Close"].loc["2018-03-29"].plot(legend=True, figsize=(15, 7), title="March 29th 2018 Exchange Comparison", color="blue", label="Bitstamp")
coinbase_sliced["Close"].loc["2018-03-29"].plot(legend=True, figsize=(15, 7), color="orange", label="Coinbase")
# Using the date from the late that you have selected, calculate the arbitrage spread 
# by subtracting the bitstamp lower closing prices from the coinbase higher closing prices

#creates a new dataframe called arbitrage_spread_late by substracting the "Close" column of coinbase_sliced from the "Close" column of bitstamp_sliced for a specific date, in this case Mar 29 2018
arbitrage_spread_late = coinbase_sliced["Close"].loc["2018-03-29"] - bitstamp_sliced["Close"].loc["2018-03-29"]

# Generate summary statistics for the late DataFrame

#returns summary statistics of arbitrage_spread_middle dataframe using describe function
arbitrage_spread_late.describe()
# Visualize the arbitrage spread from late in the dataset in a box plot

#creates a box plot of the arbitrage_spread_late dataframe
arbitrage_spread_late.plot(kind = "box", title="Arbitrage Spread - Late Date - Mar 29 2018")<jupyter_output><empty_output><jupyter_text>Step 4: Calculate the Arbitrage ProfitsCalculate the potential profits for each date that you selected in the previous section. Your goal is to determine whether arbitrage opportunities still exist in the Bitcoin market. Complete the following steps:1. For each of the three dates, measure the arbitrage spread between the two exchanges by subtracting the lower-priced exchange from the higher-priced one. Then use a conditional statement to generate the summary statistics for each arbitrage_spread DataFrame, where the spread is greater than zero.2. For each of the three dates, calculate the spread returns. To do so, divide the instances that have a positive arbitrage spread (that is, a spread greater than zero) by the price of Bitcoin from the exchange you’re buying on (that is, the lower-priced exchange). Review the resulting DataFrame.3. For each of the three dates, narrow down your trading opportunities even further. To do so, determine the number of times your trades with positive returns exceed the 1% minimum threshold that you need to cover your costs.4. Generate the summary statistics of your spread returns that are greater than 1%. How do the average returns compare among the three dates?5. For each of the three dates, calculate the potential profit, in dollars, per trade. To do so, multiply the spread returns that were greater than 1% by the cost of what was purchased. Make sure to drop any missing values from the resulting DataFrame.6. Generate the summary statistics, and plot the results for each of the three DataFrames.7. Calculate the potential arbitrage profits that you can make on each day. To do so, sum the elements in the profit_per_trade DataFrame.8. Using the `cumsum` function, plot the cumulative sum of each of the three DataFrames. Can you identify any patterns or trends in the profits across the three time periods?(NOTE: The starter code displays only one date. You'll want to do this analysis for two additional dates).  1. For each of the three dates, measure the arbitrage spread between the two exchanges by subtracting the lower-priced exchange from the higher-priced one. Then use a conditional statement to generate the summary statistics for each arbitrage_spread DataFrame, where the spread is greater than zero.*NOTE*: For illustration, only one of the three dates is shown in the starter code below.<jupyter_code># For the date early in the dataset, measure the arbitrage spread between the two exchanges
# by subtracting the lower-priced exchange from the higher-priced one

#I have chosen not to create the arbitrage_spread_early again since I had already created in the past exercise (just to keep my code DRY)

# Use a conditional statement to generate the summary statistics for each arbitrage_spread DataFrame
print("Early Date")
print("")
#this line of code uses the loc function with a conditional to select only the values in which the spread is greater than 0 and then gives us summary statistics using describe function
arbitrage_spread_early.loc[arbitrage_spread_early > 0].describe()
#middle

#I have chosen not to create the arbitrage_spread_middle again since I had already created in the past exercise (just to keep my code DRY)
print("Middle Date")
print("")
#this line of code uses the loc function with a conditional to select only the values in which the spread is greater than 0 and then gives us summary statistics using describe function
arbitrage_spread_middle.loc[arbitrage_spread_middle > 0].describe()
#late

#I have chosen not to create the arbitrage_spread_late again since I had already created in the past exercise (just to keep my code DRY)
print("Late Date")
print("")
#this line of code uses the loc function with a conditional to select only the values in which the spread is greater than 0 and then gives us summary statistics using describe function
arbitrage_spread_late.loc[arbitrage_spread_late > 0].describe()<jupyter_output>Late Date<jupyter_text>2. For each of the three dates, calculate the spread returns. To do so, divide the instances that have a positive arbitrage spread (that is, a spread greater than zero) by the price of Bitcoin from the exchange you’re buying on (that is, the lower-priced exchange). Review the resulting DataFrame.<jupyter_code># For the date early in the dataset, calculate the spread returns by dividing the instances when the arbitrage spread is positive (> 0) 
# by the price of Bitcoin from the exchange you are buying on (the lower-priced exchange).


#these lines of code take the spread return for each of the datasets (early, middle and late) and divide them into the bitstamp_sliced dataset to turn them into percentage returns

#early
spread_return_early = arbitrage_spread_early.loc[arbitrage_spread_early > 0] / bitstamp_sliced["Close"].loc["2018-01-16"]
#middle
spread_return_middle = arbitrage_spread_middle.loc[arbitrage_spread_middle > 0] / bitstamp_sliced["Close"].loc["2018-02-24"]
#late
spread_return_late = arbitrage_spread_late.loc[arbitrage_spread_late > 0] / bitstamp_sliced["Close"].loc["2018-03-29"]

# Review the spread return DataFrame

#prints spread returns for each of the spread_return data sets, early, middle and late
print("Early")
display(spread_return_early.dropna())
print("")
print("Middle")
display(spread_return_middle.dropna())
print("")
print("Late")
display(spread_return_late.dropna())<jupyter_output>Early<jupyter_text>3. For each of the three dates, narrow down your trading opportunities even further. To do so, determine the number of times your trades with positive returns exceed the 1% minimum threshold that you need to cover your costs.<jupyter_code># For the date early in the dataset, determine the number of times your trades with positive returns 
# exceed the 1% minimum threshold (.01) that you need to cover your costs

# early
print("Early")
profitable_trades_early = spread_return_early.loc[spread_return_early >0.01]
print("Count over 1%")
#number of times trade with positive returns exceed 1% threshold
display(profitable_trades_early.count())
print("First Five Profitable Trades")
# Review the first five profitable trades
display(profitable_trades_early.head())
print("")

# Middle
print("Middle")
profitable_trades_middle = spread_return_middle.loc[spread_return_middle >0.01]
print("Count over 1%")
#number of times trade with positive returns exceed 1% threshold
display(profitable_trades_middle.count())
print("First Five Profitable Trades")
# Review the first five profitable trades
display(profitable_trades_middle.head())
print("")

# Late
print("Late")
profitable_trades_late = spread_return_late.loc[spread_return_late >0.01]
print("Count over 1%")
#number of times trade with positive returns exceed 1% threshold
display(profitable_trades_late.count())
print("First Five Profitable Trades")
# Review the first five profitable trades
display(profitable_trades_late.head())<jupyter_output>Early
Count over 1%<jupyter_text>4. Generate the summary statistics of your spread returns that are greater than 1%. How do the average returns compare among the three dates?<jupyter_code># For the date early in the dataset, generate the summary statistics for the profitable trades
# or you trades where the spread returns are are greater than 1%

#early
#prints summary statistics for profitable_trades_early
print("Early")
display(profitable_trades_early.describe())
print("")

#middle
#prints summary statistics for profitable_trades_middle
print("Middle")
display(profitable_trades_middle.describe())
print("")

#late
#prints summary statistics for profitable_trades_late
print("Late")
display(profitable_trades_late.describe())<jupyter_output>Early<jupyter_text>5. For each of the three dates, calculate the potential profit, in dollars, per trade. To do so, multiply the spread returns that were greater than 1% by the cost of what was purchased. Make sure to drop any missing values from the resulting DataFrame.<jupyter_code># For the date early in the dataset, calculate the potential profit per trade in dollars 

#Early
print("Early")
# Multiply the profitable trades by the cost of the Bitcoin that was purchased
profit_early = profitable_trades_early * bitstamp_sliced["Close"].loc["2018-01-16"]
# Drop any missing values from the profit DataFrame
profit_per_trade_early = profit_early.dropna()
# View the early profit DataFrame
print("Early Profitable Trades (>1%)")
display(profit_per_trade_early)

#Middle
print("Middle")
# Multiply the profitable trades by the cost of the Bitcoin that was purchased
profit_middle = profitable_trades_middle * bitstamp_sliced["Close"].loc["2018-02-24"]
# Drop any missing values from the profit DataFrame
profit_per_trade_middle = profit_middle.dropna()
# View the early profit DataFrame
print("Early Profitable Trades (>1%)")
display(profit_per_trade_middle)

#Late
print("Late")
# Multiply the profitable trades by the cost of the Bitcoin that was purchased
profit_late = profitable_trades_late * bitstamp_sliced["Close"].loc["2018-03-29"]
# Drop any missing values from the profit DataFrame
profit_per_trade_late = profit_late.dropna()
# View the early profit DataFrame
print("Early Profitable Trades (>1%)")
display(profit_per_trade_late)<jupyter_output>Early
Early Profitable Trades (>1%)<jupyter_text>6. Generate the summary statistics, and plot the results for each of the three DataFrames.<jupyter_code># Generate the summary statistics for the early profit per trade DataFrame

#Early
#prints summary statistics for profit_per_trade_early
print("Summary Statistics Early Profitable Trades (>1%)")
display(profit_per_trade_early.describe())
print("")

#Middle
#prints summary statistics for profit_per_trade_middle
print("Summary Statistics Middle Profitable Trades (>1%)")
display(profit_per_trade_middle.describe())
print("")

#Late
#prints summary statistics for profit_per_trade_late
print("Summary Statistics Late Profitable Trades(>1%)")
display(profit_per_trade_late.describe())
# Plot the results for the early profit per trade DataFrame
#early

#creates a line plot for profit_per_trade_early with the desired title
profit_per_trade_early.plot(title="Early Profit per Trade")
#middle

#creates a line plot for profit_per_trade_middle with the desired title
profit_per_trade_middle.plot(title="Middle Profit per Trade")
#Resetting the Index to allow me to plot as a Scatter Plot (this is because it requires 2-axis (x,y) and won't accept the index as an axis)
profit_per_trade_late = pd.DataFrame(profit_per_trade_late).reset_index()
#late

#In this case I had to use the scatterplot to plot profit_per_trade_late instead of the lineplot since there was only one profitable trade (line graphs require more than one data point) it also has the desired title
profit_per_trade_late.plot(kind = "scatter", title="Late Profit per Trade", x= "Timestamp", y="Close")<jupyter_output><empty_output><jupyter_text>7. Calculate the potential arbitrage profits that you can make on each day. To do so, sum the elements in the profit_per_trade DataFrame.<jupyter_code># Calculate the sum of the potential profits for the early profit per trade DataFrame

#displays the total sum of values in profit_per_trade_early
print("Early")
display(profit_per_trade_early.sum())

#displays the total sum of values in profit_per_trade_middle
print("")
print("Middle")
display(profit_per_trade_middle.sum())

#displays the total sum of values in profit_per_trade_late
print("")
print("Late")
display(profit_per_trade_late.sum())<jupyter_output>Early<jupyter_text>8. Using the `cumsum` function, plot the cumulative sum of each of the three DataFrames. Can you identify any patterns or trends in the profits across the three time periods?<jupyter_code># Use the cumsum function to calculate the cumulative profits over time for the early profit per trade DataFrame

#early
#uses the cumsum function to do cumulative profits for the profit_per_trade_early
cumulative_profit_early = profit_per_trade_early.cumsum()

#middle
#uses the cumsum function to do cumulative profits for the profit_per_trade_middle
cumulative_profit_middle = profit_per_trade_middle.cumsum()

#late
#uses the cumsum function to do cumulative profits for the profit_per_trade_late
cumulative_profit_late = profit_per_trade_late.cumsum()
# Plot the cumulative sum of profits for the early profit per trade DataFrame

#creates a line plot for cumulative_profit_early with the desired title
cumulative_profit_early.plot(title="Early Profit - Cumulative Sum")
# Plot the cumulative sum of profits for the middle profit per trade DataFrame

#creates a line plot for cumulative_profit_middle with the desired title
cumulative_profit_middle.plot(title="Middle Profit - Cumulative Sum")
#Resetting the Index to allow me to plot as a Scatter Plot (this is because it requires 2-axis (x,y) and won't accept the index as an axis)
cumulative_profit_late = pd.DataFrame(cumulative_profit_late).reset_index()
# Plot the cumulative sum of profits for the late profit per trade DataFrame

#In this case I had to use the scatterplot instead of the lineplot since there was only one profitable trade (line graphs require more than one data point), it also has the desired title
cumulative_profit_late.plot(kind = "scatter", title="Late Profit - Cumulative Sum", x= "Timestamp", y="Close")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06900269541778976, 'fraction_numerical': 0.013889329316632313, 'mean_word_length': 5.731270010672358, 'pattern_counts': {'":': 4, '<': 73, '<?xml version=': 0, '>': 90, 'https://': 0, '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': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '650929', 'license': 'MIT', 'n_tokens_mistral': 9165, 'n_tokens_neox': 8403, 'n_words': 4039, 'path': 'crypto_arbitrage.ipynb', 'repo_name': 'epocaterrasus/CU-Assignment2-Crypto-Arbitrage', 'size': '31535'}