import numpy as np
import pandas as pd
data = pd.read_excel('F:/Desktop/Downloads/Funds_Holding_12_11_2017.xls')
M_Cap = pd.read_excel('F:/Desktop/Share_4_Feb_2018.xlsx','CAP(R2)_New')
Shariah = pd.read_excel('F:/Shariah_List.xlsx')
Data = data[['Ticker','SecurityName','FundCode','FundName','TotalValueFund','LiquidityNative']]
Shariah_Data = Shariah[['Ticker','Compliance Status: DEC 2017']]
Filter_Fund = Data['FundCode'].isin ([14, 16, 17, 24, 25, 49])
Fund = Data[Filter_Fund]
total_assets = np.sum(Fund['TotalValueFund'])+np.sum(Fund['LiquidityNative'])
weights = Fund['TotalValueFund']/total_assets
# 10% Breach Calculation
Fund['10% Breach'] = weights > 0.1
Fund['Weightage'] = round(weights*100,2)
out_1 = Fund[['Ticker','SecurityName','FundCode','FundName','Weightage','10% Breach','TotalValueFund']]
Cap_Data = M_Cap[['Ticker','% of Total Free','S&P Saudi Arabia','Free Float Mrk.','Riyad Income BM']]
newdata = out_1.merge(Cap_Data, on = 'Ticker', how ='inner')
#Market Cap Calculation
if Fund == 14:
newdata['Mkt_Cap'] = newdata['Weightage'] < newdata['% of Total Free']
elif Fund == 16:
newdata['Mkt_Cap_S&P'] = newdata['Weightage'] < newdata['S&P Saudi Arabia']
CAP = Shariah_Data.merge(Cap_Data_16, on = 'Ticker', how = 'inner')
newdata = out_1.merge(Cap_Data, on = 'Ticker', how ='inner')
elif Fund == 17:
newdata['Mkt_Cap_RI'] = newdata['Weightage'] < newdata['Riyad Income BM']
elif Fund == 24:
newdata['Mkt_Cap_Emaar'] = newdata['Weightage'] < newdata['Al Emaar BM %']
elif Fund == 25:
newdata['Mkt_Cap_BI'] = newdata['Weightage'] < newdata['SBIF (S&P Sharia)']
elif Fund == 49:
newdata['Mkt_Cap_Mid'] = newdata['Weightage'] < newdata['S&P SA Shariah']
else:
print("No Data Available")
# 5% Holding Calculation
Holding = newdata['TotalValueFund'] / (newdata['Free Float Mrk.']*1000000)
newdata['Holding Weight'] = Holding*100
newdata['5% Holdings'] = Holding > 0.05
newdata['% of Total Free'] = newdata['% of Total Free']*100
Final_Result = newdata[['Ticker','SecurityName','FundCode','FundName','Weightage','% of Total Free','10% Breach','Mkt_Cap','Mkt_Cap_S&P','Mkt_Cap_RI','Mkt_Cap_Emaar','Mkt_Cap_BI','Mkt_Cap_Mid','5% Holdings','Compliance Status: DEC 2017']]
Final_Result.to_excel('F:/Monitoring.xlsx')
After running the above, I got the error:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Please advise how can I solve this issue.
14
,16
,17
,24
,25
,49
values come from? Are they a specific company'sFundCode
? – tehhowch