<jupyter_start><jupyter_text>Bitcoin Month, Week, DayIn this activity, you’ll use the `loc` function to find time periods in the two Bitcoin DataFrames that differ in the closing price. Instructions:1. Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a period of one month.2. Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a period of a week in the month that you selected.3. Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a single day of the week that you selected.4. Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a couple of hours during the day that you selected.  Import the required libraries and dependencies.<jupyter_code># Import the required libraries and dependencies including
# Pandas, pathlib and %matplotlib inline
import pandas as pd
from pathlib import Path
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Use the `Path` module and `read_csv` functions to import the CSV files and create the bitcoin_1 and bitcoin_2 DataFrames.<jupyter_code># Read in the CSV file called "bitcoin_1.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
bitcoin_1 = pd.read_csv(
    Path('./Resources/bitcoin_1.csv'), 
    index_col="Timestamp", 
    parse_dates=True, 
    infer_datetime_format=True
)

# Review the first 5 rows of the 'bitcoin_1' DataFrame
bitcoin_1.head()
# Read in the CSV file called "bitcoin_2.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
bitcoin_2 = pd.read_csv(
    Path('./Resources/bitcoin_2.csv'), 
    index_col="Timestamp", 
    parse_dates=True, 
    infer_datetime_format=True
)

# Review the first 5 rows of the 'bitcoin_2' DataFrame
bitcoin_2.head()<jupyter_output><empty_output><jupyter_text>Use the `describe` function to generate summary statistics for the bitcoin_1 and bitcoin_2 DataFrames.<jupyter_code># Use the describe function to generate summary statistics for the `bitcoin_1` DataFrame
bitcoin_1.describe()
# Use the describe function to generate the summary statistics for the `bitcoin_2` DataFrame
bitcoin_2.describe()<jupyter_output><empty_output><jupyter_text>Create the overlay plot that visualizes the two Bitcoin DataFrames for 2015.<jupyter_code># Overlay the plot of the Bitcoin 'Close' data
bitcoin_1['Close'].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1")
bitcoin_2['Close'].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2")<jupyter_output><empty_output><jupyter_text>Step 1: Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a period of one month.<jupyter_code># Using the loc function, create an overlay plot that visualizes the two dataframes 
# over a period of one month
# Be sure that the plot includes the parameters `legend`, `figsize`, `title`, `color` and `label` 
bitcoin_1['Close'].loc["2015-01-01":"2015-02-01"].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1")
bitcoin_2['Close'].loc["2015-01-01":"2015-02-01"].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2")<jupyter_output>/Users/johnpweldon/opt/anaconda3/envs/dev/lib/python3.7/site-packages/ipykernel_launcher.py:5: FutureWarning: Value based partial slicing on non-monotonic DatetimeIndexes with non-existing keys is deprecated and will raise a KeyError in a future Version.
  """<jupyter_text>Step 2: Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a period of a week in the month that you selected.<jupyter_code># Using the loc function, create an overlay plot that visualizes the two dataframes
# over a period of one week.
# The week should be included inside of the month that you previously selected 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label`
bitcoin_1['Close'].loc["2015-01-08":"2015-01-15"].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1")
bitcoin_2['Close'].loc["2015-01-08":"2015-01-15"].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2")<jupyter_output>/Users/johnpweldon/opt/anaconda3/envs/dev/lib/python3.7/site-packages/ipykernel_launcher.py:5: FutureWarning: Value based partial slicing on non-monotonic DatetimeIndexes with non-existing keys is deprecated and will raise a KeyError in a future Version.
  """<jupyter_text>Step 3: Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a single day of the week that you selected.<jupyter_code># Using the loc function, create an overlay plot that visualizes the two dataframes 
# over a period of one day.
# The day should be included inside of the week that was previsouly selected. 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label` 
bitcoin_1['Close'].loc["2015-01-14"].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1")
bitcoin_2['Close'].loc["2015-01-14"].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2")<jupyter_output><empty_output><jupyter_text>Step 4: Using the Pandas `loc` function, create an overlay plot that illustrates the price differences between the two DataFrames over a couple of hours during the day that you selected.<jupyter_code># Using the loc function, create an overlay plot that visualizes the two dataframes
# over a period of a couple of hours.
# The hours should be included inside of the day that was previously selected. 
# Be sure that the plots include the parameters `legend`, `figsize`, `title`, `color` and `label`
bitcoin_1['Close'].loc["2015-01-14 03:30:00" : "2015-01-14 05:30:00"].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1").set_ylim([100, 220])
bitcoin_2['Close'].loc["2015-01-14 03:30:00" : "2015-01-14 05:30:00"].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2").set_ylim([100, 220])<jupyter_output>/Users/johnpweldon/opt/anaconda3/envs/dev/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Value based partial slicing on non-monotonic DatetimeIndexes with non-existing keys is deprecated and will raise a KeyError in a future Version.<jupyter_text>Additional Module Exercises<jupyter_code># Code to plot the price movement for both bitcoin_1 and bitcoin_2 for October 19, 2015
bitcoin_1['Close'].loc['2015-10-19'].plot(
    legend=True, figsize=(15, 10), title="October 19, 2015", color="blue", label="BTC 1")
bitcoin_2['Close'].loc['2015-10-19'].plot(
    legend=True, figsize=(15, 10), color="orange", label="BTC 2")

# Review the summary statistics for the spread between the two assets
arbitrage_spread = bitcoin_2['Close'].loc['2015-10-19'] - bitcoin_1['Close'].loc['2015-10-19']
arbitrage_spread.describe()

# Using the day that you plotted in the “Month, Week, Day” activity, calculate and review the arbitrage spread. 
# Code to plot the price movement for both bitcoin_1 and bitcoin_2 for October 19, 2015
bitcoin_1['Close'].loc["2015-01-14"].plot(legend=True, figsize=(15, 10), title="Bitcoin_1 v. Bitcoin_2", color="blue", label="BTC 1")
bitcoin_2['Close'].loc["2015-01-14"].plot(legend=True, figsize=(15, 10), color="orange", label="BTC 2")

# Review the summary statistics for the spread between the two assets
arbitrage_spread = bitcoin_1['Close'].loc['2015-01-14'] - bitcoin_2['Close'].loc['2015-01-14']
arbitrage_spread.describe()

# Use the arbitrage_spread to determine the return percentage of the trades with a positive spread
# Include only the trades that have an arbitrage_spread that’s greater than 0

spread_return = arbitrage_spread[arbitrage_spread>0] / bitcoin_2['Close'].loc['2015-01-14']

# Create a profitable_trades DataFrame
# Show only those trades where the spread_return is greater than 1% (.01)
profitable_trades = spread_return[spread_return > .01]
profitable_trades.head(10)

# Print the summary statistics for the profitable_trades DataFrame
profitable_trades.describe()

# # Calculate Profit in Dollars
profit = profitable_trades * bitcoin_2['Close'].loc['2015-01-14']
profit

# “NaN” displays for time periods when the spread return is less than 1%
# Remove the NaN values to get a DataFrame that contains only profits per trade
profit_per_trade = profit.dropna()

# Generate Summary Statistics
profit_per_trade.describe()

# Calculate the Profit
profit_sum = profit_per_trade.sum()
profit_sum

# Plot the Profit
profit_per_trade.plot(figsize=(15, 10), title="Bitcoin Profits (January 14, 2015)", color='blue', ylabel='USD ($)')

# View the Cumulative Profit per Trade Data over the Day
cumulative_profit = profit_per_trade.cumsum()
cumulative_profit.plot(figsize=(15, 10), title="Cumulative Bitcoin Profits (January 14, 2015)", color='blue', ylabel='USD ($)')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10748702742772424, 'fraction_numerical': 0.045112781954887216, 'mean_word_length': 5.933920704845815, 'pattern_counts': {'":': 4, '<': 34, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '217144', 'license': 'MIT', 'n_tokens_mistral': 3196, 'n_tokens_neox': 2800, 'n_words': 1033, 'path': '03_Bitcoin_Month_Week_Day/Bitcoin_Month_Week_Day.ipynb', 'repo_name': 'jpweldon/Module_3_Practice', 'size': '9443'}