Thursday, April 21, 2011

How to load csv data with quantmod in R

In this article I'm going to describe how to load data in an xts object, which is the preferred object to handle time series quantmod from a CSV file. This article is really for beginner (like myself), hopefully those can be helpful to others.

Let's imagine you have some csv data that look like:

First thing you need to make sure is that you column headers have names that contain  Open, High, Low and Close. This will make you life much easier. Secondly, your csv file should only contain dates, and numerical data, otherwise it's kind of a hassle and you have to go and manually convert data afterwards. So  what your data should really look like is:


Personnally I "massaged" the data in R, but you could very well do that in Excel, Perl, Python, or whatever tool you fancy (or simply correct the data at the source ;) ) but for the sake of example this is how I did it:


Now that you have the correct data, it's pretty simple to load :



You're now the proud owner of an xts object that you can start abusing in all the ways you'd like ;)



Hope this helps

Monday, April 18, 2011

How to extract a DEB file

DEB files are ar archives, which contain three files:
  • debian-binary
  • control.tar.gz
  • data.tar.gz
The actual data is contained into data.tar.gz. You can extract it with the following command:
ar p yourfile.deb data.tar.gz | tar xz

Sunday, April 17, 2011

Compiling a linux kernel on a Debian "like" distribution

I recently had to re-compile a kernel, and there's a few preliminaries. You need to install a bunch of packages :

sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
sudo apt-get install kernel-package

After that you can follow the excellent guide here:

One point which I had missed though is where are the packages once you've finished compiling (although it's written in the guide). So if like they recommend in the you've extracted the kernel source under ~/src/linux-source-2.6.35 for instance, then the deb packages will be in ~/src.


Enjoy.

Sunday, April 10, 2011

Edit Formula: Alternative to F2 for Excel Mac


One of the most used keyboard shortcut is F2, which allows to edit the formula in a cell without using the mouse. Unfortunately that shortcut is different between Office for Mac and Office Windows.

This shortcut was F2 in a PC, but in Excel for Mac it turns into Ctrl + U.  Unfortunately not the most effective shortcut, as it's rather difficult to press Ctrl + U with one hand on most keyboards.


Windows Shortcut: F2

Mac Shortcut: Ctrl + U

Excel Mac: Cell Reference Lock - F4 Alternative


One of the first major problem that I faced when I first began using Excel on a Mac, was the appropriate shortcut replacement for F4, which adds $ signs to cell references to lock cell/range references from moving if dragged to another cell. After a great deal of frustration, and after trawling a number of excel forums I eventually found the solution which is shown below.

Windows ShortcutF4

Mac Shortcut : Cmd + T

Install from Perl modules from CPAN without confirmation

If need to install modules from CPAN, especially if you want to install a whole bunch in one go without having to confirm every ten seconds try running your install as follow:


PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'

Additionally if you want to make sure that the install script will pull all the required dependencies (should be by default, but heh ...):



cpan
cpan> o conf prerequisites_policy follow
cpan> o conf commit


That's it.

Tuesday, April 5, 2011

Find closest and fastest repository for your Debian

I recently installed a new distrib with linux mint based on Debian. I've done that scores of times, but one thing i never remember is how to find the best repo (and the fastest of course) based on your location.

There's a very neet package that will do the work for your:
sudo apt-get install netselect-apt
sudo netselect-apt

And Voila, you're done.


Monday, April 4, 2011

Update Debian Squeeze to Mint ~ a.k.a Mintify your Debian

I've been willing to install a new linux for a while, more precisely a Linux Mint distrib for various reasons. Call me lazy i didn't wanted to download and burn a full DVD. So the came the idea to use a Debian install as a base (since there is a version called LMDE base on Debian instead of Ubuntu.

At the time of this post, Debian has recently updated Squeeze to stable, so that the freshly baked Linux Mint isn't too far away (LMDE is supposed to be based on the current testing debian).

If you want to follow the same steps as me, this post assumes a couple of things:

  1. You can and will use command line without fear
  2. You know what debian is and can read log messages or use test installer
  3. You computer is already connected to internet


Some thanks to those two posts which i used as a base and mix together with my own twist:
HOWTO: Create a custom, minimal LMDE install
Mintifying Debian

Enough talk, let's get down to it. First you'll need to download a ISO of Debian, i used the businesscard version. You can find other version fitting to your need / architecture here:
http://www.debian.org/releases/squeeze/debian-installer/

1) Download it, burn it or put it on a USB key, which ever you prefer and install debian.

Once the install is completed, and you've added yourself as a sudoer ,you can proceed.



2) Then you may want to add the contrib and non-free Debian repositories by editing the file /etc/apt/sources.list and adding “contrib non-free” without quotes right at the end of each line ending with “main”.

4) Next you add the Debian Multimedia and the Mint repositories. You can for instance create a file within /etc/apt/sources.list.d called “lmde.list” and add these two lines into it:

deb http://packages.linuxmint.com/ debian main upstream import
deb http://www.debian-multimedia.org squeeze main non-free



5) Updates :

sudo apt-get update
sudo apt-get install linuxmint-keyring
wget -c http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2010.12.26_all.deb
sudo dpkg -i debian-multimedia-keyring_2010.12.26_all.deb
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade



Now the trick start here. Apparently when Squeeze went from testing to stable a particular package called "gstreamer0.10-pitfdll" has been removed from Debian repo cause the all meta package mint-meta-debian to fall to pieces. With some error message that look like:



The following packages have unmet dependencies:
mint-meta-debian : Depends: mint-meta-codecs but it is not going to be installed



The following packages have unmet dependencies:
mint-meta-codecs : Depends: gstreamer0.10-pitfdll but it is not installable
E: Broken packages





But fear not, here's the solution:
wget -c http://debian.securedservers.com/debian/pool/contrib/g/gstreamer0.10-pitfdll/gstreamer0.10-pitfdll_0.9.1.1+cvs20080215-1_i386.deb
dpkg -i gstreamer0.10-pitfdll_0.9.1.1+cvs20080215-1_i386.deb


Now you can safely proceeed to the Mintifying of your debian:
apt-get install mint-meta-debian

Enjoy.