Financial Trading in Python
Chelsea Yang
Data Science Instructor
Financial trading is the buying and selling of financial assets
Various financial instruments to trade:
To make a profit by taking calculated risks
Market participants:
Time series data: a sequence of data points indexed in time order
import pandas as pd
# Load the data
bitcoin_data = pd.read_csv("bitcoin_data.csv", index_col='Date', parse_dates=True)
print(bitcoin_data.head())
Open High Low Close Volume
Date
2019-01-01 3746.71 3850.91 3707.23 3843.52 4324200990
2019-01-02 3849.22 3947.98 3817.41 3943.41 5244856835
2019-01-03 3931.05 3935.69 3826.22 3836.74 4530215218
2019-01-04 3832.04 3865.93 3783.85 3857.72 4847965467
2019-01-05 3851.97 3904.90 3836.90 3845.19 5137609823
import matplotlib.pyplot as plt
plt.plot(bitcoin_data['Close'], color='red')
plt.title("Daily close price")
plt.show()
Each candlestick displays high, low, open, and close
The color indicates bullish (rising prices) or bearish (falling prices) movement
import plotly.graph_objects as go
# Define the candlestick candlestick = go.Candlestick( x = bitcoin_data.index, open = bitcoin_data['Open'], high = bitcoin_data['High'], low = bitcoin_data['Low'], close = bitcoin_data['Close'])
# Create a plot fig = go.Figure(data=[candlestick])
# Show the plot fig.show()
Financial Trading in Python