基金大数据分析及基金投资建议(Python与Excel实现)

如果需要转载本文或者需要相关的数据资料,请与我联系。邮箱:[email protected]

一、目标确定
本次主要通过对基金进行大数据分析,了解目前开放型基金的现状,同时对基金的评级及回报率等相关数据进行分析,以确定最佳基金投资标的。

二、数据获取

数据获取方面,采用数据采集器,对天天基金网及晨星网的数据进行搜集。搜索数据包括基金的基本信息及分红数据,基金的历年收益率数据,基金的评级数据(包括晨星网和证券公司等评级机构的评级数据,数据量总计大约在一万五千条左右。并将数据存放在四个excel文件中,分别存放于divF.xlsx,OpenF.xlsx,RankOpenF.xlsx,tiantianRank.xlsx四个文件,作为数据源。
数据已经过清洗,其简要情况如下:
divF.xlsx:
在这里插入图片描述
OpenF.xlsx
在这里插入图片描述
RankOpenF.xlsx:
在这里插入图片描述
tiantianRank.xlsx:
在这里插入图片描述

三、数据清洗
数据清洗会消耗掉大量的时间,主要采用excel和python的相关功能进行,如excel的查找替换,python的dropna()等等。这里不过多描述。

四、数据整理及分析
这部分是核心,重点围绕数据整理及描述分析进行,呈现相应的实现代码和相关图表。后续依次生成数据分析报告。算是手把手教你如何用python进行基金的大数据分析了。
处理前提,导入相应的库:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from pyecharts import Bar
import matplotlib
matplotlib.matplotlib_fname()  #会显示matplotlibrc文件的地址
from pyecharts import online

online() # needed for online viewing
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
#有中文出现的情况,需要u'内容'

第一步,我们对整体的基金收益率进行简单分析,大部分分析思路已经通过注释的形式给出。这里文字点到为止。

#读入前期通过爬虫采集器采集天天基金网的数据
openF=pd.read_excel('D:/PythonData/OpenF.xlsx')
openF.head(3) #查看一下数据是否有异常。

显示如下:
在这里插入图片描述

#重命名索引为English name,方便数据处理,上面看到基金代码前面的0没识别,读的时候,把它转为str格式。
openF=pd.read_excel('D:/PythonData/OpenF.xlsx',converters = {u'基金代码':str}) #
openF.rename(columns={'序号':'NO.','基金代码':'code','基金简称':'name', '日期':'date','单位净值':'unitnet','累计净值':'sumnet','日增长率':'Dailygrowth','近1周':'Rweek','近1月':'R1month','近3月':'R3months','近6月':'R6months','近1年':'R1year','近2年':'R2years','近3年':'R3years','今年来':'thisyear','成立来':'SinceFounded','手续费':'charges'},inplace=True)
openF.head(3)

其显示如下:
在这里插入图片描述

#删除重复采集的数据序列
openF.drop_duplicates(inplace=True)
openF.describe()
#我们希望稳健一点,今年至今的8个月,上证指数差不多回到原点,我们希望基金今年的收益率为正。
type(openF.Dailygrowth[0]) #查看其均为str类型,需要转换成整数型
#open_F=openF[{'Dailygrowth','Rweek'}].str.strip('%').astype(float)/100   不可哈希,有毛病,得一个个来
temp=openF.replace('---',np.nan)
openF=temp.replace('--',np.nan)
openF.tail(100)
openF.dropna(inplace=True) #寻找那些成立3年以上的基金,删除近三年收益率为Nan的基金
#openF.count()

由于百分数导入为字符串格式,我们需要将其转换为float模式。

Dailygrowth=openF['Dailygrowth'].str.strip('%').astype(float)/100 
Rweek=openF['Rweek'].str.strip('%').astype(float)/100 
R1month=openF['R1month'].str.strip('%').astype(float)/100 
R3months=openF['R3months'].str.strip('%').astype(float)/100 
R6months=openF['R6months'].str.strip('%').astype(float)/100 
R1year=openF['R1year'].str.strip('%').astype(float)/100 
R2syears=openF['R2years'].str.strip('%').astype(float)/100
R3years=openF['R3years'].str.strip('%').astype(float)/100
thisyear=openF['thisyear'].str.strip('%').astype(float)/100
SinceFounded=openF['SinceFounded'].str.strip('%').astype(float)/100
charges=openF['charges'].str.strip('%').astype(float)/100 

openF['Dailygrowth']=Dailygrowth
openF['Rweek']=Rweek
openF['R1month']=R1month
openF['R3months']=R3months
openF['R6months']=R6months
openF['R1year']=R1year
openF['R2years']=R2syears
openF['R3years']=R3years
openF['thisyear']=thisyear
openF['SinceFounded']=SinceFounded
openF['charges']=charges

借助数据化的手段,让我们对基金的整体情况有一个更为直观的把握。可视化有助于我们对数据进行更直观的认识与把握,发现数据规律,洞察一些可能的趋势。
我们采用了bar来展示。

#openF.head(5)
#数据可视化,对数据有一个直观的认识
openF_charges=openF.groupby('charges').count()
openF_charges=openF_charges.reset_index()
openF_charges.head(2)

attr = ["{}".format(i*100)+str('%') for i in openF_charges['charges']]
#attr = [i for i in openF_charges['char
  • 0
    点赞
  • 265
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值