THE REINSURANCE ACTUARY
  • Blog
  • Project Euler
  • Category Theory
  • Disclaimer

Python script - scrape CME FedWatch predictions

8/4/2022

 

I wrote a python script which uses Selenium to scrape the predictions for Fed rate movements from the CME FedWatch tool.

www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html#resources

The tool works by converting the price of a 30 day Fed Fund future into an implied probability of a given range of yields.

The CME website embeds the output in a something called an 'iframe', which I had never heard of before, and the iframe then contains a dashboard powered by something called Quikstrike. It took me a while to figure out how to switch focus to the iframe, as you can't simply reference elements inside the iframe without first switching focus.

The script below may not look too complicated, but believe me, it took a while to write.

Picture
Old Federal Reserve building Philadelphia, Source: https://commons.wikimedia.org/wiki/User:Beyond_My_Ken
In [ ]:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import pandas as pd
In [ ]:
driver = webdriver.Chrome(executable_path='C:/temp/chromedriver.exe')
driver.set_page_load_timeout(10)

driver.get("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")

time.sleep(2)

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))

driver.find_element_by_link_text('Probabilities').click()

time.sleep(2)

xpath = "//*[@id='MainContent_pnlContainer']/div[3]/div/div/table[3]/tbody"
table = driver.find_element_by_xpath(xpath)
tabletext = table.text

rows = table.find_elements(By.TAG_NAME, "tr") # get all of the rows in the table
i = 0
MeetingDates = []
DaysToMeeting = []
Easeprob = []
NoChangeprob = []
Hikeprob = []
for row in rows:
    if i > 1:
    # Get the columns (all the column 2)        
        col = row.find_elements(By.TAG_NAME, "td")
        MeetingDates.append(col[0].text)
        DaysToMeeting.append(col[1].text)
        Easeprob.append(col[2].text)
        NoChangeprob.append(col[3].text)
        Hikeprob.append(col[4].text)
    i = i +1


CMEdf = pd.DataFrame(
    {'MeetingDate': MeetingDates,
     'DaysToMeeting': DaysToMeeting,
     'Easeprob': Easeprob,
     'NoChangeprob': NoChangeprob,
     'Hikeprob': Hikeprob,
    })

CMEdf.to_csv(path + "\CMEFedWatch.csv")
driver.close()
BarnabeBearBull
30/1/2023 07:09:22 pm

Thank you for this snippet. I was having a hard time understanding how to do it. You have my full gratitude

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    ​​I work as an actuary and underwriter at a global reinsurer in London.

    I mainly write about Maths, Finance, and Technology.
    ​
    If you would like to get in touch, then feel free to send me an email at:

    ​LewisWalshActuary@gmail.com

      Sign up to get updates when new posts are added​

    Subscribe

    RSS Feed

    Categories

    All
    Actuarial Careers/Exams
    Actuarial Modelling
    Bitcoin/Blockchain
    Book Reviews
    Economics
    Finance
    Forecasting
    Insurance
    Law
    Machine Learning
    Maths
    Misc
    Physics/Chemistry
    Poker
    Puzzles/Problems
    Statistics
    VBA

    Archives

    March 2023
    February 2023
    October 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    October 2021
    September 2021
    August 2021
    July 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    May 2020
    March 2020
    February 2020
    January 2020
    December 2019
    November 2019
    October 2019
    September 2019
    April 2019
    March 2019
    August 2018
    July 2018
    June 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    April 2016
    January 2016

  • Blog
  • Project Euler
  • Category Theory
  • Disclaimer