Created
February 5, 2023 03:08
-
-
Save git-shogg/75f9c9e5ba3d19e6bd9335bbf73b498a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- Function for running quick statistics on the dataframe --- | |
def dataframe_statistics(df, manager_name:str, cik:str): | |
''' | |
Build out the holdings dataframes with some basic statistics. | |
''' | |
df['Portfolio percentage'] = (df['Holding value'] / df['Holding value'].sum()) * 100 | |
df['Manager Name'] = manager_name | |
df['CIK'] = cik | |
return df | |
# --- Initialize empty dataframes --- | |
all_this_qtr_holdings = pd.DataFrame() | |
all_last_qtr_holdings = pd.DataFrame() | |
# --- Iterate through the list of investment managers, collect this quarters holdings and last --- | |
managers = json.load(open("fund_managers.json")) # Get the list of fund managers under review. | |
for manager in managers: | |
cik, manager_name = manager['cik'], manager['name'] # Get the cik and manager name. | |
fs = finsec.Filing(cik) # Initialize the finsec object. | |
this_qtr_cover_page, detailed_this_qtr_holdings, this_qtr_holdings = fs.get_a_13f_filing("Q3-2022") # Get the latest filing. | |
last_qtr_cover_page, detailed_last_qtr_holdings, last_qtr_holdings = fs.get_a_13f_filing("Q2-2022") # Get the last (available) quarterly filing. | |
this_qtr_holdings = dataframe_statistics(this_qtr_holdings, manager_name, cik) | |
last_qtr_holdings = dataframe_statistics(last_qtr_holdings, manager_name, cik) | |
all_this_qtr_holdings = pd.concat([all_this_qtr_holdings, this_qtr_holdings], ignore_index=True, sort=False) | |
all_last_qtr_holdings = pd.concat([all_last_qtr_holdings, last_qtr_holdings], ignore_index=True, sort=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment