Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsing historical book equity #29

Open
tbeason opened this issue Feb 24, 2021 · 0 comments
Open

parsing historical book equity #29

tbeason opened this issue Feb 24, 2021 · 0 comments

Comments

@tbeason
Copy link
Owner

tbeason commented Feb 24, 2021

simple function to use

using DelimitedFiles, DataFrames

function parse_moodys(fn; nomissing::Bool=true)
    inputarr = readdlm(fn)
    N,K = size(inputarr)
    permnos = Int.(inputarr[:,1])
    firstyear = Int.(inputarr[:,2])
    lastyear = Int.(inputarr[:,3])
    y1 = minimum(firstyear)
    y2 = y1 + K - 4
    yrs = y1:y2
    dfvec = Vector{DataFrame}(undef,N)

    for i in 1:N
        p = convert(Int,inputarr[i,1])
        vals = vec(inputarr[i,4:end])
        if nomissing
            vals = replace(vals, -99.99 => missing, -99.999 => missing)
        end
        dfvec_i = DataFrame(PERMNO=p,YEAR=yrs,MOODYSBE=vals)
        nomissing && dropmissing!(dfvec_i)

        dfvec[i] = dfvec_i
    end
    return vcat(dfvec...)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant