This file contains hidden or 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
| # --- Map tickers into the quarterly holding dataframes --- | |
| all_this_qtr_holdings['Ticker'] = all_this_qtr_holdings['CUSIP'].map(dict(cusip_mappings)) | |
| all_last_qtr_holdings['Ticker'] = all_last_qtr_holdings['CUSIP'].map(dict(cusip_mappings)) | |
| all_this_qtr_holdings['Ticker'] = all_this_qtr_holdings['Ticker'].fillna('N/A') | |
| all_last_qtr_holdings['Ticker'] = all_last_qtr_holdings['Ticker'].fillna('N/A') |
This file contains hidden or 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
| # --- Functions to support pandas lambda function --- | |
| def calc_pct_bought_sold(this_share_count, last_share_count): | |
| if this_share_count > 0 and last_share_count == 0: | |
| return 100 | |
| elif this_share_count == 0 and last_share_count == 0: # In the rare circumstances that both this share count and last share count are zero return 0. | |
| return 0 | |
| else: | |
| return ((this_share_count/last_share_count)-1)*100 | |
| def calc_dollar_bought_sold(count_bought_sold, last_holding_val, last_share_count, this_holding_val, this_share_count): |
This file contains hidden or 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
| def sns_heatmap(dataframe, key_column, key_column_format, chart_title, c_pos_neg): | |
| # Build out heatmap things | |
| dataframe['Position'] = range(1,len(dataframe) + 1) | |
| dataframe['y'] = [(x//10 + 1 if x%10 != 0 else (x//10)) for x in dataframe['Position']] | |
| dataframe['x'] = [(x%10 if x%10 != 0 else 10) for x in dataframe['Position']] | |
| # most_bought['normalized_dollars_bought_sold'] = (most_bought['dollars_bought_sold'] - most_bought['dollars_bought_sold'].min()) / (most_bought['dollars_bought_sold'].max()-most_bought['dollars_bought_sold'].min()) | |
| # most_bought['natural_log'] = np.log(most_bought['normalized_dollars_bought_sold']) | |
| pivot_df = dataframe.pivot(index='y', columns='x', values=key_column) | |
| ticker_labels = np.asarray(dataframe['Ticker']).reshape((10,10)) |
OlderNewer