0

I am trying to replicate the following graph: enter image description here And I downloaded the data, however I do not know how to get this timeframe for 1 hour (13:30 to 14:30). I also do not know how to create a midpoints from this data.

This is the code that I have wrote so far:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import yfinance as yf

#specify the data
PeriodStart = "2023-01-03"
PeriodEnd  = "2023-01-07"
tickerlist = ["ES=F", "SPY"]

#download the data
df = yf.download(tickerlist, start = PeriodStart, end = PeriodEnd)['Adj Close']
df.head()


#a quick chart to see adjusted closing price through the period of selection
fig = plt.figure(figsize=(20, 6))
ax = fig.add_subplot(111)
line1 = ax.plot(df['ES=F'], label = "ES=F", color = "green")
ax2 = ax.twinx()
line2 = ax2.plot(df['SPY'], label = "SPY", color = "blue")

lines = line1 + line2
labels = [1.get_label() for 1 in lines]
ax.legend()

#set the title and label axis
plt.title('(a) Hour')
ax.grid()
ax.set_xlabel('Time (CT)')
ax.set_ylabel('Index Points (ES=F)')
ax2.set_ylabel('Index Points (SPY)')

plt.show()

And this is the graph that I have: enter image description here

As you can see I still need to change the midpoints, I cannot get the second ticker in the legend as well.

Thanks for help

Patrycja
  • 1
  • 1

0 Answers0