[置顶] Python 通过QSTK管理和存储股票CVS数据

1. 前言

之前的文章中谈到可以通过Yahoo获取股票的交易数据,当对大量股票交易数据进行分析时,每次都从Yahoo获取显然不合适,因此一般的做法都是把数据保存到本地。
Georgia Tech开发了一套给予Python的开源的量化工具QSToolKit (QSTK),通过它可以使CVS数据的存储和管理变得相对简单些。

2. QSTK

2.1 介绍

QSToolKit (QSTK) is a Python-based open source software framework designed to support portfolio construction and management. We are building the QSToolKit primarily for finance students, computing students, and quantitative analysts with programming experience. You should not expect to use it as a desktop app trading platform. Instead, think of it as a software infrastructure to support a workflow of modeling, testing and trading.
QSTK介绍wiki : http://wiki.quantsoftware.org/index.php?title=QuantSoftware_ToolKit

2.2 安装

wget http://pypi.python.org/packages/source/Q/QSTK/QSTK-0.2.8.tar.gz
tar -xzvf QSTK-0.2.8.tar.gz
cd QSTK-0.2.8
sudo sh UbuntuInstallation.sh
sudo python setup.py install
cd Examples
python Validation.py

3. 存储

首先从Yahoo下载股票CVS数据,参考Python获取Yahoo股票数据
让后通过下面的代码查看文件存放路径:

    db = da.DataAccess('Yahoo', verbose=True)
    path = db.rootdir
    print path

我路径是:“/usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/QSData/Yahoo”
然后把文件放进去即可

4. 获取数据

    ls_stock_code = ['300033.SZ', '002657.SZ', '300314.SZ']
    start_time = datetime.datetime(2011, 11, 1)
    end_time = datetime.datetime(2016, 1, 1)
    time_of_day = datetime.timedelta(hours=16)
    time_stamps = dateutil.getNYSEdays(start_time, end_time, time_of_day)

    db = DataAccess.DataAccess('Yahoo')
    ls_keys = ['open', 'high', 'low', 'close', 'volume', 'actual_close']
    data = db.get_data(time_stamps, ls_stock_code, ls_keys)
    dict_data = dict(zip(ls_keys, data))

5. 参考文献

[1] QSTK Wiki http://wiki.quantsoftware.org/index.php?title=QuantSoftware_ToolKit\
[2] QSTK Install Guid http://wiki.quantsoftware.org/index.php?title=QSToolKit_Installation_Guide_Ubuntu

你可能感兴趣的:(python,cvs,股票,QSTK,量化投资)