python print 打印 % 百分号

记得以前困扰过自己的一个问题.
当时的解决方式是这样的:
 

a = 1
print "a values is ", a, "%"
 
把百分号切割开来.
 
后来才知道,正确显示百分号的方法:
 
 
print 'a values is %d%%' %a

 用2个百分号来标示.
 
 
 
继续阅读 »
记得以前困扰过自己的一个问题.
当时的解决方式是这样的:
 

a = 1
print "a values is ", a, "%"
 
把百分号切割开来.
 
后来才知道,正确显示百分号的方法:
 
 
print 'a values is %d%%' %a

 用2个百分号来标示.
 
 
  收起阅读 »

Python 学习笔记2.1 ——数据类型和结构

电脑配置:windows 64位
Python版本:3.6.0
 
学习内容: 量化分析师的Python日记【第1天:谁来给我讲讲Python?】 以下为转载加自己的笔记
         
一、容器
1,什么是容器

Python中有一种名为容器的数据结构,包括序列和字典,序列又包括列表、元组、字符串等
 
1.png

 
列表的基本形式比如:[1,3,6,10]或者[‘yes’,’no’,’OK’]

元组的基本形式比如:(1,3,6,10)或者(‘yes’,’no’,’OK’)

字符串的基本形式比如:’hello’
 
以上几种属于序列,序列中的每一个元素都被分配一个序号——即元素的位置,也称为“索引”,第一个索引,即第一个元素的位置是0,第二个是1,依次类推。列表和元组的区别主要在于,列表可以修改,而元组不能(注意列表用中括号而元组用括号)。
 
索引是从0开始的

2.png

 
2. 序列的一些通用操作

除了上面说到的索引,列表、元组、字符串等这些序列还有一些共同的操作。

(1)索引(补充上面)

序列的最后一个元素的索引,也可以是-1,倒数第二个也可以用-2,依次类推:

微信截图_20170908173242.png

 
(2)分片

使用分片操作来访问一定范围内的元素,它的格式为:

a[开始索引:结束索引:步长]

那么访问的是,从开始索引号的那个元素,到结束索引号-1的那个元素,每间隔步长个元素访问一次,步长可以忽略,默认步长为1。

微信截图_20170908173417.png

 
 
 
继续阅读 »
电脑配置:windows 64位
Python版本:3.6.0
 
学习内容: 量化分析师的Python日记【第1天:谁来给我讲讲Python?】 以下为转载加自己的笔记
         
一、容器
1,什么是容器

Python中有一种名为容器的数据结构,包括序列和字典,序列又包括列表、元组、字符串等
 
1.png

 
列表的基本形式比如:[1,3,6,10]或者[‘yes’,’no’,’OK’]

元组的基本形式比如:(1,3,6,10)或者(‘yes’,’no’,’OK’)

字符串的基本形式比如:’hello’
 
以上几种属于序列,序列中的每一个元素都被分配一个序号——即元素的位置,也称为“索引”,第一个索引,即第一个元素的位置是0,第二个是1,依次类推。列表和元组的区别主要在于,列表可以修改,而元组不能(注意列表用中括号而元组用括号)。
 
索引是从0开始的

2.png

 
2. 序列的一些通用操作

除了上面说到的索引,列表、元组、字符串等这些序列还有一些共同的操作。

(1)索引(补充上面)

序列的最后一个元素的索引,也可以是-1,倒数第二个也可以用-2,依次类推:

微信截图_20170908173242.png

 
(2)分片

使用分片操作来访问一定范围内的元素,它的格式为:

a[开始索引:结束索引:步长]

那么访问的是,从开始索引号的那个元素,到结束索引号-1的那个元素,每间隔步长个元素访问一次,步长可以忽略,默认步长为1。

微信截图_20170908173417.png

 
 
  收起阅读 »

Python 学习笔记1.2——第三方库安装

电脑配置:windows 64位
python版本:3.6.0
 
一、前往第三方网站下载所需要的包
 
http://www.lfd.uci.edu/~gohlke/pythonlibs/ 
 
二、使用pip安装
 
pip install xxx
5.png

 
继续阅读 »
电脑配置:windows 64位
python版本:3.6.0
 
一、前往第三方网站下载所需要的包
 
http://www.lfd.uci.edu/~gohlke/pythonlibs/ 
 
二、使用pip安装
 
pip install xxx
5.png

  收起阅读 »

Python 学习笔记 1.1——cmd操作

电脑配置:64位 windows
安装的python版本:3.6.0

一、目录切换

1、如果要访问D盘,先输入D:
 
1.png

2、如果要进入D盘里某一个文件夹,再输入cd Python(比如我要进入D盘下的Python文件夹)
  如果还要再往里 继续cd XXX 
  
2.png

3、返回上级目录 cd..

二、如何在cmd中使用复制粘贴 

  右键cmd窗口的标题栏,点击属性,勾选快速编辑模式,再确定 
 
4.png

 
  粘贴时,按 Alt space E P
  
       
继续阅读 »
电脑配置:64位 windows
安装的python版本:3.6.0

一、目录切换

1、如果要访问D盘,先输入D:
 
1.png

2、如果要进入D盘里某一个文件夹,再输入cd Python(比如我要进入D盘下的Python文件夹)
  如果还要再往里 继续cd XXX 
  
2.png

3、返回上级目录 cd..

二、如何在cmd中使用复制粘贴 

  右键cmd窗口的标题栏,点击属性,勾选快速编辑模式,再确定 
 
4.png

 
  粘贴时,按 Alt space E P
  
        收起阅读 »

python redis 笔记

刚接触redis,难免会有那么一些坑,新人一定会踩到的。 把自己的坑写出来,让以后新人少踩点吧。 
踩坑也不是什么坏事,不过浪费点时间而已。
 
1. 配置文件redis.config
 
如果你要远程访问你的redis服务器,那么里面有一行你一定要注释掉:

# bind 127.0.0.1
 
 
解释:

#  指定 redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
 
 
当时调了半天没连上去,就是被这个参数给害的。
 
2. redis-cli 连接本地redis服务器。 本地服务器端口已经改变。
开始使用redis-cli 127.0.0.1:8888 结果是一直都出错。
然后在某个配置文档看到测试本地端口,使用的命令是 redis-cli -p 8888
不然上面的永远都会连着6379.
 
待续。 不定期更新。 
 
 
 
 
 
 
 
 
 
继续阅读 »
刚接触redis,难免会有那么一些坑,新人一定会踩到的。 把自己的坑写出来,让以后新人少踩点吧。 
踩坑也不是什么坏事,不过浪费点时间而已。
 
1. 配置文件redis.config
 
如果你要远程访问你的redis服务器,那么里面有一行你一定要注释掉:

# bind 127.0.0.1
 
 
解释:

#  指定 redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
 
 
当时调了半天没连上去,就是被这个参数给害的。
 
2. redis-cli 连接本地redis服务器。 本地服务器端口已经改变。
开始使用redis-cli 127.0.0.1:8888 结果是一直都出错。
然后在某个配置文档看到测试本地端口,使用的命令是 redis-cli -p 8888
不然上面的永远都会连着6379.
 
待续。 不定期更新。 
 
 
 
 
 
 
 
 
  收起阅读 »

lxml.etree._ElementUnicodeResult 转为字符

在爬虫过程中,使用的是lxml的xpath查找对应的字段。
 

address=each.xpath('.//address/text()')[0].strip()
 
结果用address与一般的字符进行拼接时,总是出现
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
 
这种错误。
 
主要因为python2的蛋疼的编码原因。
 
解决办法:
根据lxml的官方文档:http://lxml.de/api/lxml.etree._ElementUnicodeResult-class.html
 

object --+ | basestring --+ | unicode --+ | _ElementUnicodeResult
 
_ElementUnicodeResult 是unicode的一个子类。
 
那么可以直接将它转为unicode
 
address.encode('utf-8') 就可以了。
 
继续阅读 »
在爬虫过程中,使用的是lxml的xpath查找对应的字段。
 

address=each.xpath('.//address/text()')[0].strip()
 
结果用address与一般的字符进行拼接时,总是出现
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
 
这种错误。
 
主要因为python2的蛋疼的编码原因。
 
解决办法:
根据lxml的官方文档:http://lxml.de/api/lxml.etree._ElementUnicodeResult-class.html
 

object --+ | basestring --+ | unicode --+ | _ElementUnicodeResult
 
_ElementUnicodeResult 是unicode的一个子类。
 
那么可以直接将它转为unicode
 
address.encode('utf-8') 就可以了。
  收起阅读 »

修改python的默认最大递归层数

python里面为了性能,默认的递归次数不能超过1000次。
 
运行下面的代码:
def recursion(n): 
if(n <= 0):
print n
return
print n
recursion(n - 1)

if __name__ == "__main__":
recursion(1200)

返回下面的错误:
 
  File "C:/Git/base_function/resursion_usage.py", line 7, in recursion
    recursion(n - 1)
RuntimeError: maximum recursion depth exceeded
 
解决办法: 修改python默认的递归层数。
在程序开头的地方添加以下语句:
 
import sys
sys.setrecursionlimit(1500)

然后再次运行,就不会有上面的错误信息了。
 
继续阅读 »
python里面为了性能,默认的递归次数不能超过1000次。
 
运行下面的代码:
def recursion(n): 
if(n <= 0):
print n
return
print n
recursion(n - 1)

if __name__ == "__main__":
recursion(1200)

返回下面的错误:
 
  File "C:/Git/base_function/resursion_usage.py", line 7, in recursion
    recursion(n - 1)
RuntimeError: maximum recursion depth exceeded
 
解决办法: 修改python默认的递归层数。
在程序开头的地方添加以下语句:
 
import sys
sys.setrecursionlimit(1500)

然后再次运行,就不会有上面的错误信息了。
  收起阅读 »

apt-get安装软件时 需要依赖更低版本的依赖库 通用解决办法

比如ubuntu尝试安装sqlite3,
xda@xda-dt:~$ sudo apt-get install sqlite3 libsqlite3-0=3.7.9-2ubuntu1.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsqlite3-0 is already the newest version.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
sqlite3 : Depends: libsqlite3-0 (= 3.7.9-2ubuntu1) but 3.7.9-2ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

会出现上面的问题。
 
方法1,使用aptitude 安装。
 
xda@xda-dt:~$ sudo aptitude install sqlite3
The following NEW packages will be installed:
sqlite3{b}
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.9 kB of archives. After unpacking 174 kB will be used.
The following packages have unmet dependencies:
sqlite3 : Depends: libsqlite3-0 (= 3.7.9-2ubuntu1) but 3.7.9-2ubuntu1.1 is installed.
The following actions will resolve these dependencies:

Keep the following packages at their current version:
1) sqlite3 [Not Installed]



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

Downgrade the following packages:
1) libsqlite3-0 [3.7.9-2ubuntu1.1 (now) -> 3.7.9-2ubuntu1 (precise)]



Accept this solution? [Y/n/q/?] Y
The following packages will be DOWNGRADED:
libsqlite3-0
The following NEW packages will be installed:
sqlite3
0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 375 kB of archives. After unpacking 174 kB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://hk.archive.ubuntu.com/ubuntu/ precise/main libsqlite3-0 amd64 3.7.9-2ubuntu1 [348 kB]
Get: 2 http://hk.archive.ubuntu.com/ubuntu/ precise/main sqlite3 amd64 3.7.9-2ubuntu1 [26.9 kB]
Fetched 375 kB in 1s (306 kB/s)
dpkg: warning: downgrading libsqlite3-0 from 3.7.9-2ubuntu1.1 to 3.7.9-2ubuntu1.
(Reading database ... 162912 files and directories currently installed.)
Preparing to replace libsqlite3-0 3.7.9-2ubuntu1.1 (using .../libsqlite3-0_3.7.9-2ubuntu1_amd64.deb) ...
Unpacking replacement libsqlite3-0 ...
Selecting previously unselected package sqlite3.
Unpacking sqlite3 (from .../sqlite3_3.7.9-2ubuntu1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libsqlite3-0 (3.7.9-2ubuntu1) ...
Setting up sqlite3 (3.7.9-2ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

xda@xda-dt:~$ sqlite3
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .exit

 
继续阅读 »
比如ubuntu尝试安装sqlite3,
xda@xda-dt:~$ sudo apt-get install sqlite3 libsqlite3-0=3.7.9-2ubuntu1.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsqlite3-0 is already the newest version.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
sqlite3 : Depends: libsqlite3-0 (= 3.7.9-2ubuntu1) but 3.7.9-2ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

会出现上面的问题。
 
方法1,使用aptitude 安装。
 
xda@xda-dt:~$ sudo aptitude install sqlite3
The following NEW packages will be installed:
sqlite3{b}
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.9 kB of archives. After unpacking 174 kB will be used.
The following packages have unmet dependencies:
sqlite3 : Depends: libsqlite3-0 (= 3.7.9-2ubuntu1) but 3.7.9-2ubuntu1.1 is installed.
The following actions will resolve these dependencies:

Keep the following packages at their current version:
1) sqlite3 [Not Installed]



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

Downgrade the following packages:
1) libsqlite3-0 [3.7.9-2ubuntu1.1 (now) -> 3.7.9-2ubuntu1 (precise)]



Accept this solution? [Y/n/q/?] Y
The following packages will be DOWNGRADED:
libsqlite3-0
The following NEW packages will be installed:
sqlite3
0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 375 kB of archives. After unpacking 174 kB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://hk.archive.ubuntu.com/ubuntu/ precise/main libsqlite3-0 amd64 3.7.9-2ubuntu1 [348 kB]
Get: 2 http://hk.archive.ubuntu.com/ubuntu/ precise/main sqlite3 amd64 3.7.9-2ubuntu1 [26.9 kB]
Fetched 375 kB in 1s (306 kB/s)
dpkg: warning: downgrading libsqlite3-0 from 3.7.9-2ubuntu1.1 to 3.7.9-2ubuntu1.
(Reading database ... 162912 files and directories currently installed.)
Preparing to replace libsqlite3-0 3.7.9-2ubuntu1.1 (using .../libsqlite3-0_3.7.9-2ubuntu1_amd64.deb) ...
Unpacking replacement libsqlite3-0 ...
Selecting previously unselected package sqlite3.
Unpacking sqlite3 (from .../sqlite3_3.7.9-2ubuntu1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libsqlite3-0 (3.7.9-2ubuntu1) ...
Setting up sqlite3 (3.7.9-2ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

xda@xda-dt:~$ sqlite3
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .exit

  收起阅读 »

编译cmake到更新的版本 【ubuntu】

ubuntu12.04 的cmake版本是2.8.7, 在一些QT程序下,需要较高的cmake版本。
如果只是使用命令: 
sudo apt-get install cmake 或者sudo apt-get upgrade cmake 
获取到的版本还是2.8.7
 
正确的做法:

cd ~/Downloads/ 
wget http://www.cmake.org/files/v2. ... ar.gz 
tar xzvf cmake-2.8.10.tar.gz 
cd cmake-2.8.10 
./configure 
make -j4 
sudo make install
 
 
关闭命令行后重新开一个命令行,然后运行 cmake --version, 就可以看到你的cmake已经更新到你要的版本。
继续阅读 »
ubuntu12.04 的cmake版本是2.8.7, 在一些QT程序下,需要较高的cmake版本。
如果只是使用命令: 
sudo apt-get install cmake 或者sudo apt-get upgrade cmake 
获取到的版本还是2.8.7
 
正确的做法:

cd ~/Downloads/ 
wget http://www.cmake.org/files/v2. ... ar.gz 
tar xzvf cmake-2.8.10.tar.gz 
cd cmake-2.8.10 
./configure 
make -j4 
sudo make install
 
 
关闭命令行后重新开一个命令行,然后运行 cmake --version, 就可以看到你的cmake已经更新到你要的版本。 收起阅读 »

斐讯路由器强制推送广告

开始以为是个别网站弹窗,都是些今日头条的app之类的app应用推广。
后面方法,居然在我这个网站上都出现,于是上网一搜。 果然发现斐讯被扒的文章。
http://www.right.com.cn/forum/thread-227504-1-1.html
 
 
继续阅读 »
开始以为是个别网站弹窗,都是些今日头条的app之类的app应用推广。
后面方法,居然在我这个网站上都出现,于是上网一搜。 果然发现斐讯被扒的文章。
http://www.right.com.cn/forum/thread-227504-1-1.html
 
  收起阅读 »

在uefi主板上安装ubuntu,grub一直无法写入

主板是技嘉P61的板子,是一块uefi的主板。
因为要安装ubuntu,所以使用ultraISO烧录的启动u盘,然后u盘启动。 
重启后,顺利进入安装界面,一路下去后。 最后卡在 grub安装出错的界面处。
 
因为用的是最新的ubuntu16.04,所以开始以为是系统兼容性问题,所以就降级到12.04。 用ultraISO重新烧录可启动U盘。
 
结果问题依然存在,所以排除系统问题,因为以前在其他机子上装过很多次12.04了。
 
于是到ubuntu官网上搜了一下,发现这个很多人遇到问题。
 
解决方案无非有2个,一个是禁用uefi模式,一个是创建efi分区。
 
然后自己自己折腾自己的bios设置。 技嘉的板子没有直接禁用uefi的选项,百度之。 原来一部分主板bios的uefi的设置选项,是CSM, 这个选项默认是开启的了,然后把个功能关闭, 然后重新安装,问题还是出现。
 
而此之后,启动设备的优先级里面,一直会出现一个ubuntu的选项。 
重置bios设置,这个选项会一直都在。 
 
然后无解,只能用第二种方法。 启动uefi,在安装ubuntu过程中,分区选项里面,选择手工分区,分了以下分区:
/
/boot
/home
swap
/efi  (一定要这个分区)
 
划分上面分区,系统不再出现grub安装失败的错误。 可是,系统重启后,系统就会挂掉,很不稳定。
 
后来重试了几次,没办法,重试第一次的方法。 这一次,我把主板的电池扣掉,放电几分钟。 然后进bios,重新禁用CSM, 重装。 使用默认的分区方法, 然后重要成功了。
 
 
继续阅读 »
主板是技嘉P61的板子,是一块uefi的主板。
因为要安装ubuntu,所以使用ultraISO烧录的启动u盘,然后u盘启动。 
重启后,顺利进入安装界面,一路下去后。 最后卡在 grub安装出错的界面处。
 
因为用的是最新的ubuntu16.04,所以开始以为是系统兼容性问题,所以就降级到12.04。 用ultraISO重新烧录可启动U盘。
 
结果问题依然存在,所以排除系统问题,因为以前在其他机子上装过很多次12.04了。
 
于是到ubuntu官网上搜了一下,发现这个很多人遇到问题。
 
解决方案无非有2个,一个是禁用uefi模式,一个是创建efi分区。
 
然后自己自己折腾自己的bios设置。 技嘉的板子没有直接禁用uefi的选项,百度之。 原来一部分主板bios的uefi的设置选项,是CSM, 这个选项默认是开启的了,然后把个功能关闭, 然后重新安装,问题还是出现。
 
而此之后,启动设备的优先级里面,一直会出现一个ubuntu的选项。 
重置bios设置,这个选项会一直都在。 
 
然后无解,只能用第二种方法。 启动uefi,在安装ubuntu过程中,分区选项里面,选择手工分区,分了以下分区:
/
/boot
/home
swap
/efi  (一定要这个分区)
 
划分上面分区,系统不再出现grub安装失败的错误。 可是,系统重启后,系统就会挂掉,很不稳定。
 
后来重试了几次,没办法,重试第一次的方法。 这一次,我把主板的电池扣掉,放电几分钟。 然后进bios,重新禁用CSM, 重装。 使用默认的分区方法, 然后重要成功了。
 
  收起阅读 »

树莓派上安装redis-server 亲测

采用的方法为到官网下载源码,然后在树莓派上编译。
 
1. 下载源码压缩包:
官方网址: https://redis.io/download
下载下来的格式为tar.gz
通过命令行解压: tar xvfz xxxxxx.tar.gz
 
2. 解压后进入 redis-4.0.0的目录,然后执行命令: make
 
3. 等待源码编译(树莓派上有点久), 见到这一行:Hint: It's a good idea to run 'make test' ;)
说明你安装成功了
 
4. 编译成功后, 记得运行命令 sudo src/redis-server
来启动redis server。
 
成功运行后的文字界面:
12718:C 17 Jul 23:09:24.447 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

12718:C 17 Jul 23:09:24.448 # Redis version=4.0.0, bits=64, commit=00000000, modified=0, pid=12718, just started

12718:C 17 Jul 23:09:24.448 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf

12718:M 17 Jul 23:09:24.450 * Increased maximum number of open files to 10032 (it was originally set to 256).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 4.0.0 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 12718

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               




12718:M 17 Jul 23:09:24.451 # Server initialized

12718:M 17 Jul 23:09:24.451 * Ready to accept connections
继续阅读 »
采用的方法为到官网下载源码,然后在树莓派上编译。
 
1. 下载源码压缩包:
官方网址: https://redis.io/download
下载下来的格式为tar.gz
通过命令行解压: tar xvfz xxxxxx.tar.gz
 
2. 解压后进入 redis-4.0.0的目录,然后执行命令: make
 
3. 等待源码编译(树莓派上有点久), 见到这一行:Hint: It's a good idea to run 'make test' ;)
说明你安装成功了
 
4. 编译成功后, 记得运行命令 sudo src/redis-server
来启动redis server。
 
成功运行后的文字界面:
12718:C 17 Jul 23:09:24.447 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

12718:C 17 Jul 23:09:24.448 # Redis version=4.0.0, bits=64, commit=00000000, modified=0, pid=12718, just started

12718:C 17 Jul 23:09:24.448 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf

12718:M 17 Jul 23:09:24.450 * Increased maximum number of open files to 10032 (it was originally set to 256).

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 4.0.0 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 12718

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               




12718:M 17 Jul 23:09:24.451 # Server initialized

12718:M 17 Jul 23:09:24.451 * Ready to accept connections 收起阅读 »

python matplotlib 中的plot legend的用法

官方有链接说明:https://matplotlib.org/users/legend_guide.html
不过对于大部分人来说,英文教程,加上上面的例子有点晦涩。
 
所以以个人的理解,简单地用代码介绍下。
    import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
print x
fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
#ax.plot(x, i * x, label='y=%dx' %i)
ax.plot(x, i * x, label='$y = %ix$' % i)

ax.legend()

plt.show()

 
运行上面的代码后,得到的结果是:
 

legend.PNG

 
如果把那句legend() 的语句去掉,那么图形上的图例也就会消失了。
 
所以legend()的主要只用就是用于在图上标明一个图例,用于说明每条曲线的文字显示。 你也可以把图例控制在左边,右边,底下等等。
 
 
实际使用中,legend()有一个loc参数,用于控制图例的位置。 比如 plot.legend(loc=2) , 这个位置就是4象项中的第二象项,也就是左上角。 loc可以为1,2,3,4 这四个数字。
原文连接:
http://30daydo.com/article/215
转载请注明出处
继续阅读 »
官方有链接说明:https://matplotlib.org/users/legend_guide.html
不过对于大部分人来说,英文教程,加上上面的例子有点晦涩。
 
所以以个人的理解,简单地用代码介绍下。
    import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
print x
fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
#ax.plot(x, i * x, label='y=%dx' %i)
ax.plot(x, i * x, label='$y = %ix$' % i)

ax.legend()

plt.show()

 
运行上面的代码后,得到的结果是:
 

legend.PNG

 
如果把那句legend() 的语句去掉,那么图形上的图例也就会消失了。
 
所以legend()的主要只用就是用于在图上标明一个图例,用于说明每条曲线的文字显示。 你也可以把图例控制在左边,右边,底下等等。
 
 
实际使用中,legend()有一个loc参数,用于控制图例的位置。 比如 plot.legend(loc=2) , 这个位置就是4象项中的第二象项,也就是左上角。 loc可以为1,2,3,4 这四个数字。
原文连接:
http://30daydo.com/article/215
转载请注明出处 收起阅读 »

为什么使用dataframe自带的plot函数绘图 没有输出图像?

比如:
    df=pd.read_csv('LoanStats_2017Q1.csv',header=0)
print df.head(10)
print df.describe()

analysis_columns = ['issue_d','term','int_rate','emp_title','grade','home_ownership','verification_status','purpose','loan_amnt','total_pymnt','out_prncp','total_rec_int','total_rec_prncp','installment','annual_inc','dti','fico_range_low','fico_range_high','last_fico_range_low','last_fico_range_high','open_acc','loan_status','delinq_amnt','acc_now_delinq','tot_coll_amt']
deal_data = df.loc[:,analysis_columns]
print deal_data
deal_data.groupby('issue_d').agg({'loan_amnt':'sum'}).plot(kind="bar")
deal_data.groupby('issue_d').agg({'issue_d':'count'}).plot(kind = 'bar')

在pycharm中程序运行完了就直接退出,没有输出任何的图像。
 
然后看了下源码后,需要在后面手工添加一句 plt.show()
 
这样就能够正常显示图像了。
继续阅读 »
比如:
    df=pd.read_csv('LoanStats_2017Q1.csv',header=0)
print df.head(10)
print df.describe()

analysis_columns = ['issue_d','term','int_rate','emp_title','grade','home_ownership','verification_status','purpose','loan_amnt','total_pymnt','out_prncp','total_rec_int','total_rec_prncp','installment','annual_inc','dti','fico_range_low','fico_range_high','last_fico_range_low','last_fico_range_high','open_acc','loan_status','delinq_amnt','acc_now_delinq','tot_coll_amt']
deal_data = df.loc[:,analysis_columns]
print deal_data
deal_data.groupby('issue_d').agg({'loan_amnt':'sum'}).plot(kind="bar")
deal_data.groupby('issue_d').agg({'issue_d':'count'}).plot(kind = 'bar')

在pycharm中程序运行完了就直接退出,没有输出任何的图像。
 
然后看了下源码后,需要在后面手工添加一句 plt.show()
 
这样就能够正常显示图像了。 收起阅读 »

numpy/dataframe 中cumsum 的用法

用途:cumsum                 样本值的累计和
 
例子:
 
    x=np.arange(101)
y=x.cumsum()
print y
print len(y)

x为一个0到100的array, 那么对这个array进行cumsum操作后
y现在的值为:
 
[   0    1    3    6   10   15   21   28   36   45   55   66   78   91  105
120 136 153 171 190 210 231 253 276 300 325 351 378 406 435
465 496 528 561 595 630 666 703 741 780 820 861 903 946 990
1035 1081 1128 1176 1225 1275 1326 1378 1431 1485 1540 1596 1653 1711 1770
1830 1891 1953 2016 2080 2145 2211 2278 2346 2415 2485 2556 2628 2701 2775
2850 2926 3003 3081 3160 3240 3321 3403 3486 3570 3655 3741 3828 3916 4005
4095 4186 4278 4371 4465 4560 4656 4753 4851 4950 5050]

 
从结果很明显看到 cumsum是将样本逐渐累加,第一个是0,第二个是0+1,第三个是0+1+2,所以第三个是3,第4个是0+1+2+3=6,如此类推,最后一个就是这101个数的累加和,5050
 
 
继续阅读 »
用途:cumsum                 样本值的累计和
 
例子:
 
    x=np.arange(101)
y=x.cumsum()
print y
print len(y)

x为一个0到100的array, 那么对这个array进行cumsum操作后
y现在的值为:
 
[   0    1    3    6   10   15   21   28   36   45   55   66   78   91  105
120 136 153 171 190 210 231 253 276 300 325 351 378 406 435
465 496 528 561 595 630 666 703 741 780 820 861 903 946 990
1035 1081 1128 1176 1225 1275 1326 1378 1431 1485 1540 1596 1653 1711 1770
1830 1891 1953 2016 2080 2145 2211 2278 2346 2415 2485 2556 2628 2701 2775
2850 2926 3003 3081 3160 3240 3321 3403 3486 3570 3655 3741 3828 3916 4005
4095 4186 4278 4371 4465 4560 4656 4753 4851 4950 5050]

 
从结果很明显看到 cumsum是将样本逐渐累加,第一个是0,第二个是0+1,第三个是0+1+2,所以第三个是3,第4个是0+1+2+3=6,如此类推,最后一个就是这101个数的累加和,5050
 
  收起阅读 »

有道云笔记注销了某台设备后无法在该设备登录

自己有多台安卓设备,都在上面登录过有道云笔记,因为有时会借给其他人,所以使用了有道云笔记网页版上的设备管理的功能,选择注销安卓设备A,并远程删除数据。
 
然后拿回设备后,准备重新登录有道云笔记,结果界面一直在删除数据,接着重新登录后,会一直弹出一个信息,远程注销了给设备,需要重新登录。
 
最后折腾了一番后,直接把有道云笔记卸载掉,然后重新安装,重新登录,结果问题就解决了。
继续阅读 »
自己有多台安卓设备,都在上面登录过有道云笔记,因为有时会借给其他人,所以使用了有道云笔记网页版上的设备管理的功能,选择注销安卓设备A,并远程删除数据。
 
然后拿回设备后,准备重新登录有道云笔记,结果界面一直在删除数据,接着重新登录后,会一直弹出一个信息,远程注销了给设备,需要重新登录。
 
最后折腾了一番后,直接把有道云笔记卸载掉,然后重新安装,重新登录,结果问题就解决了。 收起阅读 »

python uiautomator 安卓自动化测试

本教程使用的是win7 系统 - python 2.7
1. 安装uiautomator 同
pip install uiautomator

 时确保你的手机连上电脑后,adb可以正常使用, 在命令行运行adb devices,能够有设备的id输出

2. 获取手机的基本信息:
导入uiautomator包: 

from uiautomator import device as d

这样子就可以使用d操作手机,获取手机信息。
info= d.info
print info
print type(info)
for i in info:
print i,info[i]

输出的内容:
 
{u'displayRotation': 0, u'displaySizeDpY': 640, u'displaySizeDpX': 360, u'screenOn': False, u'currentPackageName': u'com.smartisanos.keyguard', u'productName': u'icesky_msm8992', u'displayWidth': 1080, u'sdkInt': 22, u'displayHeight': 1920, u'naturalOrientation': True}
<type 'dict'>
displayRotation 0
displaySizeDpY 640
displaySizeDpX 360
screenOn False
currentPackageName com.smartisanos.keyguard
productName icesky_msm8992
displayWidth 1080
sdkInt 22
displayHeight 1920
naturalOrientation True


手机的分辨率
displayWidth 1080
displayHeight 1920

当前打开的包名: currentPackageName com.smartisanos.keyguard
 
3.
d.press.home()
result=d(text=u'设置').wait.exists(timeout=10000)
#单位是毫秒, 如果timeout还没有找到,就返回false
print "next"
if result:
print "You press setting"
else:
print "You don't touch any thing"


打开home主界面,然后查看时候有设置这个选项或者图标文字。
d(text=u'设置').wait.exists(timeout=10000)

如果在10s内找到这个字符,那么这一行就返回True, 否则返回False
 
 
继续阅读 »
本教程使用的是win7 系统 - python 2.7
1. 安装uiautomator 同
pip install uiautomator

 时确保你的手机连上电脑后,adb可以正常使用, 在命令行运行adb devices,能够有设备的id输出

2. 获取手机的基本信息:
导入uiautomator包: 

from uiautomator import device as d

这样子就可以使用d操作手机,获取手机信息。
info= d.info
print info
print type(info)
for i in info:
print i,info[i]

输出的内容:
 
{u'displayRotation': 0, u'displaySizeDpY': 640, u'displaySizeDpX': 360, u'screenOn': False, u'currentPackageName': u'com.smartisanos.keyguard', u'productName': u'icesky_msm8992', u'displayWidth': 1080, u'sdkInt': 22, u'displayHeight': 1920, u'naturalOrientation': True}
<type 'dict'>
displayRotation 0
displaySizeDpY 640
displaySizeDpX 360
screenOn False
currentPackageName com.smartisanos.keyguard
productName icesky_msm8992
displayWidth 1080
sdkInt 22
displayHeight 1920
naturalOrientation True


手机的分辨率
displayWidth 1080
displayHeight 1920

当前打开的包名: currentPackageName com.smartisanos.keyguard
 
3.
d.press.home()
result=d(text=u'设置').wait.exists(timeout=10000)
#单位是毫秒, 如果timeout还没有找到,就返回false
print "next"
if result:
print "You press setting"
else:
print "You don't touch any thing"


打开home主界面,然后查看时候有设置这个选项或者图标文字。
d(text=u'设置').wait.exists(timeout=10000)

如果在10s内找到这个字符,那么这一行就返回True, 否则返回False
 
  收起阅读 »

为什么 2017 年 6 月 京东很多显卡断货

原来如此!!!! 
 
 以太坊一个月内4倍,现在显卡挖以太坊,3个月以内回本。还有做什么生意比这好的吗?各路资本都涌入了,显卡自然涨价。

显卡芯片生产速度完全跟不上显卡需求增长速度,A卡更是难买。

挖以太坊优先考虑RX470、RX480、RX570、RX580,A卡买不到才用N卡。

N卡挖以太坊用GTX1060和GTX1070,GTX1050、GTX1050Ti、GTX1080、GTX1080Ti挖以太坊效率太低,不适合用。

不仅显卡涨价了,连四川水电都涨价了。以前四川有很多矿场用水电站直供电,用电价格0.2元多一点,现在四川水电价格都涨起来了。新建矿场都去新疆和云南了。

也不能说显卡完全断货,只要愿意出价高,还是能买到。


链接:https://www.zhihu.com/question ... 47044
来源:知乎

 
继续阅读 »
原来如此!!!! 
 
 以太坊一个月内4倍,现在显卡挖以太坊,3个月以内回本。还有做什么生意比这好的吗?各路资本都涌入了,显卡自然涨价。

显卡芯片生产速度完全跟不上显卡需求增长速度,A卡更是难买。

挖以太坊优先考虑RX470、RX480、RX570、RX580,A卡买不到才用N卡。

N卡挖以太坊用GTX1060和GTX1070,GTX1050、GTX1050Ti、GTX1080、GTX1080Ti挖以太坊效率太低,不适合用。

不仅显卡涨价了,连四川水电都涨价了。以前四川有很多矿场用水电站直供电,用电价格0.2元多一点,现在四川水电价格都涨起来了。新建矿场都去新疆和云南了。

也不能说显卡完全断货,只要愿意出价高,还是能买到。


链接:https://www.zhihu.com/question ... 47044
来源:知乎

  收起阅读 »

dataframe读取excel文件第一行是列名如何跳过

比如数据如下:
 
股票代码	股票简称	涨跌幅(%)	现价(元)	收盘价:前复权(元)	区间涨跌幅:前复权(%)	交易状态
2016.07.13 2016.07.13 2016.07.13
300501.SZ 海顺新材 10.00 144.65 131.50 3.06 交易
300384.SZ 三联虹普 -0.67 57.63 58.02 5.97 交易
300506.SZ 名家汇 5.98 60.98 57.54 5.52 交易
002572.SZ 索菲亚 1.03 56.80 56.22 -0.65 交易
600419.SH 天润乳业 4.66 57.10 54.56 0.06 交易
300494.SZ 盛天网络 4.86 54.19 51.68 2.64 交易
300369.SZ 绿盟科技 2.36 45.50 44.45 -0.96 交易
002113.SZ 天润数娱 -1.89 43.55 44.39 7.14 交易
002190.SZ 成飞集成 10.01 47.17 42.88 10.01 交易
600391.SH 成发科技 3.39 43.56 42.13 1.54 交易
002699.SZ 美盛文化 3.25 40.99 39.70 9.97 交易
603027.SH 千禾味业 3.70 40.39 38.95 -1.77 交易
600893.SH 中航动力 2.03 39.29 38.51 0.44 交易
603005.SH 晶方科技 4.34 40.16 38.49 2.89 交易
300339.SZ 润和软件 2.50 36.98 36.08 1.32 交易
300246.SZ 宝莱特 3.92 37.42 36.01 -0.91 交易
002368.SZ 太极股份 4.23 37.50 35.98 1.75 交易
000555.SZ 神州信息 0.35 34.66 34.54 -0.75 交易
002745.SZ 木林森 9.15 37.10 33.99 -0.23 交易
002589.SZ 瑞康医药 -1.49 33.00 33.50 4.82 交易
002007.SZ 华兰生物 3.31 33.36 32.29 -0.89 交易
002456.SZ 欧菲光 0.32 31.60 31.50 7.88 交易
002759.SZ 天际股份 9.99 34.01 30.92 0.00 重大事项,停牌自2016-07-12起连续停牌


那么怎样不把第一行的数据读入呢? 或者说把第一行的数据给忽略掉呢?
 
sheet1 = pd.read_excel('test.xls', header=0, skiprows=[0] )
 
 
原文链接:http://30daydo.com/article/209
欢迎转载,转载请注明出处。
继续阅读 »
比如数据如下:
 
股票代码	股票简称	涨跌幅(%)	现价(元)	收盘价:前复权(元)	区间涨跌幅:前复权(%)	交易状态
2016.07.13 2016.07.13 2016.07.13
300501.SZ 海顺新材 10.00 144.65 131.50 3.06 交易
300384.SZ 三联虹普 -0.67 57.63 58.02 5.97 交易
300506.SZ 名家汇 5.98 60.98 57.54 5.52 交易
002572.SZ 索菲亚 1.03 56.80 56.22 -0.65 交易
600419.SH 天润乳业 4.66 57.10 54.56 0.06 交易
300494.SZ 盛天网络 4.86 54.19 51.68 2.64 交易
300369.SZ 绿盟科技 2.36 45.50 44.45 -0.96 交易
002113.SZ 天润数娱 -1.89 43.55 44.39 7.14 交易
002190.SZ 成飞集成 10.01 47.17 42.88 10.01 交易
600391.SH 成发科技 3.39 43.56 42.13 1.54 交易
002699.SZ 美盛文化 3.25 40.99 39.70 9.97 交易
603027.SH 千禾味业 3.70 40.39 38.95 -1.77 交易
600893.SH 中航动力 2.03 39.29 38.51 0.44 交易
603005.SH 晶方科技 4.34 40.16 38.49 2.89 交易
300339.SZ 润和软件 2.50 36.98 36.08 1.32 交易
300246.SZ 宝莱特 3.92 37.42 36.01 -0.91 交易
002368.SZ 太极股份 4.23 37.50 35.98 1.75 交易
000555.SZ 神州信息 0.35 34.66 34.54 -0.75 交易
002745.SZ 木林森 9.15 37.10 33.99 -0.23 交易
002589.SZ 瑞康医药 -1.49 33.00 33.50 4.82 交易
002007.SZ 华兰生物 3.31 33.36 32.29 -0.89 交易
002456.SZ 欧菲光 0.32 31.60 31.50 7.88 交易
002759.SZ 天际股份 9.99 34.01 30.92 0.00 重大事项,停牌自2016-07-12起连续停牌


那么怎样不把第一行的数据读入呢? 或者说把第一行的数据给忽略掉呢?
 
sheet1 = pd.read_excel('test.xls', header=0, skiprows=[0] )
 
 
原文链接:http://30daydo.com/article/209
欢迎转载,转载请注明出处。 收起阅读 »

pycharm当前使用的换行是windows模式还是mac OSX模式 ?

pycharm是一款很好用的python IDE软件。 在编写代码的时候怎样确定自己用的是windows的换行模式还是Mac OSX 或者Linux下的换行模式呢?
 
在pycharm的右下角,有一个状态栏,上面显示

换行.PNG

 
如果显示的是: CRLF,说明当前文档用的是windows的换行,占用的是2个字符 \n\r
 
而对于Mac OSX 系统,显示的则是CR, 换行则是 \r
 
而Linux下的换行,显示的是LR, 字符为\n
继续阅读 »
pycharm是一款很好用的python IDE软件。 在编写代码的时候怎样确定自己用的是windows的换行模式还是Mac OSX 或者Linux下的换行模式呢?
 
在pycharm的右下角,有一个状态栏,上面显示

换行.PNG

 
如果显示的是: CRLF,说明当前文档用的是windows的换行,占用的是2个字符 \n\r
 
而对于Mac OSX 系统,显示的则是CR, 换行则是 \r
 
而Linux下的换行,显示的是LR, 字符为\n 收起阅读 »

30天获取证券从业资格证和基金从业资格证


考试.jpg

 
 证券从业资格考试

证券从业资格考试-1.png





基金从业资格考试


基金考试-1.png







这两门都是从业考试,所以难度不会太大。只要你能够大概把书翻一遍,或者看网上的视频教程,然后刷下题库,正常来说,通过是没问题的。 




通过率.PNG





(网上说基金从业的基础知识通过率才30%都不到。这也让我觉得不可思议,怀疑不少人是去裸考的吧)




这里只是想跟大家分享一下30天内让自己完成一个时间的一个心理过程和行为过程。




首先要强迫自己去做,那么就让自己投入一些沉没成本。




报考证券从业资格和基金从业资格这两门考试,每一门需要120块的考试费用,考试费用交了后,无论你去不去考试钱都没得退回来。 因为前期投入了金钱,后期心里就不甘心让自己钱打水漂了,学习的动力会更加充足。 




对于能够见得着的金钱成本,很多人都很精明,能够看得到,且能够量化到具体数额。 




可是,平时我们投入的时间成本,有多少人能够精确的量化出来?  计划了3个月内学会一门语言,制定了相应的学习计划,然后执行了3周后, 因为各种原因,比如公司年会准备,周末team building等,让你的学习计划中断了。 而后,因为年会或者team building之后身体太累,你就把学习新语言的计划往后挪。就是因为这一挪,破坏了你的计划的连贯性,而且,有了第一次,肯定就会有第二次,第三次。 最后很可能的结果就是没能在3个月完成你学会一门新语言的计划。

在这里,你能够算出你因为前期投入的时间,而沉没的成本吗? 




所以,换一本漂亮昂贵的日记本,买一套好的运动服,你坚持写日记,跑步的动力就会比随意拿个本子或穿件山寨耐克要充足好多。 




当然,上面是对那些本来计划容易被随意打断的人而言。 对于那些自律成魔的人, 或者兴趣爱好所致,一般不需要像上面说的那样强制自己投入大量沉没成本。 
继续阅读 »

考试.jpg

 
 证券从业资格考试

证券从业资格考试-1.png





基金从业资格考试


基金考试-1.png







这两门都是从业考试,所以难度不会太大。只要你能够大概把书翻一遍,或者看网上的视频教程,然后刷下题库,正常来说,通过是没问题的。 




通过率.PNG





(网上说基金从业的基础知识通过率才30%都不到。这也让我觉得不可思议,怀疑不少人是去裸考的吧)




这里只是想跟大家分享一下30天内让自己完成一个时间的一个心理过程和行为过程。




首先要强迫自己去做,那么就让自己投入一些沉没成本。




报考证券从业资格和基金从业资格这两门考试,每一门需要120块的考试费用,考试费用交了后,无论你去不去考试钱都没得退回来。 因为前期投入了金钱,后期心里就不甘心让自己钱打水漂了,学习的动力会更加充足。 




对于能够见得着的金钱成本,很多人都很精明,能够看得到,且能够量化到具体数额。 




可是,平时我们投入的时间成本,有多少人能够精确的量化出来?  计划了3个月内学会一门语言,制定了相应的学习计划,然后执行了3周后, 因为各种原因,比如公司年会准备,周末team building等,让你的学习计划中断了。 而后,因为年会或者team building之后身体太累,你就把学习新语言的计划往后挪。就是因为这一挪,破坏了你的计划的连贯性,而且,有了第一次,肯定就会有第二次,第三次。 最后很可能的结果就是没能在3个月完成你学会一门新语言的计划。

在这里,你能够算出你因为前期投入的时间,而沉没的成本吗? 




所以,换一本漂亮昂贵的日记本,买一套好的运动服,你坚持写日记,跑步的动力就会比随意拿个本子或穿件山寨耐克要充足好多。 




当然,上面是对那些本来计划容易被随意打断的人而言。 对于那些自律成魔的人, 或者兴趣爱好所致,一般不需要像上面说的那样强制自己投入大量沉没成本。  收起阅读 »

比特币居然在25号那天突破过30000!


比特币.PNG

今天拉了下K线,才发现比特币居然还突破到30000大关。 当时只记得比特币突破了20000大关。没想到中间价格还到过30000,不知道被吊在30000的那个山顶上的朋友是怎么一个凉飕飕的感受。

比特币.PNG

今天拉了下K线,才发现比特币居然还突破到30000大关。 当时只记得比特币突破了20000大关。没想到中间价格还到过30000,不知道被吊在30000的那个山顶上的朋友是怎么一个凉飕飕的感受。

监控聚币网行情 并实时发送到微信

最近由于好友推荐我入坑了国内的山寨币,所以顺便研究了下聚币网的API。 不过网页版的聚币网和手机版的做的不好,而且因为是7x24 小时交易,自己没有那么多的精力盯盘,所以写了python代码进行监控。

Screenshot_2017-05-29-23-02-13-420_微信_副本_副本.png
# -*-coding=utf-8-*-
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: weigesysu@qq.com
'''
import random
import hashlib
import hmac,time
import smtplib
from email.mime.text import MIMEText
from email import Utils
import threading
import requests,datetime,itchat

from toolkit import Toolkit


class Jubi_web():
def __init__(self, send=None):
cfg = Toolkit.getUserData('data.cfg')
self.public_key = cfg['public_key']
self.private_key = cfg['private_key']
self.send=send
from_mail = cfg['from_mail']
password = cfg['password']
to_mail = cfg['to_mail']
smtp_server = 'smtp.qq.com'

self.server = smtp_server
self.username = from_mail.split("@")[0]
self.from_mail = from_mail
self.password = password
self.to_mail = to_mail
self.coin_list=['IFC','DOGE','EAC','DNC','MET','ZET','SKT','YTC','PLC','LKC',
'JBC','MRYC','GOOC','QEC','PEB','XRP','NXT','WDC','MAX','ZCC',
'HLB','RSS','PGC','RIO','XAS','TFC','BLK','FZ','ANS','XPM','VTC',
'KTC','VRC','XSGS','LSK','PPC','ETC','GAME','LTC','ETH','BTC']
# 初始化邮箱设置读取需要股票信息
# 这样子只登陆一次
if self.send == 'msn':

try:
self.smtp = smtplib.SMTP_SSL(port=465)
self.smtp.connect(self.server)
self.smtp.login(self.username, self.password)
except smtplib.SMTPException, e:
print e
return 0

if send=='wechat':
self.w_name=u'xxxxx'

itchat.auto_login(hotReload=True)
account=itchat.get_friends(self.w_name)


def send_wechat(self,name,content):
w_content=name+' '+content
itchat.send(w_content,toUserName=self.toName)
time.sleep(1)
itchat.send(w_content,toUserName='filehelper')


def send_text(self, name, content):

subject = '%s' % name
self.msg = MIMEText(content, 'plain', 'utf-8')
self.msg['to'] = self.to_mail
self.msg['from'] = self.from_mail
self.msg['Subject'] = subject
self.msg['Date'] = Utils.formatdate(localtime=1)
try:
self.smtp.sendmail(self.msg['from'], self.msg['to'], self.msg.as_string())
self.smtp.quit()
print "sent"
except smtplib.SMTPException, e:
print e
return 0

def warming(self, coin, up_price, down_price):
url = 'https://www.jubi.com/api/v1/ticker/'
while 1:
time.sleep(5)
try:
data = requests.post(url, data={'coin': coin}).json()
except Exception,e:
print e
print "time out. Retry"
time.sleep(15)
continue

current = float(data['last'])
if current >= up_price:
print "Up to ", up_price
print "current price ",current

if self.send=='msn':
self.send_text(coin,str(current))
if self.send=='wechat':
self.send_wechat(coin,str(current))

time.sleep(1200)
if current <= down_price:
print "Down to ", down_price
print "current price ",current
if self.send=='msn':
self.send_text(coin,str(current))
if self.send=='wechat':
self.send_wechat(coin,str(current))
time.sleep(1200)
#上面的内容尽量不用修改。


def getContent(self):
url = 'https://www.jubi.com/api/v1/trade_list'
params_data = {'key': 'x', 'signature': 'x'}
s = requests.get(url=url, params=params_data)

def getHash(self, s):
m = hashlib.md5()
m.update(s)
return m.hexdigest()

def sha_convert(self, s):
return hashlib.sha256(self.getHash(s)).hexdigest()

def get_nonce(self):
lens = 12
return ''.join([str(random.randint(0, 9)) for i in range(lens)])

def get_signiture(self):
url = 'xxxxxxxxx'
coin = 'zet'
nonce = self.get_nonce()

# sha=self.sha_convert(private_key)
md5 = self.getHash(self.private_key)
message = 'nonce=' + nonce + '&' + 'key=' + self.public_key
# print message
signature = hmac.new(md5, message, digestmod=hashlib.sha256).digest()
# print signature

# req=requests.post(url,data={'signature':signature,'key':public_key,'nonce':nonce,'coin':'zet'})
req = requests.post(url, data={'coin': coin})
print req.status_code
print req.text

def real_time_ticker(self, coin):
url = 'xxxxxxxx'
try:
data = requests.post(url, data={'coin': coin}).json()
#print data
except Exception ,e:
print e
return data


def real_time_depth(self, coin):
url = 'xxxxxxxxx'
data = requests.post(url, data={'coin': coin}).json()
print data
data_bids = data['bids']
data_asks = data['asks']
print "bids"
for i in data_bids:
print i[0],
print ' ',
print i[1]
print "asks"
for j in data_asks:
print j[0],
print ' ',
print j[1]

def list_all_price(self):
for i in self.coin_list:
print i,
print " price: ",
p=self.real_time_ticker(i.lower())
if p is not None:
print p[u'last']

def getOrder(self,coin):
url='https://www.jubi.com/api/v1/orders/'
try:
req=requests.get(url,params={'coin':coin})
except Exception,e:
print e

data=req.json()
return data
# recent 100 trade turn over
def turnover(self,coin):
i=coin.lower()
coins=Toolkit.getUserData('coins.csv')
total=long(coins[i])
[i] [/i]p=self.getOrder(i)
print p
amount=0.00
for j in p:
t= j[u'amount']
amount=float(t)+amount
#current=float(self.real_time_ticker(i)[u'last'])
turn_over=amount*1.00/total*100
print turn_over

def multi_thread(self,coin_list,price_list):
thread_num=len(coin_list)
thread_list=
for i in range(thread_num):
t=threading.Thread(target=self.warming, args=(coin_list,price_list[0],price_list[1]),)
thread_list.append(t)
for j in thread_list:
j.start()
for k in thread_list:
k.join()

if __name__ == '__main__':

obj = Jubi_web(send='wechat')
coin_list=['zet','doge']
price_list=[[0.2,0.13],[0.03,0.024]]
obj.multi_thread(coin_list,price_list)

[/i]

程序运行后,使用扫一扫登录。 

coin_list=['zet','doge'] price_list=[[0.2,0.13],[0.03,0.024]]
 
通过这个参数,设置你想要监控的币种和目标价格。
同时程序支持发送给多个用户。
 

 http://30daydo.com/article/205
转载请注明出处
继续阅读 »
最近由于好友推荐我入坑了国内的山寨币,所以顺便研究了下聚币网的API。 不过网页版的聚币网和手机版的做的不好,而且因为是7x24 小时交易,自己没有那么多的精力盯盘,所以写了python代码进行监控。

Screenshot_2017-05-29-23-02-13-420_微信_副本_副本.png
# -*-coding=utf-8-*-
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: weigesysu@qq.com
'''
import random
import hashlib
import hmac,time
import smtplib
from email.mime.text import MIMEText
from email import Utils
import threading
import requests,datetime,itchat

from toolkit import Toolkit


class Jubi_web():
def __init__(self, send=None):
cfg = Toolkit.getUserData('data.cfg')
self.public_key = cfg['public_key']
self.private_key = cfg['private_key']
self.send=send
from_mail = cfg['from_mail']
password = cfg['password']
to_mail = cfg['to_mail']
smtp_server = 'smtp.qq.com'

self.server = smtp_server
self.username = from_mail.split("@")[0]
self.from_mail = from_mail
self.password = password
self.to_mail = to_mail
self.coin_list=['IFC','DOGE','EAC','DNC','MET','ZET','SKT','YTC','PLC','LKC',
'JBC','MRYC','GOOC','QEC','PEB','XRP','NXT','WDC','MAX','ZCC',
'HLB','RSS','PGC','RIO','XAS','TFC','BLK','FZ','ANS','XPM','VTC',
'KTC','VRC','XSGS','LSK','PPC','ETC','GAME','LTC','ETH','BTC']
# 初始化邮箱设置读取需要股票信息
# 这样子只登陆一次
if self.send == 'msn':

try:
self.smtp = smtplib.SMTP_SSL(port=465)
self.smtp.connect(self.server)
self.smtp.login(self.username, self.password)
except smtplib.SMTPException, e:
print e
return 0

if send=='wechat':
self.w_name=u'xxxxx'

itchat.auto_login(hotReload=True)
account=itchat.get_friends(self.w_name)


def send_wechat(self,name,content):
w_content=name+' '+content
itchat.send(w_content,toUserName=self.toName)
time.sleep(1)
itchat.send(w_content,toUserName='filehelper')


def send_text(self, name, content):

subject = '%s' % name
self.msg = MIMEText(content, 'plain', 'utf-8')
self.msg['to'] = self.to_mail
self.msg['from'] = self.from_mail
self.msg['Subject'] = subject
self.msg['Date'] = Utils.formatdate(localtime=1)
try:
self.smtp.sendmail(self.msg['from'], self.msg['to'], self.msg.as_string())
self.smtp.quit()
print "sent"
except smtplib.SMTPException, e:
print e
return 0

def warming(self, coin, up_price, down_price):
url = 'https://www.jubi.com/api/v1/ticker/'
while 1:
time.sleep(5)
try:
data = requests.post(url, data={'coin': coin}).json()
except Exception,e:
print e
print "time out. Retry"
time.sleep(15)
continue

current = float(data['last'])
if current >= up_price:
print "Up to ", up_price
print "current price ",current

if self.send=='msn':
self.send_text(coin,str(current))
if self.send=='wechat':
self.send_wechat(coin,str(current))

time.sleep(1200)
if current <= down_price:
print "Down to ", down_price
print "current price ",current
if self.send=='msn':
self.send_text(coin,str(current))
if self.send=='wechat':
self.send_wechat(coin,str(current))
time.sleep(1200)
#上面的内容尽量不用修改。


def getContent(self):
url = 'https://www.jubi.com/api/v1/trade_list'
params_data = {'key': 'x', 'signature': 'x'}
s = requests.get(url=url, params=params_data)

def getHash(self, s):
m = hashlib.md5()
m.update(s)
return m.hexdigest()

def sha_convert(self, s):
return hashlib.sha256(self.getHash(s)).hexdigest()

def get_nonce(self):
lens = 12
return ''.join([str(random.randint(0, 9)) for i in range(lens)])

def get_signiture(self):
url = 'xxxxxxxxx'
coin = 'zet'
nonce = self.get_nonce()

# sha=self.sha_convert(private_key)
md5 = self.getHash(self.private_key)
message = 'nonce=' + nonce + '&' + 'key=' + self.public_key
# print message
signature = hmac.new(md5, message, digestmod=hashlib.sha256).digest()
# print signature

# req=requests.post(url,data={'signature':signature,'key':public_key,'nonce':nonce,'coin':'zet'})
req = requests.post(url, data={'coin': coin})
print req.status_code
print req.text

def real_time_ticker(self, coin):
url = 'xxxxxxxx'
try:
data = requests.post(url, data={'coin': coin}).json()
#print data
except Exception ,e:
print e
return data


def real_time_depth(self, coin):
url = 'xxxxxxxxx'
data = requests.post(url, data={'coin': coin}).json()
print data
data_bids = data['bids']
data_asks = data['asks']
print "bids"
for i in data_bids:
print i[0],
print ' ',
print i[1]
print "asks"
for j in data_asks:
print j[0],
print ' ',
print j[1]

def list_all_price(self):
for i in self.coin_list:
print i,
print " price: ",
p=self.real_time_ticker(i.lower())
if p is not None:
print p[u'last']

def getOrder(self,coin):
url='https://www.jubi.com/api/v1/orders/'
try:
req=requests.get(url,params={'coin':coin})
except Exception,e:
print e

data=req.json()
return data
# recent 100 trade turn over
def turnover(self,coin):
i=coin.lower()
coins=Toolkit.getUserData('coins.csv')
total=long(coins[i])
[i] [/i]p=self.getOrder(i)
print p
amount=0.00
for j in p:
t= j[u'amount']
amount=float(t)+amount
#current=float(self.real_time_ticker(i)[u'last'])
turn_over=amount*1.00/total*100
print turn_over

def multi_thread(self,coin_list,price_list):
thread_num=len(coin_list)
thread_list=
for i in range(thread_num):
t=threading.Thread(target=self.warming, args=(coin_list,price_list[0],price_list[1]),)
thread_list.append(t)
for j in thread_list:
j.start()
for k in thread_list:
k.join()

if __name__ == '__main__':

obj = Jubi_web(send='wechat')
coin_list=['zet','doge']
price_list=[[0.2,0.13],[0.03,0.024]]
obj.multi_thread(coin_list,price_list)

[/i]

程序运行后,使用扫一扫登录。 

coin_list=['zet','doge'] price_list=[[0.2,0.13],[0.03,0.024]]
 
通过这个参数,设置你想要监控的币种和目标价格。
同时程序支持发送给多个用户。
 

 http://30daydo.com/article/205
转载请注明出处
收起阅读 »

TA-Lib中MOM的计算公式

MOM是价格动能。
 TA-Lib中MOM的参数有
ouput=talib.MOM(closed,timeperiod=5)
 
closed是你传入的价格list,可以是每天的收盘价,开盘价,或者你想要计算的所有价格。
timeperiod是你要计算的时间周期。
 
假如timeperiod=5,那么,这个计算的输出值就是 p5-p0, 如果今天是1月6日,股价为14块,而1月1日的股价为12块,那么这里通过MOM运算,得出来的就是14-12=2 这个值了。 然后如此类推,如果今天是1月7日,股价为15块,而1月2日股价为11块,那么MOM得出的是4,这样子获取到所有的值,绘制成曲线,就是MOM的曲线了。
继续阅读 »
MOM是价格动能。
 TA-Lib中MOM的参数有
ouput=talib.MOM(closed,timeperiod=5)
 
closed是你传入的价格list,可以是每天的收盘价,开盘价,或者你想要计算的所有价格。
timeperiod是你要计算的时间周期。
 
假如timeperiod=5,那么,这个计算的输出值就是 p5-p0, 如果今天是1月6日,股价为14块,而1月1日的股价为12块,那么这里通过MOM运算,得出来的就是14-12=2 这个值了。 然后如此类推,如果今天是1月7日,股价为15块,而1月2日股价为11块,那么MOM得出的是4,这样子获取到所有的值,绘制成曲线,就是MOM的曲线了。 收起阅读 »

Price Momentum

Understanding Price Momentum

Today's stock market is more than just a place to buy and hold securities. Many investors prefer to move quickly in and out of the market. That's just one reason technical strategies, such as price momentum, have grown in popularity.

In this article, we're going to provide some insights into the investment strategy known as price momentum.  We'll explain why some theorists believe this model offers investors a short-term profit opportunity.  We'll also talk about the pros and cons of this approach, including the long-term opportunity that price momentum provides the market.

What is Price Momentum?

Additional Resources

Calculating Stock Prices
Capital Asset Pricing Model
Arbitrage Pricing Theory
Stock Beta and Volatility
Random Walk Theory Explained

The theory behind price momentum is relatively simple.  Generally, we can talk about it in two ways; the first has to do with buying stocks:

Stocks that had relatively high returns over the past three to twelve months should return to investors above average returns over the next three to twelve months.

The theory also provides guidance on the right time to sell stocks:

Stocks that had relatively poor returns over the past three to twelve months should return to investors below average returns over the next three to twelve months.

This investment strategy was first theorized by Narasimhan Jegadeesh and Sheridan Titman in their publication "Returns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency," which was published in The Journal of Finance back in March 1993.

Price Momentum Model

The model is based on the assumption the stock market is not completely efficient. This is something that most economists believe to be true.  The two most practical explanations for the performance of this model include:

Investors are taking advantage of human behavior, including a "herding" mentality and / or an overreaction to news.
Investors employing a price momentum strategy are taking on additional risk; therefore, higher returns are required to compensate these investors for the risk they're assuming.

Within their study, Jegadeesh and Titman examined a large number of trading strategies.  One of the conclusions from that study is stated below:

Buying past winners, and selling past losers, allowed investors to achieve above average returns over the period 1956 to 1989.  In particular, stocks that were classified based on their prior 6-month performance, and held for 6 months realized an excess return of over 12% per year on average.

The Momentum Formula

Technical stock analysts understand the value this particular technique provides.  They're constantly crunching numbers to see if patterns emerge.  The actual formula for calculating price momentum is really quite simple, and takes the form:

M = CP - CPn

Where:

M = Momentum
CP = Closing price in the current period
CPn = Closing price N periods ago

For example, if a stock was trading at $35 per share six months ago, and is currently trading at $40 per share, then its six-month price momentum would be 40 minus 35 or 5.

Unfortunately, this formula is not normalized, and this makes it difficult to compare stocks selling at different price points.  A stock experiencing a 1% price movement from $300 to $303 would have a momentum value of three.  A second stock experiencing a 100% increase in price from $3 to $6 also has a momentum value of three.

Rate of Change Formula

One of the ways technical stock analysts can work around this problem is by calculating a rate of change value, which normalizes momentum:

RoC = (CP - CPn) / CPn

Where:

RoC = Rate of Change
CP = Closing price in the current period
CPn = Closing price N periods ago

Using the example above, the stock selling at $303 per share that was trading at $300 six months ago would have a Rate of Change of 3 / 300 or 1%, while the second stock would have a Rate of Change of 3 / 3 or 100%.

Momentum and Moving Averages

A second way that stock analysts use price momentum is in conjunction with moving averages.  Here the technical analyst makes a series of price momentum calculations and plots these along with a moving average of the momentum.

For example, the plot might contain 28-day moving averages along with daily price momentum figures.  Buy signals can be triggered when price momentum travels above its moving averages, and stays there for several trading days.  Sell signals can be triggered when momentum travels below its moving average.

Contrarian Investing

As mentioned in the beginning of this article, this model tells investors they should buy past winners and sell past losers.  Because this theory is based on past price performance, or historical market information, price momentum is a trading model that technical analysts would follow.  Fundamental analysts believe that a stock is bought and sold based on its intrinsic value, including the company's potential to produce profits for its shareholders in the future.

Fortunately, fundamental analysts can also use price momentum to their advantage by adopting what is termed a contrarian investing strategy.  Contrarian investors take the opposite approach that a theory advocates.  For example, a fundamental analyst might conclude:

A stock that has been rising may now be overvalued, while a stock that has been falling may be undervalued.

One could argue the further a stock moves from its true market value, the greater the opportunity for profits.  By tracking price momentum, and using this as a screening tool, fundamental analysts can then assess if a stock is truly undervalued or overvalued by studying the company's long-term financial health and earnings power.

About the Author - Understanding Price Momentum (Last Reviewed on November 22, 2016)
 
http://30daydo.com/article/203
 
继续阅读 »
Understanding Price Momentum

Today's stock market is more than just a place to buy and hold securities. Many investors prefer to move quickly in and out of the market. That's just one reason technical strategies, such as price momentum, have grown in popularity.

In this article, we're going to provide some insights into the investment strategy known as price momentum.  We'll explain why some theorists believe this model offers investors a short-term profit opportunity.  We'll also talk about the pros and cons of this approach, including the long-term opportunity that price momentum provides the market.

What is Price Momentum?

Additional Resources

Calculating Stock Prices
Capital Asset Pricing Model
Arbitrage Pricing Theory
Stock Beta and Volatility
Random Walk Theory Explained

The theory behind price momentum is relatively simple.  Generally, we can talk about it in two ways; the first has to do with buying stocks:

Stocks that had relatively high returns over the past three to twelve months should return to investors above average returns over the next three to twelve months.

The theory also provides guidance on the right time to sell stocks:

Stocks that had relatively poor returns over the past three to twelve months should return to investors below average returns over the next three to twelve months.

This investment strategy was first theorized by Narasimhan Jegadeesh and Sheridan Titman in their publication "Returns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency," which was published in The Journal of Finance back in March 1993.

Price Momentum Model

The model is based on the assumption the stock market is not completely efficient. This is something that most economists believe to be true.  The two most practical explanations for the performance of this model include:

Investors are taking advantage of human behavior, including a "herding" mentality and / or an overreaction to news.
Investors employing a price momentum strategy are taking on additional risk; therefore, higher returns are required to compensate these investors for the risk they're assuming.

Within their study, Jegadeesh and Titman examined a large number of trading strategies.  One of the conclusions from that study is stated below:

Buying past winners, and selling past losers, allowed investors to achieve above average returns over the period 1956 to 1989.  In particular, stocks that were classified based on their prior 6-month performance, and held for 6 months realized an excess return of over 12% per year on average.

The Momentum Formula

Technical stock analysts understand the value this particular technique provides.  They're constantly crunching numbers to see if patterns emerge.  The actual formula for calculating price momentum is really quite simple, and takes the form:

M = CP - CPn

Where:

M = Momentum
CP = Closing price in the current period
CPn = Closing price N periods ago

For example, if a stock was trading at $35 per share six months ago, and is currently trading at $40 per share, then its six-month price momentum would be 40 minus 35 or 5.

Unfortunately, this formula is not normalized, and this makes it difficult to compare stocks selling at different price points.  A stock experiencing a 1% price movement from $300 to $303 would have a momentum value of three.  A second stock experiencing a 100% increase in price from $3 to $6 also has a momentum value of three.

Rate of Change Formula

One of the ways technical stock analysts can work around this problem is by calculating a rate of change value, which normalizes momentum:

RoC = (CP - CPn) / CPn

Where:

RoC = Rate of Change
CP = Closing price in the current period
CPn = Closing price N periods ago

Using the example above, the stock selling at $303 per share that was trading at $300 six months ago would have a Rate of Change of 3 / 300 or 1%, while the second stock would have a Rate of Change of 3 / 3 or 100%.

Momentum and Moving Averages

A second way that stock analysts use price momentum is in conjunction with moving averages.  Here the technical analyst makes a series of price momentum calculations and plots these along with a moving average of the momentum.

For example, the plot might contain 28-day moving averages along with daily price momentum figures.  Buy signals can be triggered when price momentum travels above its moving averages, and stays there for several trading days.  Sell signals can be triggered when momentum travels below its moving average.

Contrarian Investing

As mentioned in the beginning of this article, this model tells investors they should buy past winners and sell past losers.  Because this theory is based on past price performance, or historical market information, price momentum is a trading model that technical analysts would follow.  Fundamental analysts believe that a stock is bought and sold based on its intrinsic value, including the company's potential to produce profits for its shareholders in the future.

Fortunately, fundamental analysts can also use price momentum to their advantage by adopting what is termed a contrarian investing strategy.  Contrarian investors take the opposite approach that a theory advocates.  For example, a fundamental analyst might conclude:

A stock that has been rising may now be overvalued, while a stock that has been falling may be undervalued.

One could argue the further a stock moves from its true market value, the greater the opportunity for profits.  By tracking price momentum, and using this as a screening tool, fundamental analysts can then assess if a stock is truly undervalued or overvalued by studying the company's long-term financial health and earnings power.

About the Author - Understanding Price Momentum (Last Reviewed on November 22, 2016)
 
http://30daydo.com/article/203
  收起阅读 »

能否改变贫穷?



c9c7e29cfff7929c9043e5bcefadcb4f_b.jpg

这是我的博士同事,Naphet,10月20日下午3点,他正式打出了他的博士论文,完成了四年的博士生涯。

Naphet 来自津巴布韦,世界上最混乱的国家之一(也许没有之一)。他没有谈他的童年,但我知道那一定不是我可以相比的。他从家乡出来后,成功地申请到了我们学校的 PhD,并且获得了英国国籍。这中间的努力,真的是我难以想象的。我至今深深记得,他去参加他的博士论文答辩的那天,抱着一本300多页厚厚的博士论文,像抱着一个婴儿那么珍惜。他的论文做定量的,主要工具是spss 程序,我曾经问过他从哪里学的 spss,他和我说,他在网上自学的。在读博的三年时间里,他就通过看 Youtube 的在线视频来从0开始学习 spss,如今,他的论文里充斥着各种精致的公式,而我的论文相比之下是如此的苍白无力。但他的论文还是没有通过答辩,因为我们学校新来的一个女老师质疑了他的方法,他很愤怒,因为他不理解为什么自己学校的老师竟然不支持他,但他没有气馁,而是继续每天早出晚归地来研究室修改论文。


他是有两个孩子的单亲爸爸。女儿已经上了高中,儿子才几个月大。他白天要在家里带孩子,晚上到火车站开出租车补贴学费和家用,挣来的钱还要寄回津巴布韦老家。因此他白天在家里通过远程桌面连接学校电脑学习,只有在晚上五点以后,他的女儿放学回来能照顾自己的弟弟,以及出租下班的时候才能来研究室学习。他周末的时候从来不回家,睡在出租车里,这样能多挣钱。而他一旦坐下,就会一动不动地全神贯注地开始工作。我有时候都很奇怪他从哪里来的精力,能够一边打工一边学习,并且能够如此专注。每每午夜十二点半,我离开研究室,而他仍然坐在电脑屏幕面前,专心调整着他公式的参数。

Naphet 的女儿非常优秀,她6岁的时候来到他身边。他充满自豪地同我分享了她女儿在 BBC 演讲比赛中获胜的演讲,并且告诉我她是英国青少年议会的议员,教区领袖,学校青少年协会的领导。“她的生活非常自律,比我更加自律,我从来没见过一个哪个17岁的孩子能够像她那么生活。”他对我说。在他女儿十五岁参加的那场演讲中,她把英语称之为杀手,并且分析了外国移民在英文环境中面对的语言困境。“我没有写一个字给她,都是她自己写的。我把这个视频用到了我的课程'社会学的想象力'中,这是一个可以作为博士论文的课题。”Naphet 非常自豪地对我说。我真的很震惊一个十五岁的女孩能够对环境有如此的敏感性。我提醒 Naphet 不要让她过于骄傲,他和我说:“我从来不夸奖她,我只是告诉她需要面对的挑战。她能够完成每一项挑战。”

他曾和我分享了他求职失败的经历,原因竟然是他过于优秀。三年博士期间,他获得了多个教师资格证书,比他的面试官还要优秀。结果可想而知,他精心准备的演讲反而害了他,实在是十分荒谬。但他没有气馁,他和我说:“我目前需要做的就是尽快博士毕业,好让自己有更多的自由去寻找更好的机会。”他的教学经验之丰富,远远超过了他的同辈,连他的面试官也只能嫉妒地说:“你实在是走的太快了。”我问他关于论文引用的问题,他却反过来向我求教我使用的引用软件,等我介绍完之后他掏出本子认真的记录着:“这个软件很好,我以后也要让我女儿试试。我现在就在为她准备大学需要面临的一切。”那一刻,我真的感觉到为什么人们说机会都是留给有准备的人。什么样的人是优秀的人?自强,自律,虚心,不骄不躁,永远充满信心,这样的父亲有这样的女儿,一点也不奇怪。

人在海外,社交圈很小,因此他给我的触动反倒更大。我第一次认真思考了何为一个有担当的男人。他没有钱,所以出去工作,他没有知识,所以上网自学。他面对着所有的不公正,却充满了自信的微笑。他对我说:“我要尽快完成我的博士,向我女儿证明我可以做到这一切。”是的,他一定可以的,我一点都不怀疑。反观我自己,在每一点上都放佛要被压榨出一个大大的“小”字来,我连对比的勇气都没有。他那岩石一般英朗的笑容背后有多少辛酸,多少委屈,我无法猜测,但我看到的是,他如同钟表一样准时的每天来到研究室,坐下,学习,创造着属于他和他女儿的未来。

他在论文的致谢部分写着:“献给我的母亲和我的四个兄弟,献给我过世的爸爸和五个叔叔。”

“我已经很多年没见过我母亲了。”他看着我读完了致谢之后说。

“你是怎么走过这一切的呢?”我问。

“压力。生活挤压着你,你只有前进。我所获得的一切都是靠我自己的双手得来的。”

他,是他们五兄弟中唯一走出来的。

很多时候,Naphet 这样的人是学不来的,但我想,他本身也许就是一个答案,在我们陷入迷茫和懦弱时,在我们给自己的人生拼命找借口时,带来一个声音:

贫穷不能改变吗?

能。

 
 
转至知乎:
https://www.zhihu.com/question/28098030/answer/68722565
 
继续阅读 »


c9c7e29cfff7929c9043e5bcefadcb4f_b.jpg

这是我的博士同事,Naphet,10月20日下午3点,他正式打出了他的博士论文,完成了四年的博士生涯。

Naphet 来自津巴布韦,世界上最混乱的国家之一(也许没有之一)。他没有谈他的童年,但我知道那一定不是我可以相比的。他从家乡出来后,成功地申请到了我们学校的 PhD,并且获得了英国国籍。这中间的努力,真的是我难以想象的。我至今深深记得,他去参加他的博士论文答辩的那天,抱着一本300多页厚厚的博士论文,像抱着一个婴儿那么珍惜。他的论文做定量的,主要工具是spss 程序,我曾经问过他从哪里学的 spss,他和我说,他在网上自学的。在读博的三年时间里,他就通过看 Youtube 的在线视频来从0开始学习 spss,如今,他的论文里充斥着各种精致的公式,而我的论文相比之下是如此的苍白无力。但他的论文还是没有通过答辩,因为我们学校新来的一个女老师质疑了他的方法,他很愤怒,因为他不理解为什么自己学校的老师竟然不支持他,但他没有气馁,而是继续每天早出晚归地来研究室修改论文。


他是有两个孩子的单亲爸爸。女儿已经上了高中,儿子才几个月大。他白天要在家里带孩子,晚上到火车站开出租车补贴学费和家用,挣来的钱还要寄回津巴布韦老家。因此他白天在家里通过远程桌面连接学校电脑学习,只有在晚上五点以后,他的女儿放学回来能照顾自己的弟弟,以及出租下班的时候才能来研究室学习。他周末的时候从来不回家,睡在出租车里,这样能多挣钱。而他一旦坐下,就会一动不动地全神贯注地开始工作。我有时候都很奇怪他从哪里来的精力,能够一边打工一边学习,并且能够如此专注。每每午夜十二点半,我离开研究室,而他仍然坐在电脑屏幕面前,专心调整着他公式的参数。

Naphet 的女儿非常优秀,她6岁的时候来到他身边。他充满自豪地同我分享了她女儿在 BBC 演讲比赛中获胜的演讲,并且告诉我她是英国青少年议会的议员,教区领袖,学校青少年协会的领导。“她的生活非常自律,比我更加自律,我从来没见过一个哪个17岁的孩子能够像她那么生活。”他对我说。在他女儿十五岁参加的那场演讲中,她把英语称之为杀手,并且分析了外国移民在英文环境中面对的语言困境。“我没有写一个字给她,都是她自己写的。我把这个视频用到了我的课程'社会学的想象力'中,这是一个可以作为博士论文的课题。”Naphet 非常自豪地对我说。我真的很震惊一个十五岁的女孩能够对环境有如此的敏感性。我提醒 Naphet 不要让她过于骄傲,他和我说:“我从来不夸奖她,我只是告诉她需要面对的挑战。她能够完成每一项挑战。”

他曾和我分享了他求职失败的经历,原因竟然是他过于优秀。三年博士期间,他获得了多个教师资格证书,比他的面试官还要优秀。结果可想而知,他精心准备的演讲反而害了他,实在是十分荒谬。但他没有气馁,他和我说:“我目前需要做的就是尽快博士毕业,好让自己有更多的自由去寻找更好的机会。”他的教学经验之丰富,远远超过了他的同辈,连他的面试官也只能嫉妒地说:“你实在是走的太快了。”我问他关于论文引用的问题,他却反过来向我求教我使用的引用软件,等我介绍完之后他掏出本子认真的记录着:“这个软件很好,我以后也要让我女儿试试。我现在就在为她准备大学需要面临的一切。”那一刻,我真的感觉到为什么人们说机会都是留给有准备的人。什么样的人是优秀的人?自强,自律,虚心,不骄不躁,永远充满信心,这样的父亲有这样的女儿,一点也不奇怪。

人在海外,社交圈很小,因此他给我的触动反倒更大。我第一次认真思考了何为一个有担当的男人。他没有钱,所以出去工作,他没有知识,所以上网自学。他面对着所有的不公正,却充满了自信的微笑。他对我说:“我要尽快完成我的博士,向我女儿证明我可以做到这一切。”是的,他一定可以的,我一点都不怀疑。反观我自己,在每一点上都放佛要被压榨出一个大大的“小”字来,我连对比的勇气都没有。他那岩石一般英朗的笑容背后有多少辛酸,多少委屈,我无法猜测,但我看到的是,他如同钟表一样准时的每天来到研究室,坐下,学习,创造着属于他和他女儿的未来。

他在论文的致谢部分写着:“献给我的母亲和我的四个兄弟,献给我过世的爸爸和五个叔叔。”

“我已经很多年没见过我母亲了。”他看着我读完了致谢之后说。

“你是怎么走过这一切的呢?”我问。

“压力。生活挤压着你,你只有前进。我所获得的一切都是靠我自己的双手得来的。”

他,是他们五兄弟中唯一走出来的。

很多时候,Naphet 这样的人是学不来的,但我想,他本身也许就是一个答案,在我们陷入迷茫和懦弱时,在我们给自己的人生拼命找借口时,带来一个声音:

贫穷不能改变吗?

能。

 
 
转至知乎:
https://www.zhihu.com/question/28098030/answer/68722565
  收起阅读 »

TA-Lib MA_Type

在TA-Lib中有一个参数的类型是MA_Type, 谷歌了一下,把内容贴出来。 
 
主要就是使用不一样的加权方式对数据进行处理。
import talib
from talib import MA_Type

MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA)

 
移动平均(英语:moving average,MA),又称“移动平均线”简称均线,是技术分析中一种分析时间序列数据的工具。最常见的是利用股价、回报或交易量等变数计算出移动平均。
移动平均可抚平短期波动,反映出长期趋势或周期。数学上,移动平均可视为一种卷积。
 

简单移动平均(英语:simple moving average,SMA)是某变数之前n个数值的未作加权算术平均。例如,收市价的10日简单移动平均指之前10日收市价的平均数。:

当计算连续的数值,一个新的数值加入,同时一个旧数值剔出,所以无需每次都重新逐个数值加起来。
在技术分析中,不同的市场对常用天数(n值)有不同的需求,例如:某些市场普遍的n值为10日、40日、200日;有些则是5日、10日、20日、60日、120日、240日,视乎分析时期长短而定。投资者冀从移动平均线的图表中分辨出支持位或阻力位。
 
 
 
加权移动平均(英语:weighted moving average,WMA)指计算平均值时将个别数据乘以不同数值,在技术分析中,n日WMA的最近期一个数值乘以n、次近的乘以n-1,如此类推,一直到0:
 
指数移动平均(英语:exponential moving average,EMA或EWMA)是以指数式递减加权的移动平均。各数值的加权影响力随时间而指数式递减,越近期的数据加权影响力越重,但较旧的数据也给予一定的加权值
 
     
     WMA                                             EMA
 
 
使用下面的代码实现不一样的MA
 
    #MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA)
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
closed=df['close'].values
sma=talib.MA(closed,timeperiod=10,matype=0)
ema=talib.MA(closed,timeperiod=10,matype=1)
wma=talib.MA(closed,timeperiod=10,matype=2)
dema=talib.MA(closed,timeperiod=10,matype=3)
tema=talib.MA(closed,timeperiod=10,matype=4)
trima=talib.MA(closed,timeperiod=10,matype=5)
kma=talib.MA(closed,timeperiod=10,matype=6)
mama=talib.MA(closed,timeperiod=10,matype=7)
t3=talib.MA(closed,timeperiod=10,matype=8)
#ouput=talib.MA(closed,timeperiod=5,matype=0)
print closed
plt.ylim([0,40])
plt.plot(sma)
plt.plot(ema)
plt.plot(wma)
plt.plot(dema)
plt.plot(tema)
plt.plot(trima)
plt.plot(kma)
plt.plot(mama)
plt.plot(t3)
plt.grid()
plt.show()

生成的图像如下:

diff_ma.PNG

 
http://30daydo.com/article/201
转载请注明出处
继续阅读 »
在TA-Lib中有一个参数的类型是MA_Type, 谷歌了一下,把内容贴出来。 
 
主要就是使用不一样的加权方式对数据进行处理。
import talib
from talib import MA_Type

MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA)

 
移动平均(英语:moving average,MA),又称“移动平均线”简称均线,是技术分析中一种分析时间序列数据的工具。最常见的是利用股价、回报或交易量等变数计算出移动平均。
移动平均可抚平短期波动,反映出长期趋势或周期。数学上,移动平均可视为一种卷积。
 

简单移动平均(英语:simple moving average,SMA)是某变数之前n个数值的未作加权算术平均。例如,收市价的10日简单移动平均指之前10日收市价的平均数。:

当计算连续的数值,一个新的数值加入,同时一个旧数值剔出,所以无需每次都重新逐个数值加起来。
在技术分析中,不同的市场对常用天数(n值)有不同的需求,例如:某些市场普遍的n值为10日、40日、200日;有些则是5日、10日、20日、60日、120日、240日,视乎分析时期长短而定。投资者冀从移动平均线的图表中分辨出支持位或阻力位。
 
 
 
加权移动平均(英语:weighted moving average,WMA)指计算平均值时将个别数据乘以不同数值,在技术分析中,n日WMA的最近期一个数值乘以n、次近的乘以n-1,如此类推,一直到0:
 
指数移动平均(英语:exponential moving average,EMA或EWMA)是以指数式递减加权的移动平均。各数值的加权影响力随时间而指数式递减,越近期的数据加权影响力越重,但较旧的数据也给予一定的加权值
 
     
     WMA                                             EMA
 
 
使用下面的代码实现不一样的MA
 
    #MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA)
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
closed=df['close'].values
sma=talib.MA(closed,timeperiod=10,matype=0)
ema=talib.MA(closed,timeperiod=10,matype=1)
wma=talib.MA(closed,timeperiod=10,matype=2)
dema=talib.MA(closed,timeperiod=10,matype=3)
tema=talib.MA(closed,timeperiod=10,matype=4)
trima=talib.MA(closed,timeperiod=10,matype=5)
kma=talib.MA(closed,timeperiod=10,matype=6)
mama=talib.MA(closed,timeperiod=10,matype=7)
t3=talib.MA(closed,timeperiod=10,matype=8)
#ouput=talib.MA(closed,timeperiod=5,matype=0)
print closed
plt.ylim([0,40])
plt.plot(sma)
plt.plot(ema)
plt.plot(wma)
plt.plot(dema)
plt.plot(tema)
plt.plot(trima)
plt.plot(kma)
plt.plot(mama)
plt.plot(t3)
plt.grid()
plt.show()

生成的图像如下:

diff_ma.PNG

 
http://30daydo.com/article/201
转载请注明出处 收起阅读 »

TA-Lib 量化交易代码实例 <二> 获取布林线的上轨,中轨,下轨的数据


BOLL指标的原理
BOLL指标是美国股市分析家约翰·布林根据统计学中的标准差原理设计出来的一种非常简单实用的技术分析指标。一般而言,股价的运动总是围绕某一价值中枢(如均线、成本线等)在一定的范围内变动,布林线指标指标正是在上述条件的基础上,引进了“股价通道”的概念,其认为股价通道的宽窄随着股价波动幅度的大小而变化,而且股价通道又具有变异性,它会随着股价的变化而自动调整。正是由于它具有灵活性、直观性和趋势性的特点,BOLL指标渐渐成为投资者广为应用的市场上热门指标。
在众多技术分析指标中,BOLL指标属于比较特殊的一类指标。绝大多数技术分析指标都是通过数量的方法构造出来的,它们本身不依赖趋势分析和形态分析,而BOLL指标却股价的形态和趋势有着密不可分的联系。BOLL指标中的“股价通道”概念正是股价趋势理论的直观表现形式。BOLL是利用“股价通道”来显示股价的各种价位,当股价波动很小,处于盘整时,股价通道就会变窄,这可能预示着股价的波动处于暂时的平静期;当股价波动超出狭窄的股价通道的上轨时,预示着股价的异常激烈的向上波动即将开始;当股价波动超出狭窄的股价通道的下轨时,同样也预示着股价的异常激烈的向下波动将开始。
投资者常常会遇到两种最常见的交易陷阱,一是买低陷阱,投资者在所谓的低位买进之后,股价不仅没有止跌反而不断下跌;二是卖高陷阱,股票在所谓的高点卖出后,股价却一路上涨。布林线特别运用了爱因斯坦的相对论,认为各类市场间都是互动的,市场内和市场间的各种变化都是相对性的,是不存在绝对性的,股价的高低是相对的,股价在上轨线以上或在下轨线以下只反映该股股价相对较高或较低,投资者作出投资判断前还须综合参考其他技术指标,包括价量配合,心理类指标,类比类指标,市场间的关联数据等。
总之,BOLL指标中的股价通道对预测未来行情的走势起着重要的参考作用,它也是布林线指标所特有的分析手段。
[编辑]
BOLL指标的计算方法
在所有的指标计算中,BOLL指标的计算方法是最复杂的之一,其中引进了统计学中的标准差概念,涉及到中轨线(MB)、上轨线(UP)和下轨线(DN)的计算。另外,和其他指标的计算一样,由于选用的计算周期的不同,BOLL指标也包括日BOLL指标、周BOLL指标、月BOLL指标年BOLL指标以及分钟BOLL指标等各种类型。经常被用于股市研判的是日BOLL指标和周BOLL指标。虽然它们的计算时的取值有所不同,但基本的计算方法一样。以日BOLL指标计算为例,其计算方法如下:
1、日BOLL指标的计算公式
中轨线=N日的移动平均线
上轨线=中轨线+两倍的标准差
下轨线=中轨线-两倍的标准差
2、日BOLL指标的计算过程
1)计算MA
MA=N日内的收盘价之和÷N2)计算标准差MD
MD=平方根N日的(C-MA)的两次方之和除以N3)计算MB、UP、DN线
MB=(N-1)日的MA
UP=MB+2×MD
DN=MB-2×MD在股市分析软件中,BOLL指标一共由四条线组成,即上轨线UP 、中轨线MB、下轨线DN和价格线。其中上轨线UP是UP数值的连线,用黄色线表示;中轨线MB是MB数值的连线,用白色线表示;下轨线DN是DN数值的连线,用紫色线表示;价格线是以美国线表示,颜色为浅蓝色。和其他技术指标一样,在实战中,投资者不需要进行BOLL指标的计算,主要是了解BOLL的计算方法和过程,以便更加深入地掌握BOLL指标的实质,为运用指标打下基础。
 
    #通过tushare获取股票信息
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
#提取收盘价
closed=df['close'].values

upper,middle,lower=talib.BBANDS(closed,matype=talib.MA_Type.T3)

print upper,middle,lower
plt.plot(upper)
plt.plot(middle)
plt.plot(lower)
plt.grid()
plt.show()
diff1=upper-middle
diff2=middle-lower
print diff1
print diff2


布林线.PNG

 
最后那里可以看到diff1和diff2是一样的。 验证了布林线的定义ma+2d,m-2d。
继续阅读 »

BOLL指标的原理
BOLL指标是美国股市分析家约翰·布林根据统计学中的标准差原理设计出来的一种非常简单实用的技术分析指标。一般而言,股价的运动总是围绕某一价值中枢(如均线、成本线等)在一定的范围内变动,布林线指标指标正是在上述条件的基础上,引进了“股价通道”的概念,其认为股价通道的宽窄随着股价波动幅度的大小而变化,而且股价通道又具有变异性,它会随着股价的变化而自动调整。正是由于它具有灵活性、直观性和趋势性的特点,BOLL指标渐渐成为投资者广为应用的市场上热门指标。
在众多技术分析指标中,BOLL指标属于比较特殊的一类指标。绝大多数技术分析指标都是通过数量的方法构造出来的,它们本身不依赖趋势分析和形态分析,而BOLL指标却股价的形态和趋势有着密不可分的联系。BOLL指标中的“股价通道”概念正是股价趋势理论的直观表现形式。BOLL是利用“股价通道”来显示股价的各种价位,当股价波动很小,处于盘整时,股价通道就会变窄,这可能预示着股价的波动处于暂时的平静期;当股价波动超出狭窄的股价通道的上轨时,预示着股价的异常激烈的向上波动即将开始;当股价波动超出狭窄的股价通道的下轨时,同样也预示着股价的异常激烈的向下波动将开始。
投资者常常会遇到两种最常见的交易陷阱,一是买低陷阱,投资者在所谓的低位买进之后,股价不仅没有止跌反而不断下跌;二是卖高陷阱,股票在所谓的高点卖出后,股价却一路上涨。布林线特别运用了爱因斯坦的相对论,认为各类市场间都是互动的,市场内和市场间的各种变化都是相对性的,是不存在绝对性的,股价的高低是相对的,股价在上轨线以上或在下轨线以下只反映该股股价相对较高或较低,投资者作出投资判断前还须综合参考其他技术指标,包括价量配合,心理类指标,类比类指标,市场间的关联数据等。
总之,BOLL指标中的股价通道对预测未来行情的走势起着重要的参考作用,它也是布林线指标所特有的分析手段。
[编辑]
BOLL指标的计算方法
在所有的指标计算中,BOLL指标的计算方法是最复杂的之一,其中引进了统计学中的标准差概念,涉及到中轨线(MB)、上轨线(UP)和下轨线(DN)的计算。另外,和其他指标的计算一样,由于选用的计算周期的不同,BOLL指标也包括日BOLL指标、周BOLL指标、月BOLL指标年BOLL指标以及分钟BOLL指标等各种类型。经常被用于股市研判的是日BOLL指标和周BOLL指标。虽然它们的计算时的取值有所不同,但基本的计算方法一样。以日BOLL指标计算为例,其计算方法如下:
1、日BOLL指标的计算公式
中轨线=N日的移动平均线
上轨线=中轨线+两倍的标准差
下轨线=中轨线-两倍的标准差
2、日BOLL指标的计算过程
1)计算MA
MA=N日内的收盘价之和÷N2)计算标准差MD
MD=平方根N日的(C-MA)的两次方之和除以N3)计算MB、UP、DN线
MB=(N-1)日的MA
UP=MB+2×MD
DN=MB-2×MD在股市分析软件中,BOLL指标一共由四条线组成,即上轨线UP 、中轨线MB、下轨线DN和价格线。其中上轨线UP是UP数值的连线,用黄色线表示;中轨线MB是MB数值的连线,用白色线表示;下轨线DN是DN数值的连线,用紫色线表示;价格线是以美国线表示,颜色为浅蓝色。和其他技术指标一样,在实战中,投资者不需要进行BOLL指标的计算,主要是了解BOLL的计算方法和过程,以便更加深入地掌握BOLL指标的实质,为运用指标打下基础。
 
    #通过tushare获取股票信息
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
#提取收盘价
closed=df['close'].values

upper,middle,lower=talib.BBANDS(closed,matype=talib.MA_Type.T3)

print upper,middle,lower
plt.plot(upper)
plt.plot(middle)
plt.plot(lower)
plt.grid()
plt.show()
diff1=upper-middle
diff2=middle-lower
print diff1
print diff2


布林线.PNG

 
最后那里可以看到diff1和diff2是一样的。 验证了布林线的定义ma+2d,m-2d。 收起阅读 »

quantdigger 量化交易入门 代码示例

第五天
 
《》
待更新
第五天
 
《》
待更新

TA-Lib 量化交易代码实例 <一> 获取5日,10日,20日均线数据

第一节
 
安装教程在前面内容已经介绍过了,对于新手也是有点障碍,可以参照前面的文章进行一步一步操作。 http://30daydo.com/article/195
    #通过tushare获取股票信息
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
#提取收盘价
closed=df['close'].values
#获取均线的数据,通过timeperiod参数来分别获取 5,10,20 日均线的数据。
ma5=talib.SMA(closed,timeperiod=5)
ma10=talib.SMA(closed,timeperiod=10)
ma20=talib.SMA(closed,timeperiod=20)

#打印出来每一个数据
print closed
print ma5
print ma10
print ma20

#通过plog函数可以很方便的绘制出每一条均线
plt.plot(closed)
plt.plot(ma5)
plt.plot(ma10)
plt.plot(ma20)
#添加网格,可有可无,只是让图像好看点
plt.grid()
#记得加这一句,不然不会显示图像
plt.show()

上面第一句使用tushare获取股票的数据,如果不知道怎么操作的,可以在这里参考,同样是入门的教程。
http://30daydo.com/article/13
 
 
运行上面的代码后,可以得到下面的曲线:
 

贝斯特曲线.PNG

 
你们可以去对比一下贝斯特的收盘价,5日,10日,20日均线。是不是一样的?
就这样我们就完成了均线的获取。 是不是很简单?
 
 
 
继续阅读 »
第一节
 
安装教程在前面内容已经介绍过了,对于新手也是有点障碍,可以参照前面的文章进行一步一步操作。 http://30daydo.com/article/195
    #通过tushare获取股票信息
df=ts.get_k_data('300580',start='2017-01-12',end='2017-05-26')
#提取收盘价
closed=df['close'].values
#获取均线的数据,通过timeperiod参数来分别获取 5,10,20 日均线的数据。
ma5=talib.SMA(closed,timeperiod=5)
ma10=talib.SMA(closed,timeperiod=10)
ma20=talib.SMA(closed,timeperiod=20)

#打印出来每一个数据
print closed
print ma5
print ma10
print ma20

#通过plog函数可以很方便的绘制出每一条均线
plt.plot(closed)
plt.plot(ma5)
plt.plot(ma10)
plt.plot(ma20)
#添加网格,可有可无,只是让图像好看点
plt.grid()
#记得加这一句,不然不会显示图像
plt.show()

上面第一句使用tushare获取股票的数据,如果不知道怎么操作的,可以在这里参考,同样是入门的教程。
http://30daydo.com/article/13
 
 
运行上面的代码后,可以得到下面的曲线:
 

贝斯特曲线.PNG

 
你们可以去对比一下贝斯特的收盘价,5日,10日,20日均线。是不是一样的?
就这样我们就完成了均线的获取。 是不是很简单?
 
 
  收起阅读 »