def clean_data(collection_name):
    # 获取所有的手续费
    vals = get_collection(collection_name).distinct("日增长率")
    for val in vals:
        get_collection(collection_name).update_many(
            {"日增长率": val}, {"$set": {
                "日增长率": val.strip()
            }})
    print("清理手续费中\\n")
Exemple #2
0
 def get_data(self, fund_code="", is_all=False):
     # 获取基金
     if is_all is False:
         if fund_code == "":
             vals = get_collection("all_funds").find_one({})
         else:
             vals = get_collection('all_funds').find_one(
                 {'基金代码': fund_code})
         return vals
     else:
         vals = get_collection("all_funds").find()
         return vals
def update_add(collection_name):
    """
    weekday 添加
    :return:
    """
    for i in range(370, 1460, 1):
        day = date.today() - timedelta(days=i)
        print("正在调整", day)
        get_collection(collection_name).update_many(
            {"日期": str(day)}, {"$set": {
                "weekday": str(day.weekday())
            }})
    print("添加星期几成功")
def get_all_fund_cod(collection_name):
    """
    获取基金的code
    :return:
    """
    vals = get_collection(collection_name).distinct("基金代码")
    for val in vals:
        in_val = get_collection(collection_name).find_one({"基金代码": val})
        item = {}
        item["基金代码"] = in_val["基金代码"]
        item["基金简称"] = in_val["基金简称"]
        try:
            get_collection("all_funds").insert_one(item)
        except Exception as e:
            print("出现异常", e)
    print("加载 所有基金 代号 成功")
Exemple #5
0
 def get_data_to_show(self, vals, isdel_error=True):
     # print(vals['基金代码'])
     all_vals = get_collection("hostory_vals").find({
         "基金代码": vals['基金代码']
     }).sort([('日期', pymongo.ASCENDING)])
     items = []
     for all_val in all_vals:
         if all_val['weekday'] == '2' or all_val[
                 'weekday'] == '3' or all_val['weekday'] == '4':
             if all_val['weekday'] == '2':
                 item = {}
                 item["start"] = "\t".join(
                     [all_val['日期'], all_val['单位净值'], all_val['weekday']])
             elif all_val['weekday'] == '3':
                 item["middle"] = "\t".join(
                     [all_val['日期'], all_val['单位净值'], all_val['weekday']])
             elif all_val['weekday'] == '4':
                 item["end"] = "\t".join(
                     [all_val['日期'], all_val['单位净值'], all_val['weekday']])
                 items.append(item)
     if isdel_error:
         # 删除 不符号要求的数据
         self.del_index_item(items)
     else:
         # 改变 不符合要求的数据
         self.exchange_items(items)
     # 获取三组数据
     three_vals = [[], [], [], []]
     for item in items:
         three_vals[0].append(item["middle"].split("\t")[0])
         three_vals[1].append(float(item["start"].split("\t")[1]))
         three_vals[2].append(float(item["middle"].split("\t")[1]))
         three_vals[3].append(float(item["end"].split("\t")[1]))
     print(three_vals)
     return three_vals, vals
# coding ='utf-8'
import pymongo
from pylab import mpl
import matplotlib.pyplot as plt
from quant_all.database.mongoData import get_collection

mpl.rcParams['font.sans-serif'] = ['SimHei']

# 获取基金
vals = get_collection("all_funds").find_one({})

# print(vals['基金代码'])
all_vals = get_collection("hostory_vals").find({
    "基金代码": vals['基金代码']
}).sort([('日期', pymongo.ASCENDING)])
items = []
for all_val in all_vals:
    if all_val['weekday'] == '2' or all_val['weekday'] == '3' or all_val[
            'weekday'] == '4':
        if all_val['weekday'] == '2':
            item = {}
            item["start"] = "\t".join(
                [all_val['日期'], all_val['单位净值'], all_val['weekday']])
        elif all_val['weekday'] == '3':
            item["middle"] = "\t".join(
                [all_val['日期'], all_val['单位净值'], all_val['weekday']])
        elif all_val['weekday'] == '4':
            item["end"] = "\t".join(
                [all_val['日期'], all_val['单位净值'], all_val['weekday']])
            items.append(item)
        # print(item)