GVKun编程网logo

分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)(分析师用的软件)

3

本文的目的是介绍分析师常用工具二Python(numpy,scipy,pandas,matplotlib,seaborn包)的详细情况,特别关注分析师用的软件的相关信息。我们将通过专业的研究、有关数据

本文的目的是介绍分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)的详细情况,特别关注分析师用的软件的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)的机会,同时也不会遗漏关于Centos7安装python3、numpy、scipy、matplotlib、pandas等、matplotlib numpy scipy 的安装、Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack、numpy+pandas+matplotlib+tushare股票分析的知识。

本文目录一览:

分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)(分析师用的软件)

分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)(分析师用的软件)

一. Numpy

二. Scipy

三. Pandas

四. Matplotlib

五. Seaborn

Centos7安装python3、numpy、scipy、matplotlib、pandas等

Centos7安装python3、numpy、scipy、matplotlib、pandas等

centos 7 已经自带 python 2.7.15,这里需要安装 python 3

[root@pwm]# python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2

第一步:安装依赖包

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

 

第二步:下载python 3,这里下载 3.8.5

https://www.python.org/downloads/source/

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz

 

第三步:指定存放目录(/usr/local/python3就是python3的安装目录)

mkdir /usr/local/python3

 

第四步:解压压缩包,进入该目录

tar -xvJf  Python-3.8.5.tar.xz
cd Python-3.8.5
./configure --prefix=/usr/local/python3

(注:./configure --prefix=/usr/local/python3这句的作用就是将程序安装在/usr/local/python3这个目录下)

 

第五步:安装python3

make && make install

(注:make是编译,make install是安装)

 

第六步:创建软链接(将 /usr/bin/python3指向/usr/local/python3/bin/python3)

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

 

升级pip(如果需要)

按照提示升级pip,命令:pip3 install --upgrade pip

 

使用:

/usr/local/python3/bin/python3

 

 

2.安装其它(直接输入命令)

pip3 install numpy

pip3 install scipy

pip3 install matplotlib

pip3 install pandas

pip3 install statsmodels

pip3 install scikit-learn

pip3 install gensim

pip3 install theano

pip3 install keras

pip3 install tensorflow

 

 

REF

https://www.cnblogs.com/zhangtingzu/p/8650664.html

centos 7 已经自带 python 2.7.15,这里需要安装 python 3

[root@pwm]# python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2

第一步:安装依赖包

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

 

第二步:下载python 3,这里下载 3.8.5

https://www.python.org/downloads/source/

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz

 

第三步:指定存放目录(/usr/local/python3就是python3的安装目录)

mkdir /usr/local/python3

 

第四步:解压压缩包,进入该目录

tar -xvJf  Python-3.8.5.tar.xz
cd Python-3.8.5
./configure --prefix=/usr/local/python3

(注:./configure --prefix=/usr/local/python3这句的作用就是将程序安装在/usr/local/python3这个目录下)

 

第五步:安装python3

make && make install

(注:make是编译,make install是安装)

 

第六步:创建软链接(将 /usr/bin/python3指向/usr/local/python3/bin/python3)

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

 

升级pip(如果需要)

按照提示升级pip,命令:pip3 install --upgrade pip

 

使用:

/usr/local/python3/bin/python3

 

 

2.安装其它(直接输入命令)

pip3 install numpy

pip3 install scipy

pip3 install matplotlib

pip3 install pandas

pip3 install statsmodels

pip3 install scikit-learn

pip3 install gensim

pip3 install theano

pip3 install keras

pip3 install tensorflow

 

 

REF

https://www.cnblogs.com/zhangtingzu/p/8650664.html

matplotlib numpy scipy 的安装

matplotlib numpy scipy 的安装

 

 

一:windows 端的安装

#cmd指令
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

 成功安装所需库!

 

二、linux端安装--基于Ubuntu的操作

第一步:下载压缩包到指定位置

jiyongjia@ubuntu:~$ cd ~/Downloads/

jiyongjia@ubuntu:~/Downloads$ wget https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.4.3/matplotlib-1.4.3.tar.gz

 

第二步:解压下载的压缩包

jiyongjia@ubuntu:~/Downloads$ tar xzf matplotlib-1.4.3.tar.gz
jiyongjia@ubuntu:~/Downloads$ cd matplotlib-1.4.3/
jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ ls

第三步:进入文件夹进行编译

jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ python3 setup.py build

第四步:安装

jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ python3 setup.py install

 



Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

如何解决Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

我在matplotlib和scipy之间的交互方面遇到一些问题。 这是我对情况的理解:

  1. 错误在于LinearRegression的{​​{1}}抛出sklearn
  2. 经过一些调试后,SVD not converging error引发了错误,其中scipy\\linalg\\basic.py方法返回的信息值不同于dgesld(在这种情况下为0)。在我的情况下,使用的-4是fortran flatpack lapack_func
  3. 错误似乎取决于输入的数字和dgesldpyplot)代码,尤其是方法matplotlibyticks
  4. 该错误首先发生在多线性回归问题中(xticks中的信息值等于23,在这种情况下为正值),但我编写了以下脚本来更好地概述问题
  1. scipy\\linalg\\basic.py

在具有以下功能的Windows 10计算机上运行时:

  1. import numpy as np
  2. from sklearn.linear_model import LinearRegression
  3. import matplotlib.pyplot as plt
  4. a = [0.27236845,0.79433854,0.05986454,0.62736383,0.5732594,0.54175392,0.92359127,0.19913404,0.17357701,0.10225879,0.94727807,0.23766063,0.92438574,0.10981865,0.18669187,0.71337215,0.17843819,0.98693265,0.80787247,0.931572]
  5. b = [1.68869178,2.20448291,1.64828788,1.95276497,1.23976119,1.61260175,1.32652345,1.94535222,1.37353248,1.47830833,1.08400723,1.91091901,1.63909271,2.37494003,1.64490261,1.90403079,1.81028796,1.66986048,1.65304452,1.60747378]
  6. for no_plot in [True,False]:
  7. for i in range(len(a)-1):
  8. _a = a[:i + 2]
  9. _b = b[:i + 2]
  10. if not no_plot:
  11. bar_color = "blue"
  12. margin = 10
  13. y_label = x_label = None
  14. angle = 0
  15. title = "TestError"
  16. color_theme = (0 / 235,32 / 235,96 / 235)
  17. fig,ax = plt.subplots(figsize=(18,6.8))
  18. plt.bar(_a,_b,color=bar_color)
  19. Box = ax.get_position()
  20. ax.set_position([Box.x0,Box.y0 + margin * Box.height,Box.width,Box.height * (1 - margin)])
  21. plt.xticks(fontname="Cambria",color=color_theme,rotation=angle,fontsize=25)
  22. plt.yticks(fontname="Cambria",fontsize=25)
  23. plt.title(title,fontname="Cambria",fontsize=25)
  24. ax_output = plt.gca()
  25. try:
  26. reg = LinearRegression().fit(np.array(_a).reshape(-1,1),_b)
  27. print("Success: {},@ i={} with no_plot={}".format(reg.score(np.array(_a).reshape(-1,_b),i,no_plot))
  28. except Exception as e:
  29. print("Exception: {} @ i={} with no_plot={}".format(repr(e),no_plot))

python version: 3.7.9 scipy version: 1.5.2 scikit-learn version: 0.23.2 numpy version: 1.19.2 matplotlib version: 3.3.2

结果如下:

  1. _flapack.cp37-win_amd64

就堆栈跟踪而言:

  1. Success: 1.0,@ i=0 with no_plot=True
  2. Success: 0.9524690407545247,@ i=1 with no_plot=True
  3. Success: 0.9248909415334777,@ i=2 with no_plot=True
  4. Success: 0.17921330631542143,@ i=3 with no_plot=True
  5. Success: 0.1559357435898613,@ i=4 with no_plot=True
  6. Success: 0.001129573837944875,@ i=5 with no_plot=True
  7. Success: 0.008667658302087822,@ i=6 with no_plot=True
  8. Success: 0.001674117195053615,@ i=7 with no_plot=True
  9. Success: 0.011802146118754298,@ i=8 with no_plot=True
  10. Success: 0.024141340568111902,@ i=9 with no_plot=True
  11. Success: 0.04144995409093344,@ i=10 with no_plot=True
  12. Success: 0.03301917468171267,@ i=11 with no_plot=True
  13. Success: 0.0959782634092683,@ i=12 with no_plot=True
  14. Success: 0.08847483030078473,@ i=13 with no_plot=True
  15. Success: 0.06428117850391502,@ i=14 with no_plot=True
  16. Success: 0.07033033186821203,@ i=15 with no_plot=True
  17. Success: 0.06394158828230323,@ i=16 with no_plot=True
  18. Success: 0.0640239869160919,@ i=17 with no_plot=True
  19. Success: 0.06734590831873866,@ i=18 with no_plot=True
  20. Success: 1.0,@ i=0 with no_plot=False
  21. Success: 0.9524690407545247,@ i=1 with no_plot=False
  22. Success: 0.9248909415334777,@ i=2 with no_plot=False
  23. Success: 0.17921330631542143,@ i=3 with no_plot=False
  24. Success: 0.1559357435898613,@ i=4 with no_plot=False
  25. Success: 0.001129573837944875,@ i=5 with no_plot=False
  26. Success: 0.008667658302087822,@ i=6 with no_plot=False
  27. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=7 with no_plot=False
  28. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=8 with no_plot=False
  29. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=9 with no_plot=False<
  30. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=10 with no_plot=False
  31. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=11 with no_plot=False
  32. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=12 with no_plot=False
  33. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=13 with no_plot=False
  34. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=14 with no_plot=False
  35. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=15 with no_plot=False
  36. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=16 with no_plot=False
  37. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=17 with no_plot=False
  38. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=18 with no_plot=False

坦白说,我有点迷路了。有人对此事有想法吗?

numpy+pandas+matplotlib+tushare股票分析

numpy+pandas+matplotlib+tushare股票分析

一.数据导入

安装tushare模块包

pip install tushare

http://tushare.org/

tushare是一个财经数据接口包

import numpy as np
import matplotlib as plt
import pandas as pd
import tushare as ts

#获取股票号为601318的股票信息
df=ts.get_k_data("601318")

#将数据保存到本地,方便处理
df.to_csv("601318.csv",index=False)

#获取数据内的有用列,并将date列作为index
df = pd.read_csv("601318.csv",index_col="date")[["open","close","high","low","volume"]]

 

二.分析股票策略

使用双均线金叉点和死叉点

首先是添加5日均线点,和30日均线点

#获取5日均线,10日均线
df["ma5"]=np.nan
df["ma30"]=np.nan

# 方式一
# for i in range(4, len(df)):
#     df.loc[df.index[i], ''ma5''] = df[''close''][i-4:i+1].mean()

# for i in range(29, len(df)):
#     df.loc[df.index[i], ''ma30''] = df[''close''][i-29:i+1].mean()

# 方式二
df["ma5"]=df["close"].rolling(5).mean()
df["ma30"]=df["close"].rolling(30).mean()

三.查看数据图形

df[["close","ma5","ma30"]].plot()

 

 四.获取金叉和死叉点

# 获取金叉点,死叉点
golden_cross = []
death_cross = []

for i in range(1, len(df)):
    if df[''ma5''][i] >= df[''ma30''][i] and df[''ma5''][i-1] < df[''ma30''][i-1]:
        golden_cross.append(df.index[i])
    if df[''ma5''][i] < df[''ma30''][i] and df[''ma5''][i-1] >= df[''ma30''][i-1]:
        death_cross.append(df.index[i])

 

五.计算收益

first_money = 100000
money = first_money
hold = 0 # 持有的股票数

sr1 = pd.Series(1, index=golden_cross)
sr2 = pd.Series(0, index=death_cross)
sr = sr2.append(sr1).sort_index()

for i in range(0, len(sr)):
    p = df[''close''][sr.index[i]]
    if sr.iloc[i] == 1:
        #金叉
        buy = (money // p*100)
        hold += buy*100
        money -= buy*100*p
    else:
        money += hold*p
        hold = 0
        
p = df[''close''][-1]
now_money = hold*p + money

now_money - first_money

 

今天关于分析师常用工具二 Python(numpy, scipy, pandas, matplotlib, seaborn包)分析师用的软件的讲解已经结束,谢谢您的阅读,如果想了解更多关于Centos7安装python3、numpy、scipy、matplotlib、pandas等、matplotlib numpy scipy 的安装、Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack、numpy+pandas+matplotlib+tushare股票分析的相关知识,请在本站搜索。

本文标签: