Rs—Ri—部分差Rsf部分
% 20160825
% 得到母基金的股票和股指期货持仓的交易日收益率
%计算母基金equity 下 PN,PH的占比计算,分别求得相应的日占比。
%{
Rate= Pn*Rs+ Ph*(Rs-Ri)+Ph*(Ri-Rsf)+Pcf*Rcf
Rs 股票净值收益率
Ri 股指期货指数收益率,股指+期货的收益率,反应的是股票 指数部分的收益
Rsf 股指期货净值收益率
Pn Ph 分种类情况
%}
clear;clc
tic
load('Rate.mat')
%% 母基金名称
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);
%% 提取母基金的equity值
foc= FOFCode{1,1}; %母基金名称
Index=['tradingday,productCode,equity'];
%sql=sprintf('select %s from account where productCode = %d',Index,foc);
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});%cell转数值为母基金的代码
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);
%% 保留‘600’、‘601’、‘603’、‘000’、‘002’和‘300’打头的股票部分
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,'期货')); %这个是找到x的位置数值
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');%'CFFEX'替换为'CFE',便于wind查询
%% 提取股票、股指期货的日收益率
instrumentCodeUni=unique(allInst(:,3)); %存储所有不重复的股票代码
for i=1:1:length(allInst(:,1))
dayAll{i,1}=allInst{i}; % 日期在第一列
end
dayUni=unique(dayAll);
%% 以上已经将母基金包含的信息全部得到了,下面先求子基金代码,
FundCodeValue=eval(FOFCode{1});%cell转数值为母基金的代码 ,数值转换
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);
%% 子基金运算 提取子基金的equity值
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);
%%
%当a10 为 1 时候,基金没有数据,当不等于1时有数据
a10 = length(Fundequity);
for j=1:165
%j=161;
xday=Fundequity{j,1};
Fundday = Fundequity(:,1);
xf = find(strcmp(Fundday,xday));
Funddayinfo=Fundequity(xf,:); %xf 就是占位数目,同收益率 有关
Fname = allInst(:,4); %子基金
xa=find(strncmp(Fname,Fund,10)); %某个子基金下的某日的股票和期货
if length(xa)~=0 %判断是否有股票 期货
alldayinfo=allInst(xa,:); %可能里面有重复的
eday = alldayinfo(:,1); %全部日期
xb=find(strcmp(eday,xday));
onedayinfo02=alldayinfo(xb,:);
xdx= find(strcmp(dayUni,xday));%通过dayUni 确定信息在rateTable的第几行
%% %判断股票和期货是否存在
%% 股票类,收益率
atype = '股票';
ctype = onedayinfo02(:,2);
xc=find(strcmp(ctype,atype));
if length(xc)~=0
onedaystock=onedayinfo02(xc,:); %利用这个onedaystock 找到所有当日收益率,列值
aa= cell2mat(onedaystock(:,5));%xday 从rateTable 可以找到相应的收益率,然后同股票的相乘
%kt =1;%第一只股票
TsRate = 0; %当天的多股票累计收益率
for kt=1:length(aa)
yd= find(strcmp(instrumentCodeUni,onedaystock{kt,3}));
sRate=rateTable(xdx,yd); %ook
%fprintf('%d',sRate);
%tsRate = isnan(sRate);
if isnan(sRate)
sRate =0; %如果当天没有数据,当天的收益率就是 0;
TsRate=TsRate+sRate*onedaystock{kt,5}/Funddayinfo{1,3};
else
TsRate=TsRate+sRate*onedaystock{kt,5}/Funddayinfo{1,3};
end
end
dayStockValue= sum(aa(:,1)); %股票就全加一下子,基金判断一下再加
end %length(xc)~=0
%% 期货指数类,收益率
btype = '期货'; %多开和空开要相减
ctype = onedayinfo02(:,2);
xd1=find(strcmp(ctype,btype));
dayfdd=0;
dayfkk=0;
if length(xd1)~=0 %判断xd 是否存在
onedayfuture=onedayinfo02(xd1,:);
%找到多开 - 空开
ftype = '多开';
ftype01 = '买入';
htype = onedayfuture(:,6);
xe=find(strcmp(htype,ftype)|strcmp(htype,ftype01));
if length(xe)~=0
onedayfuturedd=onedayfuture(xe,:);
a1= cell2mat(onedayfuturedd(:,5));
dayfdd= sum(a1(:,1)); %基金多开累加
end
gtype = '空开';
gtype01 = '卖出';
jtype = onedayfuture(:,6);
xr=find(strcmp(jtype,gtype)|strcmp(jtype,gtype01));
if length(xr)~=0
onedayfuturekk=onedayfuture(xr,:);
a2= cell2mat(onedayfuturekk(:,5));
dayfkk= sum(a2(:,1)); %基金空开累加
end
%% 期货收益率计算,RI
%先用时间找到 IF IC IH 这三个变量的值,然后根据下面的分类分别相乘
% AIF=IF*(多头-空头) AIC=IC*(多头-空头) AIH=IH*(多头-空头)
%想法没有错,确实是指数收益
%RI= AIF+AIC+AIH
onedayfuture=onedayinfo02(xd1,:);
TFRate=rateTable(xdx,1823);
TCRate=rateTable(xdx,1824);
THRate=rateTable(xdx,1825);
%判断是IF IC IH, 三次判断如果有就是 value 如果没有就是 0
xih=find(strncmp(onedayfuture(:,3),'IH',2));
ihvalue =0;
if xih
onedayfutureih=onedayfuture(xih,:);
%找到多开 - 空开
ftype = '多开';
ftype01 = '买入';
htype = onedayfutureih(:,6);
xe=find(strcmp(htype,ftype)|strcmp(htype,ftype01));
ihdayfdd =0;
if length(xe)~=0
onedayfuturedd=onedayfutureih(xe,:);
a1= cell2mat(onedayfuturedd(:,5));
ihdayfdd= sum(a1(:,1)); %基金多开累加
end
gtype = '空开';
gtype01 = '卖出';
jtype = onedayfutureih(:,6);
xr=find(strcmp(jtype,gtype)|strcmp(jtype,gtype01));
ihdayfkk =0;
if length(xr)~=0
onedayfuturekk=onedayfutureih(xr,:);
a2= cell2mat(onedayfuturekk(:,5));
ihdayfkk= sum(a2(:,1)); %基金空开累加
end
ihvalue =ihdayfdd-ihdayfkk;
end
xic=find(strncmp(onedayfuture(:,3),'IC',2));
icvalue =0;
if xic
onedayfutureic=onedayfuture(xic,:);
%找到多开 - 空开
ftype = '多开';
ftype01 = '买入';
htype = onedayfutureic(:,6);
xe=find(strcmp(htype,ftype)|strcmp(htype,ftype01));
icdayfdd = 0;
if length(xe)~=0
onedayfuturedd=onedayfutureic(xe,:);
a1= cell2mat(onedayfuturedd(:,5));
icdayfdd= sum(a1(:,1)); %基金多开累加
end
gtype = '空开';
gtype01 = '卖出';
jtype = onedayfutureic(:,6);
xr=find(strcmp(jtype,gtype)|strcmp(jtype,gtype01));
icdayfkk =0;
if length(xr)~=0
onedayfuturekk=onedayfutureic(xr,:);
a2= cell2mat(onedayfuturekk(:,5));
icdayfkk= sum(a2(:,1)); %基金空开累加
end
icvalue =icdayfdd-icdayfkk;
end
xif=find(strncmp(onedayfuture(:,3),'IF',2));
ifvalue =0;
if xif
onedayfutureif=onedayfuture(xif,:);
%找到多开 - 空开
ftype = '多开';
ftype01 = '买入';
htype = onedayfutureif(:,6);
xe=find(strcmp(htype,ftype)|strcmp(htype,ftype01));
ifdayfdd =0;
if length(xe)~=0
onedayfuturedd=onedayfutureif(xe,:);
a1= cell2mat(onedayfuturedd(:,5));
ifdayfdd= sum(a1(:,1)); %基金多开累加
end
gtype = '空开';
gtype01 = '卖出';
jtype = onedayfutureif(:,6);
xr=find(strcmp(jtype,gtype)|strcmp(jtype,gtype01));
ifdayfkk =0;
if length(xr)~=0
onedayfuturekk=onedayfutureif(xr,:);
a2= cell2mat(onedayfuturekk(:,5));
ifdayfkk= sum(a2(:,1)); %基金空开累加
end
ifvalue =ifdayfdd-ifdayfkk;
end
IIIrate= TFRate*ihvalue + TCRate*icvalue + THRate*ifvalue;
%%
else
dayfdd=0;
dayfkk=0;
IIIrate =0; % 代表了指数收益
end
tstockRate = dayStockValue/Funddayinfo{1,3};
tfutureRate = (dayfdd-dayfkk)/Funddayinfo{1,3};
end
infodata5{j,1}=xday;
infodata5{j,2}=tstockRate;
infodata5{j,3}=tfutureRate;
infodata5{j,4}=TsRate;
infodata5{j,5}=IIIrate;
end
%save('infodata5.mat','infodata5');
Rs—Ri—部分差Rsf部分相关推荐
- python2、python3部分差异点
1.打印: Python2 :既可度以使用带小括号的方式,也可以使用一个空格来分隔打印内容,比如 print 'hi' Python3 :使用 print 必须要以小括号包括打知印内容,比如 prin ...
- sift的java实现解述
代码已经开源到github上,https://github.com/alibaba/simpleimage项目,其中的 analyze模块中. 原始图片为: 主要调用方法: [java] view p ...
- 择时 配置 选股 2016-9-12 图形正确
%% %{only hate road when you miss home Ps 股票占比是第二列 Psf 股指期货占比是第三列 Rs 第四列 股票收益 Ri 第五列 指数收益,三个指数 Rsf 第 ...
- POCO C++库学习和分析 -- 序
POCO C++库学习和分析 -- 序 1. POCO库概述: POCO是一个C++的开源库集.同一般的C++库相比,POCO的特点是提供了整一个应用框架.如果要做C++程序应用框架的快速开发,我觉得 ...
- 计算机体系结构——流水线技术(Pipelining)
本文导读: 一.并行技术 1.并行技术分类 2.新技术的设计与实现 3.指令周期二.流水线技术 1.什么是流水线 2.指令重叠方式 3.流水工作设计 4.流水线的描述方法(时空图) 5.流水线特点三. ...
- 计算机体系结构——流水线技术
计算机体系结构--流水线技术(Pipelining) 本文导读: 一.并行技术 1.并行技术分类 2.新技术的设计与实现 3.指令周期二.流水线技术 1.什么是流水线 2.指令重叠方式 3.流水工作设 ...
- rtklib单点定位
前言 单点定位是卫星定位里面最基本的一个定位算法,基本原理是:假如在地上的一个点A,能观测到4颗卫星(卫星位置已知),通过后方交汇原理就可以求出点A的概略位置,精度在m级. 单点定位算法除了能给提供一 ...
- 难忘的一天——装操作系统(二)
接下来准备好自己要安装系统的电脑,最后看一眼我的正版win10系统,不舍,蓝瘦香菇! 第一步: 插好优盘,开机,在出现电脑logo时,按(Delete+F2)进入BIOS界面. 首先不同电脑,进入BI ...
- 社会生活中常用的14条著名法则
一. 马太效应 八. 水桶定律 二. 手表定理 九. 蘑菇管理 三. 不值得定律 十. 奥卡姆剃刀定律 四. 彼得原理 十一. 二八定律 五. 零和游戏原理 十二. 钱的问题 六. 华盛顿合作规律 十 ...
最新文章
- 相机标定:(1)相机模型
- 通用双向链表的设计(参考Linux系统中的实现)
- Channels In Go
- 不想打造物联网的制造型企业不是一家合格的百年老店
- kong 网关教程入门
- [模板] 线筛欧拉函数
- Eclipse内存溢出
- 最简单的方式开发一个高并发服务器
- CS231n Assignment1 Knn
- 体育馆预约系统java_基于SSM框架下的JAVA体育场地预约系统
- 单片机c语言曲普两只蝴蝶,51单片机蜂鸣器播放音乐代码(生日快乐 两只蝴蝶 祝你平安)...
- 抖音快手短视频去水印API,接口开发文档
- MySQL的两阶段提交(数据一致性)
- 邯郸三中高考2021成绩查询,邯郸2021年中考统考成绩
- Three.js 绘图之不规则路径 3D 墙体生成算法
- 使用拦截器防止表单重复提交
- 开发环境 -- 在linux中写一个脚本拷机
- 携程再爆大数据杀熟,携程致歉信:程序 bug 已紧急修复,将赔偿用户
- UrlRewriter url 地址重写
- 幼儿园语言活动包括哪几类_幼儿园健康活动分为哪几类,幼儿园教育活动包括...
热门文章
- 2.2 DP: Value Iteration Gambler‘s Problem
- 【HDU 5755】Gambler Bo(高斯消元)
- 动图太大无法添加到微信表情怎么办?
- 亲测,2023年私藏的免费好用的磁力网盘资源搜索网站,找资源不用愁
- 五猴分桃python_五猴分桃问题
- 烤仔TVのCCW | 带宽不可能三角(上)
- mes系统故障_mes系统实施失败是什么原因?
- Android FrameWork(AMS,WMS,PMS等)的概念及解析,获取系统服务
- 浏览器无法访问此网站,连接已被重置,无法加载
- 【疑难解决】通过网页访问EasyDSS报错出现“无法访问此网站”提示的排查过程