Fortran-Stock-Quotes
March 30, 2026 ยท View on GitHub
Download daily and intraday stock and ETF prices from Yahoo Finance using Python, and analyze the downloaded CSV files in Fortran.
The project uses:
- Python for data download via
yfinance - Fortran for orchestration, file handling, and summary statistics
The repository currently supports:
- daily prices
- 1-minute intraday prices
- 5-minute intraday prices
For each symbol, the Fortran code can summarize:
- number of observations
- first and last date or datetime
- first and last price
- return from first to last price
- minimum, maximum, and standard deviation of returns
Files
get_yahoo_prices.py- Python downloader for Yahoo Finance datayahoo_prices.f90- Fortran module with generic and wrapper proceduresxyahoo_intraday.f90- example main program for intraday downloads and summariesxyahoo_daily.f90- example main program for daily downloads and summariesMakefile- build and run targets usinggfortranetf_symbols.txt- sample ticker file
Design
The project uses one generic downloader and one generic summarizer, plus thin daily and intraday wrappers.
Main Fortran procedures:
get_yahoo_pricesget_yahoo_intradayget_yahoo_dailysummarize_yahoo_pricessummarize_yahoo_intradaysummarize_yahoo_daily
This avoids duplicating logic while keeping the common daily and intraday entry points simple.
Requirements
Python
- Python 3
yfinance
Install with:
pip install yfinance
Depending on your Python environment, you may also want:
pip install pandas
Fortran
- tested with
gfortranandifx
GNU Make
A GNU-compatible make is recommended for using the provided Makefile.
Yahoo Finance notes
Yahoo Finance limits how much intraday history is available.
Typical behavior is:
1mdata: only recent history is available5mdata: more history is available, but still limited relative to daily data1ddata: long history is usually available
The exact limits and availability are controlled by Yahoo Finance, not by this project.
Python downloader
The Python script accepts a ticker file and or a comma-separated list of tickers.
Example command:
python get_yahoo_prices.py --ticker-file etf_symbols.txt --interval 1d --base-dir stocks_daily_test
Example for intraday data:
python get_yahoo_prices.py --ticker-file etf_symbols.txt --interval 5m --ndays-prior 30 --base-dir stocks_test
Output directories
Downloaded CSV files are written under directories of the form:
- daily:
BASE_DIR/daily_prices/YYYYMMDD - 1-minute:
BASE_DIR/1_minute_prices/YYYYMMDD - 5-minute:
BASE_DIR/5_minute_prices/YYYYMMDD
Examples:
stocks_daily_test/daily_prices/20260330stocks_test/5_minute_prices/20260330
Building
Build both executables:
make
Build only intraday:
make intraday
Build only daily:
make daily
Run intraday example:
make run_intraday
Run daily example:
make run_daily
Clean generated files:
make clean
Executables
The Makefile builds:
yahoo_intraday.exeyahoo_daily.exe
Example usage from Fortran
Intraday
Example program: xyahoo_intraday.f90
Typical flow:
- call
get_yahoo_intraday - call
summarize_yahoo_intraday
Example:
program xyahoo_intraday
use yahoo_prices_mod, only: get_yahoo_intraday, summarize_yahoo_intraday
implicit none
logical, parameter :: run_download = .true.
logical, parameter :: run_summary = .true.
character(len=8), parameter :: tickers(2) = [character(len=8) :: "SPY", "XLF"]
print *, "testing yahoo_prices_mod intraday"
if (run_download) then
call get_yahoo_intraday( &
tickers=tickers, &
ticker_file="etf_symbols.txt", &
base_dir="stocks_test", &
interval="5m", &
ndays_prior=30)
end if
if (run_summary) then
call summarize_yahoo_intraday( &
tickers=tickers, &
ticker_file="etf_symbols.txt", &
base_dir="stocks_test", &
interval="5m")
end if
print *
print *, "done"
end program xyahoo_intraday
Daily
Example program: xyahoo_daily.f90
Typical flow:
- call
get_yahoo_daily - call
summarize_yahoo_daily
Example:
program xyahoo_daily
use yahoo_prices_mod, only: get_yahoo_daily, summarize_yahoo_daily
implicit none
logical, parameter :: run_download = .true.
logical, parameter :: run_summary = .true.
character(len=8), parameter :: tickers(2) = [character(len=8) :: "SPY", "XLF"]
print *, "testing yahoo_prices_mod daily"
if (run_download) then
call get_yahoo_daily( &
tickers=tickers, &
ticker_file="etf_symbols.txt", &
base_dir="stocks_daily_test", &
start_date="2020-01-01", &
end_date="2026-03-30")
end if
if (run_summary) then
call summarize_yahoo_daily( &
tickers=tickers, &
ticker_file="etf_symbols.txt", &
base_dir="stocks_daily_test")
end if
print *
print *, "done"
end program xyahoo_daily
Fortran API summary
get_yahoo_prices
Generic downloader for daily or intraday data.
Important arguments:
tickers- optional array of ticker symbolsticker_file- optional file containing one ticker per linebase_dir- optional output base directorypyexe- optional Python executable, default"python"pyscript- optional Python script name, default"get_yahoo_prices.py"interval-"1m","5m", or"1d"period- optional Yahoo period stringstart_date- optional start date stringend_date- optional end date stringndays_prior- optional integer mainly useful for intraday downloads
At least one of tickers and ticker_file must be present.
get_yahoo_intraday
Wrapper around get_yahoo_prices for 1m or 5m data.
Important arguments:
intervalmust be"1m"or"5m"ndays_prioris typically used for5m
get_yahoo_daily
Wrapper around get_yahoo_prices for daily data.
Important arguments:
periodstart_dateend_date
Date strings should be passed as:
YYYY-MM-DD
Example:
"2025-01-15"
summarize_yahoo_prices
Generic summarizer for downloaded CSV files.
Important arguments:
tickersticker_filebase_dirintervaldate_dirprice_column
If date_dir is not supplied, the current date in YYYYMMDD format is used.
summarize_yahoo_intraday
Wrapper around summarize_yahoo_prices for 1m or 5m data.
summarize_yahoo_daily
Wrapper around summarize_yahoo_prices for daily data.
By default, daily summaries use:
Adj Closeif present- otherwise
Close
Intraday summaries use:
Close
Summary statistics
For each symbol, the Fortran summarizer computes:
nobsdt_firstdt_lastpx_firstpx_lastret_flret_minret_maxret_sd
Definitions:
ret_fl = px_last / px_first - 1- consecutive return at time
tisprice_t / price_(t-1) - 1 ret_sdis the sample standard deviation of consecutive returns
For daily data, only the date is shown in the summary table.
For intraday data, the full timestamp is shown.
Example daily summary
summary from directory: stocks_daily_test/daily_prices/20260330
symbol nobs dt_first dt_last px_first px_last ret_fl ret_min ret_max ret_sd
SPY 1568 2020-01-02 2026-03-30 296.8882 635.9250 1.141968 -0.109424 0.105019 0.012920
EFA 1568 2020-01-02 2026-03-30 58.6371 94.3443 0.608953 -0.109902 0.084731 0.012193
TLT 1568 2020-01-02 2026-03-30 114.6227 86.7950 -0.242776 -0.066683 0.075196 0.010649
XLF 1568 2020-01-02 2026-03-30 27.7851 48.5500 0.747341 -0.137093 0.131566 0.015784
Example intraday summary
summary from directory: stocks_test/5_minute_prices/20260330
symbol nobs dt_first dt_last px_first px_last ret_fl ret_min ret_max ret_sd
SPY 1567 2026-03-02 09:30:00-05:00 2026-03-30 10:00:00-04:00 681.2000 636.0400 -0.066295 -0.017236 0.012737 0.001323
XLF 1567 2026-03-02 09:30:00-05:00 2026-03-30 10:00:00-04:00 50.7400 48.2700 -0.048680 -0.022829 0.014199 0.001656
Ticker file format
A ticker file should contain one symbol per line, for example:
SPY
EFA
TLT
XLF
Notes on symbol handling
The project accepts symbols from:
- a Fortran character array
- a text file
- or both
If both are supplied, the code uses the union of symbols.
Limitations
- The Fortran CSV parser is simple and intended for the CSV files written by
pandas.DataFrame.to_csv(). - This is not a general quoted-CSV parser.
- Yahoo Finance data availability and history limits are controlled by Yahoo.
- Intraday history is limited relative to daily history.
- The project depends on Python and
yfinancefor the actual data download.
Windows notes
On Windows, execute_command_line may be sensitive to quoting and shell behavior. The current code is written to work with a command such as:
python "get_yahoo_prices.py" --ticker-file "etf_symbols.txt" --interval 1d
The Makefile is intended for GNU make.