示例#1
0
def get_fund(code):
    if code[0] == "F":
        df = fundinfo(code[1:]).price
    elif code[0] == "M":
        df = mfundinfo(code[1:]).price
    df["close"] = df["netvalue"]
    return df[["date", "close"]]
示例#2
0
 def __init__(self,
              *fundtradeobj,
              status=None,
              fetch=False,
              save=False,
              path="",
              form="csv"):
     if not fundtradeobj:
         # warning: not a very good way to automatic generate these fund obj
         # because there might be some funds use round_down for share calculation, ie, label=2 must be given
         # unless you are sure corresponding funds are added to the droplist
         fundtradeobj = []
         for code in status.columns[1:]:
             try:
                 fundtradeobj.append(
                     trade(
                         fundinfo(code,
                                  fetch=fetch,
                                  save=save,
                                  path=path,
                                  form=form),
                         status,
                     ))
             except FundTypeError:
                 fundtradeobj.append(
                     trade(
                         mfundinfo(code,
                                   fetch=fetch,
                                   save=save,
                                   path=path,
                                   form=form),
                         status,
                     ))
     self.fundtradeobj = tuple(fundtradeobj)
     self.totcftable = self._mergecftb()
示例#3
0
    def __init__(self,
                 *fundtradeobj,
                 status=None,
                 property=None,
                 fetch=False,
                 save=False,
                 path="",
                 form="csv"):
        if isinstance(status, record):
            if not property:
                property = getattr(status, "property", {})
            status = status.status
        elif not property:
            property = {}

        if not fundtradeobj:
            # warning: not a very good way to automatic generate these fund obj
            # because there might be some funds use round_down for share calculation, ie, label=2 must be given
            # unless you are sure corresponding funds are added to the droplist
            fundtradeobj = []
            for code in status.columns[1:]:
                # r1, d2, v4 p = r+d+v
                p = property.get(code, 0)
                round_label = p % 2
                dividend_label = ((p - round_label) / 2) % 2
                value_label = ((p - round_label - dividend_label) / 4) % 2
                try:
                    fundtradeobj.append(
                        trade(
                            fundinfo(
                                code,
                                round_label=round_label,
                                dividend_label=dividend_label,
                                fetch=fetch,
                                save=save,
                                path=path,
                                form=form,
                            ),
                            status,
                        ))
                except FundTypeError:
                    fundtradeobj.append(
                        trade(
                            mfundinfo(
                                code,
                                round_label=round_label,
                                value_label=value_label,
                                fetch=fetch,
                                save=save,
                                path=path,
                                form=form,
                            ),
                            status,
                        ))
        self.fundtradeobj = tuple(fundtradeobj)
        self.totcftable = self._mergecftb()
示例#4
0
    def get_info(self, code):
        """
        get the correct new info object based on Fcode

        :param code:
        :return:
        """
        if code in self.infos:
            return self.infos[code]
        if code.startswith("F"):
            try:
                return fundinfo(code[1:])
            except FundTypeError:
                return mfundinfo(code[1:])
        elif code.startswith("M"):
            return mfundinfo(code[1:])
        else:
            return vinfo(
                code, start=(self.start - pd.Timedelta(days=180)).strftime("%Y-%m-%d")
            )
示例#5
0
 def __init__(self,
              *fundtradeobj,
              status=None,
              istatus=None,
              property=None,
              fetch=False,
              save=False,
              path="",
              form="csv"):
     if isinstance(status, record):
         if not property:
             property = getattr(status, "property", {})
         status = status.status
     elif not property:
         property = {}
     self.is_in = False
     if fundtradeobj:
         for t in fundtradeobj:
             if isinstance(t, itrade):
                 self.is_in = True
             break
     else:
         fundtradeobj = []
         # warning: not a very good way to automatic generate these fund obj
         # because there might be some funds use round_down for share calculation, ie, label=2 must be given
         # unless you are sure corresponding funds are added to the droplist
     fundcodelist = [f.code for f in fundtradeobj]
     if status is not None:
         for code in status.columns:
             if code == "date":
                 continue
             # r1, d2, v4 p = r+d+v
             if code in fundcodelist:
                 continue
             p = property.get(code, 0)
             round_label = p % 2
             dividend_label = ((p - round_label) / 2) % 2
             value_label = ((p - round_label - dividend_label) / 4) % 2
             try:
                 fundtradeobj.append(
                     trade(
                         fundinfo(
                             code,
                             round_label=round_label,
                             dividend_label=dividend_label,
                             fetch=fetch,
                             save=save,
                             path=path,
                             form=form,
                         ),
                         status,
                     ))
             except FundTypeError:
                 fundtradeobj.append(
                     trade(
                         mfundinfo(
                             code,
                             round_label=round_label,
                             value_label=value_label,
                             fetch=fetch,
                             save=save,
                             path=path,
                             form=form,
                         ),
                         status,
                     ))
         if istatus is not None:
             self.is_in = True
             if isinstance(istatus, irecord):
                 istatus = istatus.status
             for code in istatus.code.unique():
                 if code not in fundcodelist and not code.startswith("#"):
                     fundtradeobj.append(itrade(code, istatus))
     self.fundtradeobj = tuple(fundtradeobj)
     self.totcftable = self._mergecftb()