This project provides an in-depth analysis of events listed on the Forex Factory calendar, serving as a comprehensive resource for traders. We employed Python for data extraction, successfully navigating through Cloudflare to scrape essential data. The collected information encompasses a variety of global events, offering a rich dataset for analysis and interpretation. Utilizing advanced technologies and methods, including pandas and Selenium, we ensured the accuracy and completeness of the extracted data.
The centerpiece of this initiative is an interactive Tableau dashboard that visualizes the data, offering insights from multiple angles. Traders can explore the number of events per currency, assess the impact types of events, and observe their distribution over time. The use of Tableau, complemented by design elements from Figma, allows for an intuitive and user-friendly interface. This visual tool is instrumental in enabling traders to anticipate upcoming events and formulate informed trading decisions.
The combination of programming, data analytics, and financial knowledge underscores the project’s contribution to the trading industry. Technologies like Python were pivotal for data collection and manipulation, while Tableau facilitated an engaging visualization of complex financial data. The accessibility of the complete dataset and Python code via GitHub ensures transparency and offers opportunities for further exploration and analysis. In essence, this project highlights the critical role of data visualization in simplifying complex financial datasets, paving the way for enhanced and effective trading strategies.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
import time
import pandas as pd
from datetime import datetime, timedelta
# Calculate the end date, which is 5 days from now
end_date = datetime.now() + timedelta(days=5)
# Initialize an empty DataFrame to store the scraped data
df = pd.DataFrame()
# Loop from the start date to the end date
current_date = datetime(2023, 1, 1) # start date
while current_date <= end_date:
# Format the date in the required format
date_string = current_date.strftime("%b%d.%Y").lower()
# Create the URL
url = f"https://www.forexfactory.com/calendar?day={date_string}"
driver = None
try:
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.get(url)
time.sleep(10) # sleep for 10 seconds
page_source = driver.page_source
html_data = page_source # replace with the actual column name
soup = BeautifulSoup(html_data, 'html.parser')
# Continue with your scraping code...
# ...
# Find all <td> elements with the specified class
td_dates = soup.find_all('td', class_='calendar__cell calendar__date date')
# Find all <td> elements with the specified class
td_times = soup.find_all('td', class_='calendar__cell calendar__time time')
# Extract the time from the <td> elements
times = [td_element.get_text(strip=True) for td_element in td_times]
# Repeat the date value to match the length of other lists
dates = [td_dates[0].span.get_text(strip=True)] * len(times)
# Extract the values from all occurrences
for td_element in td_dates[1:]:
span_element = td_element.find('span', class_='date')
if span_element is not None:
value = span_element.text.strip()
dates.append(value)
# Find all <td> elements with the specified class
td_currency = soup.find_all('td', class_='calendar__cell calendar__currency currency')
# Extract the currency values
currencies = [td.get_text(strip=True) for td in td_currency]
# Find all <td> elements with class starting with the specified string
td_impacts = soup.find_all('td', class_=lambda value: value and value.startswith('calendar__cell calendar__impact impact calendar__impact'))
# Extract the impact values from the <span> element
impacts = [td.span['title'] for td in td_impacts]
# Find all <td> elements with the specified class
td_events = soup.find_all('td', class_='calendar__cell calendar__event event')
# Extract the event titles from the <span> elements
event_titles = [td_event.span.text.strip() for td_event in td_events]
tr_details = soup.find_all('tr', class_='calendar__row calendar__expand')
details_ids = [tr_element.get('data-eventid') for tr_element in tr_details]
# Find all <td> elements with the specified class
td_actuals = soup.find_all('td', class_='calendar__cell calendar__actual actual')
# Extract the values from the <td> elements
actual = [td_actual.get_text(strip=True) for td_actual in td_actuals]
# Find all <td> elements with the specified class
td_forecasts = soup.find_all('td', class_='calendar__cell calendar__forecast forecast')
# Extract the forecast values from the <td> elements
forecasts = [td_forecast.find('span', class_='calendar-forecast').get_text(strip=True) for td_forecast in td_forecasts]
# Find all <td> elements with the specified class
td_previous_values = soup.find_all('td', class_='calendar__cell calendar__previous previous')
# Extract the previous values from the <td> elements
previous = [td_previous.find('span', class_='calendar-previous').get_text(strip=True) for td_previous in td_previous_values]
data = {
'Date': dates,
'Time': times,
'Currency': currencies,
'Impact': impacts,
'Event Title': event_titles,
'Details id': details_ids,
'Actual': actual,
'Forecast': forecasts,
'Previous': previous
}
df = pd.concat([df, pd.DataFrame(data)], ignore_index=True)
except Exception as e:
print(f"An error occurred: {e}")
finally:
if driver is not None:
driver.quit()
# Increment the current_date by one day
current_date += timedelta(days=1)
# Save the DataFrame to a CSV file
df.to_csv('Forex Factory Calendar.csv', index=False)
An error occurred: Message: session not created from no such execution context: loader has changed while resolving nodes (Session info: chrome=114.0.5735.199) Stacktrace: Backtrace: GetHandleVerifier [0x005FA813+48355] (No symbol) [0x0058C4B1] (No symbol) [0x00495358] (No symbol) [0x00497D86] (No symbol) [0x004999E1] (No symbol) [0x00499A80] (No symbol) [0x004E1F1B] (No symbol) [0x004E093C] (No symbol) [0x004DA536] (No symbol) [0x004B82DC] (No symbol) [0x004B93DD] GetHandleVerifier [0x0085AABD+2539405] GetHandleVerifier [0x0089A78F+2800735] GetHandleVerifier [0x0089456C+2775612] GetHandleVerifier [0x006851E0+616112] (No symbol) [0x00595F8C] (No symbol) [0x00592328] (No symbol) [0x0059240B] (No symbol) [0x00584FF7] BaseThreadInitThunk [0x76DB00C9+25] RtlGetAppContainerNamedObjectPath [0x77AB7B4E+286] RtlGetAppContainerNamedObjectPath [0x77AB7B1E+238] An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable
[WDM] - Downloading: 100%|█████████████████████████████████████████████████████████| 6.30M/6.30M [00:06<00:00, 987kB/s]
An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: Message: session not created from no such execution context: loader has changed while resolving nodes (Session info: chrome=114.0.5735.199) Stacktrace: Backtrace: GetHandleVerifier [0x00FAA813+48355] (No symbol) [0x00F3C4B1] (No symbol) [0x00E45358] (No symbol) [0x00E47D86] (No symbol) [0x00E499E1] (No symbol) [0x00E49A80] (No symbol) [0x00E91F1B] (No symbol) [0x00E9093C] (No symbol) [0x00E8A536] (No symbol) [0x00E682DC] (No symbol) [0x00E693DD] GetHandleVerifier [0x0120AABD+2539405] GetHandleVerifier [0x0124A78F+2800735] GetHandleVerifier [0x0124456C+2775612] GetHandleVerifier [0x010351E0+616112] (No symbol) [0x00F45F8C] (No symbol) [0x00F42328] (No symbol) [0x00F4240B] (No symbol) [0x00F34FF7] BaseThreadInitThunk [0x76DB00C9+25] RtlGetAppContainerNamedObjectPath [0x77AB7B4E+286] RtlGetAppContainerNamedObjectPath [0x77AB7B1E+238] An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable An error occurred: 'NoneType' object is not subscriptable