Documentation | Build Status | Code Coverage |
---|---|---|
FinanceRoutines.jl
is a package that contains useful functions to download and process academic financial data.
So far the package provides function to import:
- CRSP and Compustat from the WRDS Postgres server
- Fama-French three factors series from Ken French's website
- GSW Yield curves from the NY Fed
- Estimation of betas for stocks
FinanceRoutines.jl
is a registered package.
You can install from the my julia registry loulouJL
via the julia package manager:
> using Pkg, LocalRegistry
> pkg"registry add https://github.com/LouLouLibs/loulouJL.git"
> Pkg.add("FinanceRoutines")
If you don't want to add a new registry, you can install it directly from github:
> import Pkg; Pkg.add("https://github.com/louloulibs/FinanceRoutines.jl#main")
First import the monthly stock file and the compustat funda file
using FinanceRoutines
using DataFrames
# Set up a wrds connection (requires your WRDS credentials)
wrds_conn = FinanceRoutines.open_wrds_pg()
Then we can import the monthly stock file.
The new version of FinanceRoutines.jl
supports pulling from the new CIZ
file format.
df_msf_v2 = import_MSF_v2(wrds_conn) # CHECK YOUR TWO STEP AUTHENTICATOR
# 3826457×11 DataFrame
# Row │ permno mthcaldt mthret mthretx shrout mthprc mthcap mthprevcap siccd naics datem
# │ Int64 Date Decimal? Decimal? Int64? Decimal? Decimal? Decimal? Int64 String? MonthlyD…
# ─────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# 1 │ 10000 1986-01-31 0.707317 0.707317 3680 4.375 16100 9430 3990 missing 1986-01
# 2 │ 10000 1986-02-28 -0.257143 -0.257143 3680 3.25 11960 16100 3990 missing 1986-02
# 3 │ 10000 1986-03-31 0.365385 0.365385 3680 4.4375 16330 11960 3990 missing 1986-03
# 4 │ 10000 1986-04-30 -0.098592 -0.098592 3793 4 15172 16330 3990 missing 1986-04
On the other side, the package also allows pulling from the compustat funda file:
df_funda = import_Funda(wrds_conn);
build_Funda!(df_funda)
Last there is a function to get the link table and merge crsp with compustat:
# Merge both files
df_linktable = FinanceRoutines.import_ccm_link(wrds_conn)
# merge gvkey on monthly stock file
df_msf = link_MSF(df_linktable,
select(df_msf_v2, :permno, :mthcaldt=>:date, :datem, :mthret=>:ret, :mthcap))
df_msf = innerjoin(df_msf, df_funda, on = [:gvkey, :datey], matchmissing=:notequal)
This downloads directly data from Ken French's website and formats the data
df_FF3 = import_FF3()
# there is an option to download the daily factors
df_FF3_daily = import_FF3(:daily)
The function downloads yield curves from the NY Fed GSW and estimate returns based on the curves
df_GSW = import_gsw_parameters(date_range=(Date("1960-01-01"), Dates.today()) )
FinanceRoutines.add_yields!(df_GSW, [1, 10]) # maturities is in years
# or compute the yields yourself using functions
transform!(df_GSW,
AsTable(:) => ByRow(row ->
begin
gsw_params = GSWParameters(row)
ismissing(gsw_params) ? missing : gsw_yield(5, gsw_params)
end) => :yield_5y,
)
See the doc and tests for more options.
Look in the documentation for a guide on how to estimate betas: over the whole sample and using rolling regressions.
The package exports the function calculate_rolling_betas
.
olsgmm
from cochrane GMM code
The package the closest to this one is
- WrdsMerger.jl; WrdsMerger is probably in a more stable state than this package.
- WRDS.jl; WRDS specific wrappers to interact with the Postgres database.
Other packages or sources of code I have used to process the WRDS data
- WRDS demo on momentum (python)
- Tidy Finance Book and repo (R)
- French data package (R)
- Ian Gow's Empirical Research in Accounting Book (R)
- Replication Open Source AP (stata)