Esempio n. 1
0
 def update(self):
     lastdate = self.price.iloc[-1].date
     lastdatestr = lastdate.strftime("%Y%m%d")
     weight = self.price.iloc[1].totvalue
     self._updateurl = (
         "http://quotes.money.163.com/service/chddata.html?code="
         + self.code
         + "&start="
         + lastdatestr
         + "&end="
         + yesterday()
         + "&fields=TCLOSE"
     )
     df = pd.read_csv(self._updateurl, encoding="gb2312")
     self.name = df.iloc[0].loc["名称"]
     if len(df) > 1:
         df = df.rename(columns={"收盘价": "totvalue"})
         df["date"] = pd.to_datetime(df.日期)
         df = df.drop(["股票代码", "名称", "日期"], axis=1)
         df["netvalue"] = df.totvalue / weight
         df["comment"] = [0 for _ in range(len(df))]
         df = df.iloc[::-1].iloc[1:]
         df = df[df["date"].isin(opendate)]
         df = df.reset_index(drop=True)
         df = df[df["date"] <= yesterdayobj()]
         self.price = self.price.append(df, ignore_index=True, sort=True)
         return df
Esempio n. 2
0
 def __init__(self, code, fetch=False, save=False, path="", form="csv"):
     date = yesterday()
     self.rate = 0
     self._url = (
         "http://quotes.money.163.com/service/chddata.html?code="
         + code
         + "&start=19901219&end="
         + date
         + "&fields=TCLOSE"
     )
     super().__init__(code, fetch=fetch, save=save, path=path, form=form)
Esempio n. 3
0
    def __init__(self,
                 *codes,
                 start="20200101",
                 end=yesterday(),
                 col="close",
                 normalize=True):
        """

        :param codes: Union[str, tuple], 格式与 :func:`xalpha.universal.get_daily` 相同,若需要汇率转换,需要用 tuple,第二个元素形如 "USD"
        :param start: %Y%m%d
        :param end: %Y%m%d, default yesterday
        :param col: str, default close. The column to be compared.
        :param normalize: bool, default True. 是否将对比价格按起点时间归一。
        """
        totdf = pd.DataFrame()
        codelist = []
        for c in codes:
            if isinstance(c, tuple):
                code = c[0]
                currency = c[1]
            else:
                code = c
                currency = "CNY"  # 标的不做汇率调整
            codelist.append(code)
            df = xu.get_daily(code, start=start, end=end)
            df = df[df.date.isin(opendate)]
            currency_code = _get_currency_code(currency)
            if currency_code:
                cdf = xu.get_daily(currency_code, start=start, end=end)
                cdf = cdf[cdf["date"].isin(opendate)]
                df = df.merge(right=cdf, on="date", suffixes=("_x", "_y"))
                df[col] = df[col + "_x"] * df[col + "_y"]
            if normalize:
                df[code] = df[col] / df.iloc[0][col]
            else:
                df[code] = df[col]
            df = df.reset_index()
            df = df[["date", code]]
            if "date" not in totdf.columns:
                totdf = df
            else:
                totdf = totdf.merge(on="date", right=df)
        self.totdf = totdf
        self.codes = codelist
Esempio n. 4
0
 def update(self):
     lastdate = self.price.iloc[-1].date
     lastdatestr = lastdate.strftime('%Y%m%d')
     weight = self.price.iloc[1].totvalue
     self._updateurl = 'http://quotes.money.163.com/service/chddata.html?code=' + \
                       self.code + '&start=' + lastdatestr + '&end=' + yesterday() + '&fields=TCLOSE'
     df = pd.read_csv(self._updateurl, encoding='gb2312')
     self.name = df.iloc[0].loc['名称']
     if len(df) > 1:
         df = df.rename(columns={'收盘价': 'totvalue'})
         df['date'] = pd.to_datetime(df.日期)
         df = df.drop(['股票代码', '名称', '日期'], axis=1)
         df['netvalue'] = df.totvalue / weight
         df['comment'] = [0 for _ in range(len(df))]
         df = df.iloc[::-1].iloc[1:]
         df = df[df['date'].isin(opendate)]
         df = df.reset_index(drop=True)
         df = df[df['date'] <= yesterdayobj()]
         self.price = self.price.append(df, ignore_index=True, sort=True)
         return df
Esempio n. 5
0
 def __init__(self,
              code,
              value_label=0,
              fetch=False,
              save=False,
              path="",
              form="csv"):
     date = yesterday()
     if code.startswith("SH") and code[2:].isdigit():
         code = "0" + code[2:]
     elif code.startswith("SZ") and code[2:].isdigit():
         code = "1" + code[2:]
     self.rate = 0
     self._url = ("http://quotes.money.163.com/service/chddata.html?code=" +
                  code + "&start=19901219&end=" + date + "&fields=TCLOSE")
     super().__init__(code,
                      value_label=value_label,
                      fetch=fetch,
                      save=save,
                      path=path,
                      form=form)
Esempio n. 6
0
 def __init__(self, code, fetch=False, save=False, path='', form='csv'):
     date = yesterday()
     self.rate = 0
     self._url = 'http://quotes.money.163.com/service/chddata.html?code=' + code + '&start=19901219&end=' + date + '&fields=TCLOSE'
     super().__init__(code, fetch=fetch, save=save, path=path, form=form)