Beispiel #1
0
# Merge Hoberg and stocks_month data
stocks_month = stocks_month.merge(hoberg,
                                  on=['DATE', 'MAIN_KEY', 'DW_INSTRUMENT_ID'],
                                  how='left')

del hoberg

# Drop MAIN_KEY
stocks_month.drop('MAIN_KEY', axis=1, inplace=True)

# Convert to decimal
stocks_month['RETURN'] = 0.01 * stocks_month['RETURN']
stocks_month['TNIC_RET'] = 0.01 * stocks_month['TNIC_RET']

# Winsorize columns
stocks_month = cf.winsorize(stocks_month, 'RETURN')

FF, RF = cf.prep_FF_monthly(path)

for signal in [1, 3, 6, 12]:
    _, MOM = cf.get_mom_diff(stocks_month,
                             RF,
                             0,
                             signal,
                             monthly=True,
                             sig_rtn=True)

    MOM.to_csv(path + '\\Data\\signals\\ind_minus_fund_0_' + str(signal) +
               '_cut_' + str(cut) + '.csv',
               index=False)
Beispiel #2
0
file = path + '\\Data\\fundamental_mods\\monthly_fund_rtn_cluster_cut_' + str(cut) + '.csv'

# If file isn't none, in which folder should everything be place?
folder = 'fund_rtn_clusters'

# Get the month return data
stocks_month = cf.prep_monthly_rtn(path, cut, file, post_2009)

# Load Fama French three factors
FF, RF = cf.prep_FF_monthly(path)

# Compute industry returns
stocks_month['ind'] = stocks_month.groupby(['DATE', 'INDUSTRY'])['RETURN'].transform('mean')

# Winsorize
stocks_month = cf.winsorize(stocks_month, 'ind')

# Compute number of industries
stocks_month['n_ind'] = stocks_month.groupby(['DATE', 'INDUSTRY'])['DW_INSTRUMENT_ID'].transform('count')

# Construct difference of industry and fundemental returns
stocks_month['ind-fund'] = stocks_month['ind'] - stocks_month['TNIC_RET']


def calc_quant_rtn(n):
    
    stocks_month.sort_values(by = ['DW_INSTRUMENT_ID', 'DATE'], inplace = True)

    # Initialize output
    output = pd.DataFrame()
  
Beispiel #3
0
folder = None

# Get the month return data
stocks_month = cf.prep_monthly_rtn(path, cut, file1, post_2009)

# Get the weekly return data
stocks_week = cf.prep_weekly_rtn(path, cut, file2, post_2009)

print(0.25 * int((time.time() - start_time)/15), 'minutes so far...')

# Calculate faux SIC return; equal weighted within each faux SIC
stocks_week['ind'] = stocks_week.groupby(['DATE', 'INDUSTRY'])['RETURN'].transform('mean')
stocks_month['ind'] = stocks_month.groupby(['DATE', 'INDUSTRY'])['RETURN'].transform('mean')

# Winsorize functions
stocks_week = cf.winsorize(stocks_week, 'ind')
stocks_month = cf.winsorize(stocks_month, 'ind')

# Calculate firm return minus industry return 
stocks_week['r-ind'] = stocks_week['RETURN'] - stocks_week['ind']
stocks_month['r-ind'] = stocks_month['RETURN'] - stocks_month['ind']

# Calculate official minus fundemental
stocks_week['ind-fund'] = stocks_week['ind'] - stocks_week['TNIC_RET']
stocks_month['ind-fund'] = stocks_month['ind'] - stocks_month['TNIC_RET']

# Construct r - fund
stocks_week['r-fund'] = stocks_week['RETURN'] - stocks_week['TNIC_RET']
stocks_month['r-fund'] = stocks_month['RETURN'] - stocks_month['TNIC_RET']

# Create SIC counts
Beispiel #4
0
file = path + '\\Data\\fundamental_mods\\weekly_fund_rtn_inv_val_wt_cut_' + str(cut) + '.csv'

# If file isn't none, in which folder should everything be place?
folder = 'fund_inv_val_wt'

# Get the weekly return data
stocks_week = cf.prep_weekly_rtn(path, cut, file, post_2009)

# Load Fama French three factors
FF, RF = cf.prep_FF_weekly(path)

# Compute industry returns
stocks_week['ind'] = stocks_week.groupby(['DATE', 'INDUSTRY'])['RETURN'].transform('mean')

# Winsorize industry returns
stocks_week = cf.winsorize(stocks_week, 'ind')

# Compute number of industries
stocks_week['n_ind'] = stocks_week.groupby(['DATE', 'INDUSTRY'])['DW_INSTRUMENT_ID'].transform('count')

# Construct difference of industry and fundemental returns
stocks_week['ind-fund'] = stocks_week['ind'] - stocks_week['TNIC_RET']


def calc_quant_rtn(n):
    
    stocks_week.sort_values(by = ['DW_INSTRUMENT_ID', 'DATE'], inplace = True)

    # Initialize output
    output = pd.DataFrame()