13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

321

# up days and red for down days

csticks = candlestick_ohlc(

ax, df[

[’date_fmt’, ’Open’, ’High’, ’Low’, ’Close’]

].values, width=0.6,

colorup=’#000000’, colordown=’#ff0000’

)

ax.set_axis_bgcolor((1,1,0.9))

ax.xaxis_date()

plt.setp(

plt.gca().get_xticklabels(),

rotation=45, horizontalalignment=’right’

)

plt.show()

def plot_3d_normalised_candles(data):

"""

Plot a 3D scatterchart of the open-normalised bars

highlighting the separate clusters by colour

"""

fig = plt.figure(figsize=(12, 9))

ax = Axes3D(fig, elev=21, azim=-136)

ax.scatter(

data["H/O"], data["L/O"], data["C/O"],

c=labels.astype(np.float)

)

ax.set_xlabel(’High/Open’)

ax.set_ylabel(’Low/Open’)

ax.set_zlabel(’Close/Open’)

plt.show()

def plot_cluster_ordered_candles(data):

"""

Plot a candlestick chart ordered by cluster membership

with the dotted blue line representing each cluster

boundary.

"""

# Set the format for the axis to account for dates

# correctly, particularly Monday as a major tick

mondays = WeekdayLocator(MONDAY)

alldays = DayLocator()

weekFormatter = DateFormatter("")

fig, ax = plt.subplots(figsize=(16,4))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!