Giter Site home page Giter Site logo

caljadav / yahoo-fx-scraper Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 23 KB

This is a simple script that will scrape recent daily exchange rate data from Yahoo Finance.

License: GNU General Public License v3.0

Python 100.00%
exchange-rates finace fx python scraping yahoo-finance

yahoo-fx-scraper's Introduction

Yahoo-FX-Scraper

This is a simple script that will scrape recent daily FX data from Yahoo Finance.

Usage

Command Line Execution

You can run the scrape_yahoo_fx.py script directly from the command line. Here's how to do it:

python scrape_yahoo_fx.py --fx_type=closing --from=2024-1-1 --to=2024-3-1 --interval=1d --frequency=1d --currencies USD GBP AUD --o=example_rates.csv
  • --fx_type: The type of FX data to scrape. This can be closing, opening, high, or low.
  • --from: The start date for the data to scrape. Suggest the format YYYY-MM-DD, others will work.
  • --to: The end date for the data to scrape. If not provided, the current date will be used.
  • --interval: The interval for fetching data, e.g. 1d, 1wk, 1mo. If not provided, 1d will be used.
  • --frequency: The frequency for fetching data, e.g. 1d, 1wk, 1mo. If not provided, 1d will be used.
  • --currencies: The currencies to scrape data for. This should be a space-separated list of currency codes.
  • --o: The name of the output file where the scraped data will be saved. This should be a .csv file. If not provided, the data will be printed to the console.

Using the scrape_yahoo_fx Function

The scrape_yahoo_fx function allows you to scrape foreign exchange (FX) data from Yahoo Finance directly within your Python code. Here's an example of how to use it:

from scrape_yahoo_fx import scrape_yahoo_fx
from datetime import datetime

# Define the currencies to scrape data for
currencies = ["USD", "GBP", "AUD"]

# Call the function
df = scrape_yahoo_fx(
    fx_type="closing", 
    currencies=currencies,
    from_date=datetime(2024,1,1),
    to_date=datetime(2024,3,1),
    interval='1d',
    frequency='1d'
)

# The function returns a pandas DataFrame
print(df.head())

The scraper will produce an output CSV/DataFrame with the following format, where each column is in the format "BASE TARGET".

Date USD GBP GBP USD USD USD USD AUD AUD USD GBP AUD AUD GBP GBP GBP AUD AUD
2024-01-01 0.79 1.27 1.00 1.47 0.68 1.87 0.54 1.00 1.00
2024-01-02 0.79 1.27 1.00 1.47 0.68 1.87 0.54 1.00 1.00
2024-01-03 0.79 1.26 1.00 1.48 0.68 1.87 0.54 1.00 1.00
2024-01-04 0.79 1.27 1.00 1.48 0.67 1.88 0.53 1.00 1.00
2024-01-05 0.79 1.27 1.00 1.49 0.67 1.89 0.53 1.00 1.00
... ... ... ... ... ... ... ... ... ...

Hopefully someone finds this little script useful, enjoy!

yahoo-fx-scraper's People

Contributors

caljadav avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.