예제 #1
0
 def __init__(self,
              *fundtradeobj,
              status=None,
              property=None,
              fetch=False,
              save=False,
              path="",
              form="csv",
              totmoney=100000,
              cashobj=None):
     super().__init__(*fundtradeobj,
                      status=status,
                      property=property,
                      fetch=fetch,
                      save=save,
                      path=path,
                      form=form)
     if cashobj is None:
         cashobj = cashinfo()
     self.totmoney = totmoney
     nst = mulfix._vcash(totmoney, self.totcftable, cashobj)
     cashtrade = trade(cashobj, nst)
     # 		 super().__init__(*self.fundtradeobj, cashtrade)
     self.fundtradeobj = list(self.fundtradeobj)
     self.fundtradeobj.append(cashtrade)
     self.fundtradeobj = tuple(self.fundtradeobj)
     btnk = bottleneck(self.totcftable)
     if btnk > totmoney:
         raise TradeBehaviorError("the initial total cash is too low")
     self.totcftable = pd.DataFrame(data={
         "date": [nst.iloc[0].date],
         "cash": [-totmoney]
     })
예제 #2
0
    def combsummary(self, date=yesterdayobj()):
        '''
        brief report table of every funds and the combination investment

        :param date: string or obj of date, show info of the date given
        :returns: empty dict if nothing is remaining that date
            dict of various data on the trade positions
        '''
        date = convert_date(date)
        columns = ['基金名称', '基金代码', '当日净值', '单位成本', '持有份额', '基金现值', '基金总申购', '历史最大占用',
                   '基金持有成本', '基金分红与赎回', '换手率', '基金收益总额', '投资收益率']
        summarydf = pd.DataFrame([], columns=columns)
        for fund in self.fundtradeobj:
            summarydf = summarydf.append(fund.dailyreport(date), ignore_index=True, sort=True)
        tname = '总计'
        tcode = 'total'
        tunitvalue = float('NaN')
        tunitcost = float('NaN')
        tholdshare = float('NaN')
        tcurrentvalue = summarydf['基金现值'].sum()
        tpurchase = summarydf['基金总申购'].sum()
        tbtnk = bottleneck(self.totcftable[self.totcftable['date'] <= date])
        tcost = summarydf['基金持有成本'].sum()
        toutput = summarydf['基金分红与赎回'].sum()
        tturnover = turnoverrate(self.totcftable[self.totcftable['date'] <= date], date)
        # 计算的是总系统作为整体和外界的换手率,而非系统各成分之间的换手率
        tearn = summarydf['基金收益总额'].sum()
        trate = round(tearn / tbtnk * 100, 4)
        trow = pd.DataFrame([[tname, tcode, tunitvalue, tunitcost, tholdshare,
                              tcurrentvalue, tpurchase, tbtnk, tcost, toutput, tturnover, tearn, trate]],
                            columns=columns)
        summarydf = summarydf.append(trow, ignore_index=True, sort=True)

        return summarydf[columns].sort_values(by="基金现值", ascending=False)
예제 #3
0
 def __init__(self, *fundtradeobj, status=None, fetch=False, save=False, path='', form='csv', totmoney=100000,
              cashobj=None):
     super().__init__(*fundtradeobj, status=status, fetch=fetch, save=save, path=path, form=form)
     if cashobj is None:
         cashobj = cashinfo()
     self.totmoney = totmoney
     nst = mulfix._vcash(totmoney, self.totcftable, cashobj)
     cashtrade = trade(cashobj, nst)
     #		 super().__init__(*self.fundtradeobj, cashtrade)
     self.fundtradeobj = list(self.fundtradeobj)
     self.fundtradeobj.append(cashtrade)
     self.fundtradeobj = tuple(self.fundtradeobj)
     btnk = bottleneck(self.totcftable)
     if btnk > totmoney:
         raise Exception('the initial total cash is too low')
     self.totcftable = pd.DataFrame(data={'date': [nst.iloc[0].date], 'cash': [-totmoney]})
예제 #4
0
    def combsummary(self, date=yesterdayobj()):
        """
        brief report table of every funds and the combination investment

        :param date: string or obj of date, show info of the date given
        :returns: empty dict if nothing is remaining that date
            dict of various data on the trade positions
        """
        date = convert_date(date)
        columns = [
            "基金名称",
            "基金代码",
            "当日净值",
            "单位成本",
            "持有份额",
            "基金现值",
            "基金总申购",
            "历史最大占用",
            "基金持有成本",
            "基金分红与赎回",
            "换手率",
            "基金收益总额",
            "投资收益率",
        ]
        summarydf = pd.DataFrame([], columns=columns)
        for fund in self.fundtradeobj:
            summarydf = summarydf.append(fund.dailyreport(date),
                                         ignore_index=True,
                                         sort=True)
        tname = "总计"
        tcode = "total"
        tunitvalue = float("NaN")
        tunitcost = float("NaN")
        tholdshare = float("NaN")
        tcurrentvalue = summarydf["基金现值"].sum()
        tpurchase = summarydf["基金总申购"].sum()
        tbtnk = bottleneck(self.totcftable[self.totcftable["date"] <= date])
        tcost = summarydf["基金持有成本"].sum()
        toutput = summarydf["基金分红与赎回"].sum()
        tturnover = turnoverrate(
            self.totcftable[self.totcftable["date"] <= date], date)
        # 计算的是总系统作为整体和外界的换手率,而非系统各成分之间的换手率
        tearn = summarydf["基金收益总额"].sum()
        trate = round(tearn / tbtnk * 100, 4)
        trow = pd.DataFrame(
            [[
                tname,
                tcode,
                tunitvalue,
                tunitcost,
                tholdshare,
                tcurrentvalue,
                tpurchase,
                tbtnk,
                tcost,
                toutput,
                tturnover,
                tearn,
                trate,
            ]],
            columns=columns,
        )
        summarydf = summarydf.append(trow, ignore_index=True, sort=True)

        return summarydf[columns].sort_values(by="基金现值", ascending=False)
예제 #5
0
    def v_xirrate(self,start_date, end_date=yesterdayobj()):
        """
        graph of the xirate of the over all investment

        :param date: string or obj of date, show info of the date given
        :returns:
        """
        start_date = convert_date(start_date)
        end_date = convert_date(end_date)
        columns = [
            "基金名称",
            "基金代码",
            "当日净值",
            "单位成本",
            "持有份额",#changed to date
            "基金现值",
            "基金总申购",
            "历史最大占用",
            "基金持有成本",
            "基金分红与赎回",
            "换手率",
            "基金收益总额",
            "投资收益率",
        ]
        columns_tot = [
            "基金名称",
            "基金代码",
            "当日净值",
            "单位成本",
            "持有份额",#changed to date
            "基金现值",
            "基金总申购",
            "历史最大占用",
            "基金持有成本",
            "基金分红与赎回",
            "换手率",
            "基金收益总额",
            "投资收益率",
        ]
        tsummarydf = pd.DataFrame([],columns=columns)
        for date in pd.date_range(start_date,end_date):
            summarydf = pd.DataFrame([], columns=columns)
            for fund in self.fundtradeobj:
                summarydf = summarydf.append(
                    fund.dailyreport(date), ignore_index=True, sort=True
                )
            tname = "总计"
            tcode = "total"
            tunitvalue = float("NaN")
            tunitcost = float("NaN")
            tholdshare = date
            tcurrentvalue = summarydf["基金现值"].sum()
            tpurchase = summarydf["基金总申购"].sum()
            tbtnk = bottleneck(self.totcftable[self.totcftable["date"] <= date])
            tcost = summarydf["基金持有成本"].sum()
            toutput = summarydf["基金分红与赎回"].sum()
            tturnover = turnoverrate(self.totcftable[self.totcftable["date"] <= date], date)
            # 计算的是总系统作为整体和外界的换手率,而非系统各成分之间的换手率
            tearn = summarydf["基金收益总额"].sum()
            trate = round(tearn / tbtnk * 100, 4)
            trow = pd.DataFrame(
                [
                    [
                        tname,
                        tcode,
                        tunitvalue,
                        tunitcost,
                        tholdshare,
                        tcurrentvalue,
                        tpurchase,
                        tbtnk,
                        tcost,
                        toutput,
                        tturnover,
                        tearn,
                        trate,
                    ]
                ],
                columns=columns
            )
            # summarydf = summarydf.append(trow, ignore_index=True, sort=True)
            tsummarydf = tsummarydf.append(trow, ignore_index=True, sort=True)

        return tsummarydf[columns].sort_values(by="持有份额", ascending=False)