only hate road when you miss home
Ps 股票占比是第二列
Psf 股指期货占比是第三列
Rs 第四列 股票收益
Ri 第五列 指数收益,三个指数
Rsf 第六列 股指期货收益
if Ps>0, Psf<0
Pn= Ps+Psf
if Pn>=0
Ph = abs(Psf)
elseif Pn<0
Ph = abs(Ps)
Pn = Ps+Psf
end
elseif Ps>0, Psf>0
Pn = Ps+Psf
end
clear;clc
tic
load('C:\Users\lenovo\Desktop\test\alpha\data0829\datafunda0001.mat');
Ps = datafunda0001(:,2);
Psf = datafunda0001(:,3);
Rs = datafunda0001(:,4);
Ri = datafunda0001(:,5);
Rsf = datafunda0001(:,6);
for i01=1:168
PH(i01,1) = 0;
PN(i01,1) = 0;
if (Ps{i01}>0&&Psf{i01}<0)
fprintf('有对冲\n');
if abs(Ps{i01})>abs(Psf{i01})
PH(i01,1) = abs(Psf{i01});
PN(i01,1) = (abs(Ps{i01})-abs(Psf{i01}));
else
PH(i01,1) = abs(Ps{i01});
PN(i01,1) = (abs(Psf{i01})-abs(Ps{i01}));
end
elseif (Ps{i01}>0&&Psf{i01}>0)
fprintf('无对冲\n');
PH(i01,1) = 0;
end
end
选择wind A 为基准因为,包含了全部28个行业
拆分出超额收益,
择时是净暴露仓位,择时是判断 Pn
超额收益 Rs- Rb 择时体现在beta之中
alpha + beta 就是超额收益
A 是万德全A收益率 ,Po 是设定的仓位是基准仓位 取0.6
(情况1 只有多空时)超额利润
= Ps*rs - Po*A
= Ps*rs -Ps*A+ Ps*A- Po*A
= Ps(rs-A)+(Ps-Po)*a
rs = Wf*Rf - Wi*Ri
Rs代表行业收益
Wi*Ri 申万 每个行业权重,每个行业收益
Wf*rf - Wi*Ri
(Wf*rf -Wf*Ri)+( Wf*Ri- Wi*Ri)
Wf*(rf -Ri)+ (Wf - Wi)*Ri
Wf*(rf -Ri) 选股能力
(Wf - Wi)*Ri 配置能力
2.0 用沪深300为基准 ,则权重,但是可用申万的编制规则,将300 分到申万的28个桶之中,其中 Ri 可以重新计算
3.0 以对冲为主要
Ps*rs - Ph*ri = alpha - beta
= Ps*rs - Ph*ri (-Po*ri1)
= Ph(rs- ri)+Pn*rs(-Po*ri1)
= Ph(Wf*rf - Wi*Ri)+Pn*rs(-Po*ri1)
Ph(Wf*rf - Wi*Ri)
Pn*rs(-Po*ri1)
Pn*rs - Pn*ri1 + Pn*ri1 - Po*ri1
Pn(rs - ri1) + (Pn- Po)*ri1
Pn(rs - ri1)近似为Pn(rs - ri) 如果没有对冲,就看股票的范围。
(Pn- Po)*ri1 体现了择时能力 (Pn- Po)*Wi*Ri
其中 ri1就是上面的ri 为的是区别而写出来
如果没有对冲的话,不一定用wind A 或者
中证 800 就是中证300 加中证500
重点 (1)wind A (2)中证300 (3)支持指数复权
ProName=['("母基金二期")'];
conn=database('report','uxmc','uxmc-123', 'com.MySQL.jdbc.Driver','jdbc:mysql://report001.mysql.rds.aliyuncs.com/report');
ping(conn);
sql=sprintf('select productCode from product where productName in %s order by productCode',ProName);
cursorA=exec(conn,sql);
cursorA=fetch(cursorA);
FOFCode=cursorA.Data;
close(cursorA);
foc= FOFCode{1,1};
Index=['tradingday,productCode,equity'];
sql=sprintf('select %s from account where productCode = %s order by tradingDay',Index,foc);
cursorA=exec(conn,sql);
cursorA=fetch(cursorA);
FOFequity=cursorA.Data;
close(cursorA);
FundCodeValue=eval(FOFCode{1});
Index=['tradingDay,instType,instrumentCode,productCode,marketValue,direction'];
sql=sprintf('select %s from positions_history where left(productCode,5)=%d order by tradingDay',Index,FundCodeValue);
cursorA=exec(conn,sql);
cursorA=fetch(cursorA);
allInst=cursorA.Data;
close(cursorA);
instType=allInst(:,2);
instrumentCodeAll=allInst(:,3);
x=find(strncmp(instrumentCodeAll,'600',3)|strncmp(instrumentCodeAll,'601',3)...
|strncmp(instrumentCodeAll,'603',3)|strncmp(instrumentCodeAll,'000',3)...
|strncmp(instrumentCodeAll,'002',3)|strncmp(instrumentCodeAll,'300',3)...
|strcmp(instType,'期货'));
allInst=allInst(x,:);
instType=allInst(:,2);
instrumentCodeAll=allInst(:,3);
x=find(strncmp(instrumentCodeAll,'IC',2)|strncmp(instrumentCodeAll,'IF',2)...
|strncmp(instrumentCodeAll,'IH',2)|strcmp(instType,'股票'));
allInst=allInst(x,:);
allInst(:,3)=strrep(allInst(:,3),'CFFEX','CFE');
instrumentCodeUni=unique(allInst(:,3));
for i=1:1:length(allInst(:,1))
dayAll{i,1}=allInst{i};
end
dayUni=unique(dayAll);
FundCodeValue=eval(FOFCode{1});
Index=['productCode,accountType,parentProductCode'];
sql=sprintf('select %s from product where parentProductCode=%d ',Index,FundCodeValue);
cursorA=exec(conn,sql);
cursorA=fetch(cursorA);
Fundname=cursorA.Data;
close(cursorA);
Fund = Fundname{1,1};
Index=['tradingday,productCode,equity'];
sql=sprintf('select %s from account where productCode = %s order by tradingDay',Index,Fund);
cursorA=exec(conn,sql);
cursorA=fetch(cursorA);
Fundequity=cursorA.Data;
close(cursorA);
load('data0829/Rate.mat');
load('swRate.mat');
load('index_constituent.mat');
load('C:\Users\lenovo\Desktop\test\newtask\picktime\swRate.mat');
load('C:\Users\lenovo\Desktop\test\newtask\picktime\data0829\datafunda0001.mat');
load('C:\Users\lenovo\Desktop\test\newtask\picktime\data0829\Rate.mat');
load('index_weight.mat', 'index_weight');
[data_hangye,textdata_hangye,raw_hangye]=xlsread('行业权重.xlsx','Sheet1');
textdata_hangye 要改成 swCode
load('index_weight.mat');
k01= length(index_weight);
indexweight=[];
weight= 0;
for i= 1:28
j = i+1;
raw = textdata_hangye{j,1};
for p =1:k01
if find(strcmp(raw,index_weight{p,5}))
data_fund01 = index_weight(:,4);
aavalue = data_fund01{p,1};
if ~isnan(aavalue)
weight = weight+ aavalue;
end
end
end
indexweight{i,1}=weight;
weight= 0;
end
fundNameWeight(:,1)=textdata_hangye(2:end,1);
aa=0;
for i= 1:28
fundNameWeight{i,2}=indexweight{i,1};
aa= aa + indexweight{i,1};
end
save('fundNameWeight.mat','fundNameWeight');
load('fundNameWeight.mat');
多空
Ps*(RS- A)
PS*(WF*RF-WF*RI+WF*RI-WI*RI) WI是计算出来的 RI 是拉取出来的。
Ps*WF*(RF-RI) 是选股能力 算式是PS1*WF1*(RF1-RI1) 然后进行累加 28行业
其中 WF1 = T01/F, 其中T01 子基金中在某个行业下全部股票的市值,F 是子基金股票方面的市值
其中RF1 是某个行业的组合收益率R1*A/T01+R2*B/T01+R3*C/T01+....=(R1*A+R2*B+R3*C)/T01+
的份子已经求得 因式分解 PS*((T01/F)* ((R1*A+R2*B+R3*C)/T01-RI1) )=
H01 = l累计收益率, H02 = WF1*RI1
WI 是通过计算得来的,通过index_weight 这个表
通过index_weight构建一个行业包含表,28行,然后用行业包含的28同每个日股票做一个交集运算,然后计算学会用交集运算
stockName 是名称 全部股票
stockRate 是收益率 全部股票
for j=1:168
xday=Fundequity{j,1};
Fundday = Fundequity(:,1);
xf = find(strcmp(Fundday,xday));
Funddayinfo=Fundequity(xf,:);
Fname = allInst(:,4);
xa=find(strncmp(Fname,Fund,10));
tstockProp =0;
tfutureProp =0;
TsRate =0;
if ~isempty(xa)
alldayinfo=allInst(xa,:);
eday = alldayinfo(:,1);
xb=find(strcmp(eday,xday));
onedayinfo02=alldayinfo(xb,:);
xdx = xf;
atype = '股票';
ctype = onedayinfo02(:,2);
xc=find(strcmp(ctype,atype));
dayStockValue =0;
TsRate = 0;
if ~isempty(xc)
onedaystock=onedayinfo02(xc,:);
aa= cell2mat(onedaystock(:,5));
dayStockValue= sum(aa(:,1));
for kt=1:length(aa)
yd= find(strcmp(instrumentCodeUni,onedaystock{kt,3}));
if ~isempty(yd)
sRate=rateTable(xdx,yd);
if ~isnan(sRate)
TsRate=TsRate+sRate*onedaystock{kt,5}/dayStockValue;
end
end
end
end
end
swCode={ '801010.SI','801020.SI','801030.SI','801040.SI','801050.SI','801080.SI','801110.SI','801120.SI','801130.SI',...
'801140.SI','801150.SI','801160.SI','801170.SI','801180.SI','801200.SI','801210.SI','801230.SI','801710.SI',...
'801720.SI','801730.SI','801740.SI','801750.SI','801760.SI','801770.SI','801780.SI','801790.SI','801880.SI','801890.SI'};
sw= length(swCode);
newSW = swCode;
for i=1:sw
sw01= swCode{i};
ctype = index_weight(:,5);
xc=find(strcmp(ctype,swCode{i}));
if ~isempty(xc)
onedaycode=index_weight(xc,:);
b = length(onedaycode);
for j01 = 1:b
p=j01+1;
newSW{p,i}= onedaycode{j01,2};
end
end
end
Ht=0;
for t=1:28
p001 = length(newSW(:,t));
newS =0;
for i02=1:p001
if ~isnan(newSW{i02,t})
newS = newS +1;
end
end
ap01= newSW(1:newS,t);
trade = intersect(ap01,onedaystock(:,3));
Tvalue=0;
if ~isempty(trade)
tradeSize = length(trade);
for i01=1:tradeSize
aa01 =trade{i01,1};
num01 = find(strcmp(onedaystock(:,3),aa01));
Tvalue = Tvalue + onedaystock{num01,5};
end
end
swRt= swRate(xf,t);
Ht= Ht +swRt*Tvalue/dayStockValue;
end
AI=0;
for t02=1:28
swRt = swRate(xf,t02);
iWeight = fundNameWeight{t02,2}/100;
AI= AI+swRt*iWeight;
end
PhValue =PH(j,1);
selectStockph(j,1) = 0;
if ~isnan(PhValue*(TsRate-Ht))
selectStockph(j,1)= PhValue*(TsRate-Ht);
end
ConfigurationStockph(j,1) = 0;
if ~isnan(PhValue*(Ht-AI))
ConfigurationStockph(j,1)=PhValue*(Ht-AI);
end
PnValue = PN(j,1);
selectStockpn(j,1)= 0;
if ~isnan(PnValue*(TsRate-Ht))
selectStockpn(j,1)= PnValue*(TsRate-Ht);
end
ConfigurationStockpn(j,1)= 0;
if ~isnan(PnValue*(TsRate-Ht))
ConfigurationStockpn(j,1)=PnValue*(Ht-AI);
end
Po = 0.6;
PickTime(j,1) =0;
if ~isnan(PnValue*(TsRate-Ht))
PickTime(j,1)=(PnValue-Po)*AI;
end
end
figure;
hold on;
plot(PickTime(:,1),'g');