mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
bcc08fc598
@ -1,292 +0,0 @@
|
||||
coolpigs is translating this article
|
||||
|
||||
Installing a Desktop Algorithmic Trading Research Environment using Ubuntu Linux and Python
|
||||
================================================================================
|
||||
In this article I want to discuss how to set up a robust, efficient and interactive development environment for algorithmic trading strategy research making use of Ubuntu Desktop Linux and the Python programming language. We will utilise this environment for nearly all subsequent algorithmic trading articles.
|
||||
|
||||
To create the research environment we will install the following software tools, all of which are open-source and free to download:
|
||||
|
||||
- [Oracle VirtualBox][1] - For virtualisation of the operating system
|
||||
- [Ubuntu Desktop Linux][2] - As our virtual operating system
|
||||
- [Python][3] - The core programming environment
|
||||
- [NumPy][4]/[SciPy][5] - For fast, efficient array/matrix calculation
|
||||
- [IPython][6] - For visual interactive development with Python
|
||||
- [matplotlib][7] - For graphical visualisation of data
|
||||
- [pandas][8] - For data "wrangling" and time series analysis
|
||||
- [scikit-learn][9] - For machine learning and artificial intelligence algorithms
|
||||
|
||||
These tools (coupled with a suitable [securities master database][10]) will allow us to create a rapid interactive strategy research environment. Pandas is designed for "data wrangling" and can import and cleanse time series data very efficiently. NumPy/SciPy running underneath keeps the system extremely well optimised. IPython/matplotlib (and the qtconsole described below) allow interactive visualisation of results and rapid iteration. scikit-learn allows us to apply machine learning techniques to our strategies to further enhance performance.
|
||||
|
||||
Note that I've written the tutorial so that Windows or Mac OSX users who are unwilling or unable to install Ubuntu Linux directly can still follow along by using VirtualBox. VirtualBox allows us to create a "Virtual Machine" inside the host system that can emulate a guest operating system without affecting the host in any way. This allows experimentation with Ubuntu and the Python tools before committing to a full installation. For those who already have Ubuntu Desktop installed, you can skip to the section on "Installing the Python Research Environment Packages on Ubuntu".
|
||||
|
||||
## Installing VirtualBox and Ubuntu Linux ##
|
||||
|
||||
This section of the tutorial regarding VirtualBox installation has been written for a Mac OSX system, but will easily translate to a Windows host environment. Once VirtualBox has been installed the procedure will be the same for any underlying host operating system.
|
||||
|
||||
Before we begin installing the software we need to go ahead and download both Ubuntu and VirtualBox.
|
||||
|
||||
**Downloading the Ubuntu Desktop disk image**
|
||||
|
||||
Open up your favourite web browser and navigate to the [Ubuntu Desktop][11] homepage then select Ubuntu 13.04:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0004.png)
|
||||
|
||||
*Download Ubuntu 13.04 (64-bit if appropriate)*
|
||||
|
||||
You will be asked to contribute a donation although this is optional. Once you have reached the download page make sure to select Ubuntu 13.04. You'll need to choose whether you want the 32-bit or 64-bit version. It is likely you'll have a 64-bit system, but if you're in doubt, then choose 32-bit. On a Mac OSX system the Ubuntu Desktop ISO disk image will be stored in your Downloads directory. We will make use of it later once we have installed VirtualBox.
|
||||
|
||||
**Downloading and Installing VirtualBox**
|
||||
|
||||
Now that we've downloaded Ubuntu we need to go and obtain the latest version of Oracle's VirtualBox software. Click [here][12] to visit the website and select the version for your particular host (for the purposes of this tutorial we need Mac OSX):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0002.png)
|
||||
|
||||
*Oracle VirtualBox download page*
|
||||
|
||||
Once the file has been downloaded we need to run it and click on the package icon (this will vary somewhat in Windows but will be a similar process):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0007.png)
|
||||
|
||||
*Double-click the package icon to install VirtualBox*
|
||||
|
||||
Once the package has opened, we follow the installation instructions, keeping the defaults as they are (unless you feel the need to change them!). Now that VirtualBox has been installed we can open it from the Applications folder (which can be found with Finder). It puts VirtualBox on the icon dock while running, so you may wish to keep it there permanently if you want to examine Ubuntu Linux more closely in the future before committing to a full install:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0008.png)
|
||||
|
||||
*VirtualBox with no disk images yet*
|
||||
|
||||
We are now going to create a new 'virtual box' (i.e. virtualised operating system) by clicking on the New icon, which looks like a cog. I've called mine "Ubuntu Desktop 13.04 Algorithmic Trading" (so you may wish to use something similarly descriptive!):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0009.png)
|
||||
|
||||
*Naming our new virtual environment*
|
||||
|
||||
Choose the amount of RAM you wish to allocate to the virtual system. I've kept it at 512Mb since this is only a "test" system. A 'real' backtesting engine would likely use a native installation (and thus allocate significantly more memory) for efficiency reasons:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0010.png)
|
||||
|
||||
*Choose the amount of RAM for the virtual disk*
|
||||
|
||||
Create a virtual hard drive and use the recommended 8Gb, with a VirtualBox Disk Image, dynamically allocated, with the same name as the VirtualBox Image above:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0011.png)
|
||||
|
||||
*Choosing the type of hard disk used by the image*
|
||||
|
||||
You will now see a complete system with listed details:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0012.png)
|
||||
|
||||
*The virtual image has been created*
|
||||
|
||||
We now need to tell VirtualBox to include a virtual 'CD drive' for the new disk image so that we can pretend to boot our new Ubuntu disk image from this CD drive. Head to the Settings section, click on the "Storage" tab and add a Disk. You will need to navigate to the Ubuntu Disk image ISO file stored in your Downloads directly (or wherever you downloaded Ubuntu to). Select it and then save the settings:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0014.png)
|
||||
|
||||
*Choosing the Ubuntu Desktop ISO on first boot*
|
||||
|
||||
Now we are ready to boot up our Ubuntu image and get it installed. Click on "Start" and then on "OK" when you see the message about Host Capture of the Mouse/Keyboard. Note that on my Mac OSX, the host capture key is the Left Cmd key (i.e. Left Apple key). You will now be presented with the Ubuntu Desktop installation screen. Click on "Install Ubuntu":
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0015.png)
|
||||
|
||||
*Click on Install Ubuntu to get started*
|
||||
|
||||
Make sure to tick both boxes to install the proprietary MP3 and Wi-Fi drivers:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0016.png)
|
||||
|
||||
*Install the proprietary drivers for MP3 and Wi-Fi*
|
||||
|
||||
You will now see a screen asking how you would like to store the data created for the operating system. Don't panic about the "Erase Disk and Install Ubuntu" option. It does NOT mean that it will erase your normal hard disk! It actually refers to the virtual disk it is using to run Ubuntu in, which is safe to erase (there isn't anything on there anyway, as we've just created it). Carry on with the install and you will be presented with a screen asking for your location and subsequently, your keyboard layout:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0017.png)
|
||||
|
||||
*Select your geographical location*
|
||||
|
||||
Enter in your user credentials, making sure to remember your password as you'll need it later on for installing packages:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0018.png)
|
||||
|
||||
*Enter your username and password (this password is the administrator password)*
|
||||
|
||||
Ubuntu will now install the files. It should be relatively quick as it is just copying from the hard disk to the hard disk! Eventually it will complete and the VirtualBox will restart. If it doesn't restart on its own, you can go to the menu and force a Shutdown. You will be brought back to the Ubuntu Login Screen:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0019.png)
|
||||
|
||||
*The Ubuntu Desktop login screen*
|
||||
|
||||
Login with your username and password from above and you will see your shiny new Ubuntu desktop:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0020.png)
|
||||
|
||||
*The Unity interface to the Ubuntu Desktop after logging in*
|
||||
|
||||
The last thing to do is click on the Firefox icon to test that the internet/networking functionality is correct by visiting a website (I picked QuantStart.com, funnily enough!):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0021.png)
|
||||
|
||||
The Ubuntu Desktop login screen
|
||||
|
||||
Now that the Ubuntu Desktop is installed we can begin installing the algorithmic trading research environment packages.
|
||||
|
||||
## Installing the Python Research Environment Packages on Ubuntu ##
|
||||
|
||||
Click on the search button at the top-left of the screen and type "Terminal" into the box to bring up the command-line interface. Double-click the terminal icon to launch the Terminal:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0022.png)
|
||||
|
||||
*The Ubuntu Desktop login screen*
|
||||
|
||||
All subsequent commands will need to be typed into this terminal.
|
||||
|
||||
The first thing to do on any brand new Ubuntu Linux system is to update and upgrade the packages. The former tells Ubuntu about new packages that are available, while the latter actually performs the process of replacing older packages with newer versions. Run the following commands (you will be prompted for your passwords):
|
||||
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y upgrade
|
||||
|
||||
*Note that the -y prefix tells Ubuntu that you want to accept 'yes' to all yes/no questions. "sudo" is a Ubuntu/Debian Linux command that allows other commands to be executed with administrator privileges. Since we are installing our packages sitewide, we need 'root access' to the machine and thus must make use of 'sudo'.*
|
||||
|
||||
You may get an error message here:
|
||||
|
||||
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
|
||||
|
||||
To remedy it just run "sudo apt-get -y update" again or take a look at this site for additional commands to run in case the first does not work ([http://penreturns.rc.my/2012/02/could-not-get-lock-varlibaptlistslock.html][13]).
|
||||
|
||||
Once both of those updating commands have been successfully executed we now need to install Python, NumPy/SciPy, matplotlib, pandas, scikit-learn and IPython. We will start by installing the Python development packages and compilers needed to compile all of the software:
|
||||
|
||||
sudo apt-get install python-pip python-dev python2.7-dev build-essential liblapack-dev libblas-dev
|
||||
|
||||
Once the necessary packages are installed we can go ahead and install NumPy via pip, the Python package manager. Pip will download a zip file of the package and then compile it from the source code for us. Bear in mind that it will take some time to compile, probably 10-20 minutes!
|
||||
|
||||
sudo pip install numpy
|
||||
|
||||
Once NumPy has been installed we need to check that it works before proceeding. If you look in the terminal you'll see your username followed by your computer name. In my case it is `mhallsmoore@algobox`, which is followed by the prompt. At the prompt type `python` and then try importing NumPy. We will test that it works by calculating the mean average of a list:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import numpy
|
||||
>>> from numpy import mean
|
||||
>>> mean([1,2,3])
|
||||
2.0
|
||||
>>> exit()
|
||||
|
||||
Now that NumPy has been successfully installed we want to install the Python Scientific library known as SciPy. However it has a few package dependencies of its own including the ATLAS library and the GNU Fortran compiler:
|
||||
|
||||
sudo apt-get install libatlas-base-dev gfortran
|
||||
|
||||
We are ready to install SciPy now, with pip. This will take quite a long time (approx 20 minutes, depending upon your computer) so it might be worth going and grabbing a coffee:
|
||||
|
||||
sudo pip install scipy
|
||||
|
||||
Phew! SciPy has now been installed. Let's test it out by calculating the standard deviation of a list of integers:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import scipy
|
||||
>>> from scipy import std
|
||||
>>> std([1,2,3])
|
||||
0.81649658092772603
|
||||
>>> exit()
|
||||
|
||||
Next we need to install the dependency packages for matplotlib, the Python graphing library. Since matplotlib is a Python package, we cannot use pip to install the underlying libraries for working with PNGs, JPEGs and freetype fonts, so we need Ubuntu to install them for us:
|
||||
|
||||
sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev
|
||||
|
||||
Now we can install matplotlib:
|
||||
|
||||
sudo pip install matplotlib
|
||||
|
||||
We're now going to install the data analysis and machine learning libraries pandas and scikit-learn. We don't need any additional dependencies at this stage as they're covered by NumPy and SciPy:
|
||||
|
||||
sudo pip install -U scikit-learn
|
||||
sudo pip install pandas
|
||||
|
||||
We should test scikit-learn:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from sklearn load datasets
|
||||
>>> iris = datasets.load_iris()
|
||||
>>> iris
|
||||
..
|
||||
..
|
||||
'petal width (cm)']}
|
||||
>>>
|
||||
|
||||
In addition, we should also test pandas:
|
||||
|
||||
>>> from pandas import DataFrame
|
||||
>>> pd = DataFrame()
|
||||
>>> pd
|
||||
Empty DataFrame
|
||||
Columns: []
|
||||
Index: []
|
||||
>>> exit()
|
||||
|
||||
Finally, we want to instal IPython. This is an interactive Python interpreter that provides a significantly more streamlined workflow compared to using the standard Python console. In later tutorials I will outline the full usefulness of IPython for algorithmic trading development:
|
||||
|
||||
sudo pip install ipython
|
||||
|
||||
While IPython is sufficiently useful on its own, it can be made even more powerful by including the qtconsole, which provides the ability to inline matplotlib visualisations. However, it takes a little bit more work to get this up and running.
|
||||
|
||||
First, we need to install the the [Qt library][14]. For this you may need to update your packages again (I did!):
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
Now we can install Qt:
|
||||
|
||||
sudo apt-get install libqt4-core libqt4-gui libqt4-dev
|
||||
|
||||
The qtconsole has a few additional packages, namely the ZMQ and Pygments libraries:
|
||||
|
||||
sudo apt-get install libzmq-dev
|
||||
sudo pip install pyzmq
|
||||
sudo pip install pygments
|
||||
|
||||
Finally we are ready to launch IPython with the qtconsole:
|
||||
|
||||
ipython qtconsole --pylab=inline
|
||||
|
||||
Then we can make a (rather simple!) plot by typing the following commands (I've included the IPython numbered input/outut which you do not need to type):
|
||||
|
||||
In [1]: x=np.array([1,2,3])
|
||||
|
||||
In [2]: plot(x)
|
||||
Out[2]: [<matplotlib.lines.Line2D at 0x392a1d0>]
|
||||
|
||||
This produces the following inline chart:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0023.png)
|
||||
|
||||
*IPython with qtconsole displaying an inline chart*
|
||||
|
||||
That's it for the installation procedure. We now have an extremely robust, efficient and interactive algorithmic trading research environment at our fingertips. In subsequent articles I will be detailing how IPython, matplotlib, pandas and scikit-learn can be combined to successfully research and backtest quantitative trading strategies in a straightforward manner.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://quantstart.com/articles/Installing-a-Desktop-Algorithmic-Trading-Research-Environment-using-Ubuntu-Linux-and-Python
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
[1]:https://www.virtualbox.org/
|
||||
[2]:http://www.ubuntu.com/desktop
|
||||
[3]:http://python.org/
|
||||
[4]:http://www.numpy.org/
|
||||
[5]:http://www.scipy.org/
|
||||
[6]:http://ipython.org/
|
||||
[7]:http://matplotlib.org/
|
||||
[8]:http://pandas.pydata.org/
|
||||
[9]:http://scikit-learn.org/
|
||||
[10]:http://quantstart.com/articles/Securities-Master-Database-with-MySQL-and-Python
|
||||
[11]:http://www.ubuntu.com/desktop
|
||||
[12]:https://www.virtualbox.org/
|
||||
[13]:http://penreturns.rc.my/2012/02/could-not-get-lock-varlibaptlistslock.html
|
||||
[14]:http://qt-project.org/downloads
|
@ -0,0 +1,301 @@
|
||||
在Ubuntu下用Python搭建桌面算法交易研究环境
|
||||
================================================================================
|
||||
这篇文章将讨论在ubuntu下,使用Python编程语言,来搭建一个强大,高效和易交互的算法交易策略研究环境.几乎所有的后续的算法交易文章都将利用此环境.
|
||||
|
||||
搭建此环境需要安装以下软件,它们都是开源的或免费下载的:
|
||||
|
||||
- [Oracle VirtualBox][1] - 虚拟机
|
||||
- [Ubuntu Desktop Linux][2] - 作为我们的虚拟操作系统
|
||||
- [Python][3] - 核心编程环境
|
||||
- [NumPy][4]/[SciPy][5] - 快速、高效的数组和矩阵运算
|
||||
- [IPython][6] - Python的可视化交互环境
|
||||
- [matplotlib][7] - 图形化的虚拟数据
|
||||
- [pandas][8] - 数据“冲突”和时间序列分析
|
||||
- [scikit-learn][9] - 机器学习和人工智能算法
|
||||
|
||||
这些工具(配合合适的 [证券master数据库][10]),将使我们能够创建一个快速可交互的策略研究环境。Pandas是专为数据“冲突”设计的,它可以高效地导入和清洗时间序列数据。NumPy/SciPy在底层运行,使得系统被很好的优化。IPython/matplotlib (和qtconsole,详见下文)使结果可视化可交互并快速迭代。scikit-learn可让我们将机器学习技术应用到我们的策略中,以进一步提高性能。
|
||||
|
||||
请注意,我写这篇教程是为了那些无法或不愿意直接安装ubuntu系统的windows或Mac OSX用户,通过VirtualBox来搭建此环境。VirtualBox使我们可在host操作系统中创建一个虚拟机,可模拟guest操作系统,而丝毫不影响host操作系统。由此我们可以在完整安装Ubuntu前练习Ubuntu和Python工具。如果已经安装Ubuntu桌面系统,可跳过“在Ubuntu下安装Python研究环境包”这一节。
|
||||
|
||||
##安装VirtualBoX和Ubuntu##
|
||||
|
||||
Mac OSX操作系统上关于VirtualBox安装的部分已经写过了,这里将简单的移到Windows环境中。一旦各种host操作系统下的VirtualBox安装完毕,其它过程就都一样了。
|
||||
|
||||
开始安装前,我们需要先下载Ubuntu和VirtualBox。
|
||||
|
||||
**下载Ubuntu桌面磁盘镜像**
|
||||
|
||||
打开收藏夹,导航到[Ubuntu 桌面][11]主页,然后选择Ubuntu 13.04:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0004.png)
|
||||
|
||||
*下载Ubuntu13.04(64位(如适用))*
|
||||
|
||||
你会被问及是否愿意捐赠一些money,不过这个是可选的。进入下载页面后选择Ubuntu 13.04。你需要选择是否要下载32位或64位版本。很可能你是64位系统,但如果你有疑问,那么选择32位。在Mac OSX系统上,Ubuntu桌面ISO磁盘镜像将保存到下载目录下。安装VirtualBox后我们就要用到它了。
|
||||
|
||||
|
||||
**下载和安装VirtualBox**
|
||||
|
||||
现在,我们已经下载了Ubuntu ,接下来需要去获取最新版本的Oracle的VirtualBox软件。点击[这里][12]访问该网站,选择你的特定主机的版本(本教程要求Mac OSX版本)
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0002.png)
|
||||
|
||||
*Oracle VirtualBox下载页面*
|
||||
|
||||
一旦文件下载完毕,我们点击安装包图标运行(Windows上会有些不同,但是类似):
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0007.png)
|
||||
|
||||
*双击安装包图标,安装VirtualBox*
|
||||
|
||||
打开后,按照安装说明操作,保持默认(除非你觉得有必要修改他们!)。VirtualBox安装完毕后,可从Applications文件夹中打开(可通过Finder搜索到)。VirtualBox运行过程中它的图标将出现在Dock栏里,如果你以后想经常以虚拟机方式使用Ubuntu,你可以将VirtualBox图标永久保存在Dock栏中:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0008.png)
|
||||
|
||||
*还没有磁盘镜像的VirtualBox*
|
||||
|
||||
点击类似齿轮的图标,创建一个新的虚拟盒子(也就是虚拟机),命名为"Ubuntu Desktop 13.04 Algorithmic Trading"(你可以使用别的类似的描述):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0009.png)
|
||||
|
||||
*命名我们的新虚拟环境*
|
||||
|
||||
分配虚拟机内存.因为是测试系统,所以我只分配了512Mb.一个实际的回溯引擎因为效率原因需要一个本地安装(这样才能明显分配到更多内存):
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0010.png)
|
||||
|
||||
*选择虚拟磁盘的RAM量*
|
||||
|
||||
创建虚拟硬盘,大小为推荐的8Gb,动态生成VirtualBox磁盘镜像,名字同上:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0011.png)
|
||||
|
||||
*选择镜像所使用的硬盘类型*
|
||||
|
||||
You will now see a complete system with listed details:
|
||||
完整系统的详细信息如下:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0012.png)
|
||||
|
||||
*已经创建的虚拟镜像*
|
||||
|
||||
现在我们需要在VirtualBox中为新的磁盘镜像包含一个虚拟的'CD驱动器',这样就可以假装从这张光盘驱动器引导我们的Ubuntu磁盘镜像。在Settings里点击“Storage”选项卡,并添加一个磁盘。选择Downloads目录下的Ubuntu磁盘镜像ISO文件(或者其他你下载Ubuntu的目录),选择Ubuntu ISO镜像,并保存设置。
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0014.png)
|
||||
|
||||
*在第一次启动时选择Ubuntu桌面ISO*
|
||||
|
||||
一切就绪,准备启动Ubuntu镜像并安装。点击“Start”,当出现主机捕获鼠标或键盘消息时点击“Ok”。在我的Mac OSX系统中,主机捕获键是左边的Cmd键(即左Apple键)。现在出现在你眼前的就是Ubuntu桌面安装界面,点击“Install Ubuntu”:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0015.png)
|
||||
|
||||
*点击 "Install Ubuntu "开始安装*
|
||||
|
||||
确保勾选两个框,安装专有的MP3和Wi-Fi驱动程序:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0016.png)
|
||||
|
||||
*安装MP3和Wi-Fi的专用驱动程序*
|
||||
|
||||
现在,您将看到一个界面,询问你想如何保存操作系统创建过程中的的数据。不要惊慌于“Erase Disk and Install Ubuntu”的选项。这并不意味着它会删除你的普通硬盘!它实际上指的是运行Ubuntu的虚拟磁盘,这是安全擦除(反正里面没有什么内容,因为是我们刚刚创建的)。继续进行安装,将出现询问位置的界面,随后,又将出现选择键盘布局的界面:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0017.png)
|
||||
|
||||
*选择您所在的地理位置*
|
||||
|
||||
输入您的用户凭据,请务必记住您的密码,以后安装软件包的时候需要它:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0018.png)
|
||||
|
||||
*输入您的用户名和密码(此密码是管理员密码)*
|
||||
|
||||
现在, Ubuntu将安装文件。它应该是比较快的,因为它是从硬盘复制到硬盘!完成后VirtualBox将重启。如果不自行重启,你可以去菜单强制关机。接下来将回到Ubuntu的登录界面:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0019.png)
|
||||
|
||||
*Ubuntu桌面登录界面*
|
||||
|
||||
用您的用户名和密码登录,你将看到闪亮的新的Ubuntu桌面:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0020.png)
|
||||
|
||||
*Ubuntu桌面登录后的整体界面*
|
||||
|
||||
最后需要做的事是点击火狐图标,通过访问一个网站(我选择QuantStart.com,有意思吧!),来测试互联网/网络功能是正确的:
|
||||
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0021.png)
|
||||
|
||||
*Ubuntu中的火狐浏览器(注:原文此处为"The Ubuntu Desktop login screen")*
|
||||
|
||||
现在Ubuntu桌面已经安装完毕,接下来,我们就可以开始安装的算法交易研究环境软件包。
|
||||
|
||||
## Installing the Python Research Environment Packages on Ubuntu ## 在Ubuntu上安装Python研究环境软件包
|
||||
|
||||
点击左上角的搜索按钮,在输入框里输入“Terminal”,弹出命令行界面。双击终端图标启动终端:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0022.png)
|
||||
|
||||
**Ubuntu中的终端界面(注:原文此处为"Ubuntu Desktop login screen")*
|
||||
|
||||
所有后续的命令都在此终端输入。
|
||||
|
||||
任何崭新的Ubuntu Linux系统上做的第一件事就是更新和升级软件包。前者告诉Ubuntu可用的新软件包有哪些,后者用新版的软件包替换旧版的。运行下列命令(你将被提示输入您的密码) :
|
||||
|
||||
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y upgrade
|
||||
|
||||
*-y前缀告诉Ubuntu接受所有回答“是/否”的问题为'是'。 “sudo”是一个Ubuntu/Debian Linux的命令,允许以管理员权限执行其他命令。由于我们将在站点范围安装软件包,我们需要机器的root权限,因此必须使用'sudo'*
|
||||
|
||||
你可能会在这里得到一个错误消息:
|
||||
|
||||
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
|
||||
|
||||
为了解决这个问题,你只需再次运行"sudo apt-get -y update"或者万一第一种方式不起作用,你可以在该站点([http://penreturns.rc.my/2012/02/could-not-get-lock-varlibaptlistslock.html][13])上查看是否有其他的命令。
|
||||
|
||||
一旦这些更新命令成功执行,接下来我们需要安装Python,NumPy/SciPy,matplotlib,pandas,scikit-learn和IPython。我们将开始安装Python开发包和编译器,编译器将在编译所有软件的时候用到:
|
||||
|
||||
sudo apt-get install python-pip python-dev python2.7-dev build-essential liblapack-dev libblas-dev
|
||||
|
||||
一旦安装必要的软件包,我们就可以通过pip,即Python包管理器,安装NumPy的。pip将下载NumPy的zip包,然后从源代码编译。请记住,编译需要花费一些时间,大概10-20分钟!
|
||||
|
||||
sudo pip install numpy
|
||||
|
||||
NumPy安装完了后,我们需要在继续之前检查它是否可用。如果你仔细看终端,你会发现计算机名后面跟了你的用户名。比如我的是`mhallsmoore@algobox`,随后是提示符。在提示符下键入`python`,然后试着导入NumPy。我们将计算一个列表的平均值,以测试NumPy是否可用:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import numpy
|
||||
>>> from numpy import mean
|
||||
>>> mean([1,2,3])
|
||||
2.0
|
||||
>>> exit()
|
||||
|
||||
现在,我们已成功安装NumPy,接下来要安装Python的科学库,即SciPy。然而,它有一些依赖的软件包,包括ATLAS库和GNU Fortran编译器:
|
||||
|
||||
sudo apt-get install libatlas-base-dev gfortran
|
||||
|
||||
现在,我们将通过pip安装SciPy.这将需要相当长的时间(约20分钟,这取决于你的电脑),所以也许你可以去喝杯咖啡先:
|
||||
|
||||
sudo pip install scipy
|
||||
|
||||
唷!现在已安装SciPy。让我们通过计算一个整数列表的标准差来测试SciPy是否可以正常使用:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import scipy
|
||||
>>> from scipy import std
|
||||
>>> std([1,2,3])
|
||||
0.81649658092772603
|
||||
>>> exit()
|
||||
|
||||
接下来我们需要安装matplotlib的依赖包,Python的图形库。 由于matplotlib是一个Python包,无法使用pip去安装以下PNG,JPEG文件和FreeType字体库相关的库,所以我们需要Ubuntu为我们安装:
|
||||
|
||||
sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev
|
||||
|
||||
现在我们可以安装matplotlib了:
|
||||
|
||||
sudo pip install matplotlib
|
||||
|
||||
我们将安装数据分析和机器学习库,pandas和scikit-learn.这步不需要安装额外的依赖库, 因为NumPy和SciPy已经将依赖都覆盖了.
|
||||
|
||||
sudo pip install -U scikit-learn
|
||||
sudo pip install pandas
|
||||
|
||||
我需要测试scikit-learn:
|
||||
|
||||
mhallsmoore@algobox:~$ python
|
||||
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
|
||||
[GCC 4.7.3] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from sklearn load datasets
|
||||
>>> iris = datasets.load_iris()
|
||||
>>> iris
|
||||
..
|
||||
..
|
||||
'petal width (cm)']}
|
||||
>>>
|
||||
|
||||
另外,我们需要测试pandas:
|
||||
|
||||
>>> from pandas import DataFrame
|
||||
>>> pd = DataFrame()
|
||||
>>> pd
|
||||
Empty DataFrame
|
||||
Columns: []
|
||||
Index: []
|
||||
>>> exit()
|
||||
|
||||
最后, 我们需要安装IPython.这是一个交互式的Python解释器,它提供了一个更精简的工作流相比标准的Python控制台。在以后的教程中,我将讲述IPython在算法交易开发中的充分的用处:
|
||||
|
||||
sudo pip install ipython
|
||||
|
||||
虽然IPython本身已经相当有用,但它通过包含qtconsole可以有更强大的能力,qtconsole提供了内联matplotlib可视化的能力。尽管如此,它需要多一点点的工作以使它启动和运行。
|
||||
|
||||
首先,我们需要安装[Qt库][14]。对于这一点,你可能需要更新你的软件包(我做了!):
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
现在我们可以安装Qt了:
|
||||
|
||||
sudo apt-get install libqt4-core libqt4-gui libqt4-dev
|
||||
|
||||
qtconsole有一些附加的包,即ZMQ和Pygments库:
|
||||
|
||||
sudo apt-get install libzmq-dev
|
||||
sudo pip install pyzmq
|
||||
sudo pip install pygments
|
||||
|
||||
最后我们准备启动带有qtconsole的IPython:
|
||||
|
||||
ipython qtconsole --pylab=inline
|
||||
|
||||
然后我们可以做一个图(非常简单的!), 键入下列命令(我已经包含了IPython编号的输入/输出,你不需要再输入):
|
||||
|
||||
In [1]: x=np.array([1,2,3])
|
||||
|
||||
In [2]: plot(x)
|
||||
Out[2]: [<matplotlib.lines.Line2D at 0x392a1d0>]
|
||||
|
||||
这将产生以下内嵌图表:
|
||||
|
||||
![](https://s3.amazonaws.com/quantstart/media/images/qs-python-ubuntu-install-0023.png)
|
||||
|
||||
*带有qtconsole的IPython显示一幅内嵌的图表*
|
||||
|
||||
这就是它的安装过程。现在,我们手头就有一个非常强大的,高效和互动的算法交易的科研环境。我会在后续的文章中详细介绍如何结合IPython,matplotlib,pandas和scikit-learn,以一种直观的方式, 成功地研究和回溯测试量化交易策略。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
来源于: http://quantstart.com/articles/Installing-a-Desktop-Algorithmic-Trading-Research-Environment-using-Ubuntu-Linux-and-Python
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
译者:[coolpigs](https://github.com/coolpigs) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
[1]:https://www.virtualbox.org/
|
||||
[2]:http://www.ubuntu.com/desktop
|
||||
[3]:http://python.org/
|
||||
[4]:http://www.numpy.org/
|
||||
[5]:http://www.scipy.org/
|
||||
[6]:http://ipython.org/
|
||||
[7]:http://matplotlib.org/
|
||||
[8]:http://pandas.pydata.org/
|
||||
[9]:http://scikit-learn.org/
|
||||
[10]:http://quantstart.com/articles/Securities-Master-Database-with-MySQL-and-Python
|
||||
[11]:http://www.ubuntu.com/desktop
|
||||
[12]:https://www.virtualbox.org/
|
||||
[13]:http://penreturns.rc.my/2012/02/could-not-get-lock-varlibaptlistslock.html
|
||||
[14]:http://qt-project.org/downloads
|
Loading…
Reference in New Issue
Block a user