Downloading Stock Market Data to a Google Spreadsheet with a Perl Script

In this post will be shown how to download stock market with perl script into Google spreadsheet. Once the data is loaded in Google spreadsheet you can do trend or forecasting analysis and build charts using Google Docs functionality.

Perl script helps to automate downloading process, to replace manual downloading process with just one command to run script. The proposed perl script is using perl module Finance::QuoteHist.

Here is the example how you can get stock data using this module: use Finance::QuoteHist;
$q = Finance::QuoteHist->new ( symbols => [qw(IBM UPS AMZN)], start_date => ‘8/18/2013’, end_date => ‘today’, );

Now you just iterate through each row and do what you need to do with the data:

foreach $row ($q->quotes()) { ($symbol, $date, $open, $high, $low, $close, $volume) = @$row; }

In this example you will get data for 3 companies with the stock symbols IBM, UPS, AMZN. Below is the full code example showing how to download and save data to Google spreadsheets. To use it you need replace stock symbols and Google spreadsheet names with the actual names.
Also you need to put actual Google account username and password. The script is assuming that spreadsheet document is already created on Google Drive and has enough columns and rows to put data. In other words before running perl script add enough rows and columns to spreadsheet where the data will be saved.

Here is the link for free financial data from Chart Oasis in case you need more data Download free market data of stocks, indices, commodities and forex

use Finance::QuoteHist;
$q = Finance::QuoteHist->new ( symbols => [qw(IBM UPS AMZN)], start_date => ‘8/18/2013’, end_date => ‘today’, );
$count=0;
foreach $row ($q->quotes()) { ($symbol, $date, $open, $high, $low, $close, $volume) = @$row; print “$symbol, $date, $open, $high, $low, $close, $volume \n”;
$data[$count][0]=$symbol;
$data[$count][1]=$date;
$data[$count][2]=$open;
$data[$count][3]=$high;
$data[$count][4]=$low;
$data[$count][5]=$close;
$data[$count][6]=$volume;
$count=$count+1; }

use Net::Google::Spreadsheets;
my $service = Net::Google::Spreadsheets->new( username => ‘xxxxxxx’, password => ‘xxxxxxx’ );
my @spreadsheets = $service->spreadsheets();
my $spreadsheet = $service->spreadsheet( { title => ‘put_actual_title_here’ } );
my $worksheet1 = $spreadsheet->worksheet( { title => ‘put_actual_title_here’ } );
$cell = $worksheet1->cell({col => 1, row => 1}); $cell->input_value(“symbol”);
$cell = $worksheet1->cell({col => 2, row => 1}); $cell->input_value(“date”);
$cell = $worksheet1->cell({col => 3, row => 1}); $cell->input_value(“open”);
$cell = $worksheet1->cell({col => 4, row => 1}); $cell->input_value(“high”);
$cell = $worksheet1->cell({col => 5, row => 1}); $cell->input_value(“low”);
$cell = $worksheet1->cell({col => 6, row => 1}); $cell->input_value(“close”);
$cell = $worksheet1->cell({col => 7, row => 1}); $cell->input_value(“volume”);
for($i=2; $i<$count+2; $i++) { for($j=1; $j<8; $j++) { $cell = $worksheet1->cell({col => $j, row => $i}); $cell->input_value($data[$i-2][$j-1]); } }



5 Ways of Web User Modeling

Web user modeling can be done in many different ways. Below will be described some of them and will be provided the links to the resources.

One of the way of modeling web user behavior is to use Markov chains. This theory allows us to find the probability of clicking available links if we know the transition matrix. Elements of this matrix are the probabilities of moving from page i to page j

Clustering is the assignment of group of objects into subgroups (clusters) based on some metric. This can be also used to cluster users into some subgroups and then we can compare new user path with the cluster which is the most close to this user. More detailed description of clustering is provided at [1]

Vector space models use similarity to compare user data. Each user can be represented by visited pages, by some keywords from visited pages or some other data. With this model the user is represented as the vector in the vector space. Some perl code and examples for vector space modeling can be found at [2]

Soft computing like neural networks, genetic algorithm, swarm intelligence and many other heuristic or AI methods also can be used for web user modeling. [3] provides taxonomy for personalization of web-based systems by CI models. Collaborative filtering is a method of making automatic predictions (filtering) about the interests of a user by collecting taste information from many users (collaborating). [4]

Different types and many algorithms are described on Wikipedia site. Thus there are many ways to do web user modeling. This post provides some ideas and links to resources that can be used as the starting point.

References

1.Cluster Analysis, From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Cluster_analysis

2. http://www.lwebzem.com/cgi-bin/res/user_modeling_1.cgi Website User Modeling with Perl

3. RECENT ADVANCES in COMPUTER ENGINEERING and APPLICATIONS Personalization of Web-Based Systems based on Computational Intelligence Modeling TRICIA RAMBHAROSE, ALEXANDER NIKOV

4 Collaborative filtering, From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Collaborative_filtering



Cloud Computing

Cloud computing is the use of computing resources (hardware and software) that are delivered as a service over a network (typically the Internet). The name comes from the use of a cloud-shaped symbol as an abstraction for the complex infrastructure it contains in system diagrams.

Cloud computing entrusts remote services with a user’s data, software and computation.[1]

Example of cloud service is Google Cloud Storage which allows store, access and manage your data on Google’s storage infrastructure. The good description of the cloud computing is posted on Technology Cloud Blog [2]. It has also a list of some cloud services.

There are also cloud services that provide ability to develop programming applications. For example dotcloud.com allows to build your ideal application stack by combining powerful cloud services. You do need to pay for development. You start to pay only when you deploy your application. Developers can use PHP, PERL, Python, Ruby, MYSQL and other applications. Artificial Intelligence services in the cloud also can be found: Google provides prediction API which is cloud-based set of machine-learning tools that can help you analyze the data.

Another cloud service is Data Applied, a web based data mining environment. As stated on their site “Data Applied revolutionizes data-driven decision making by integrating rich analytics, data mining, and information visualization capabilities”

References

1.Cloud computing From Wikipedia, the free encyclopedia

2.What is in the Cloud ?

3.dotCloud

4.Cloud Computing

5.Turn on Google’s Prediction API for simple, AI in the cloud

6.Data Applied



Maze Games with Perl Modules from CPAN

As stated on CPAN [1] the perl module Games::Maze creates mazes. You can create 3-dimensional rectangular or hexagonal mazes and then manipulate maze objects using the available methods.

This module has to_ascii() method that allows to print maze view from command prompt or get the string which will describe the maze. The new line in this string will separate rows of the maze. The walls will be marked some characters like underscore and “:”.

There is also another module Games::Maze::SVG [2] which can build mazes in SVG using Games::Maze. The Games::Maze::SVG module supports the creation of 2-dimensional mazes in an SVG format suitable for printing or playing interactively.

So if you like creating maze perl has modules to make this job very easy.

1.Games::Maze

2.Games::Maze::SVG



Bollinger Bands

Bollinger Bands – are advanced technical indicators that consist of three curves: [1]
1. an N-period moving average (MA). Usually simple moving average (SMA)
2. an upper band at K times an N-period standard deviation above the moving average (MA + Kσ), K is usually 2 and N is usually 20 days.
3. a lower band at K times an N-period standard deviation below the moving average (MA − Kσ)

SMA smoothes a data series and makes analyzing volatile data easier. There are different types of MA:
Exponential Moving Average
Simple Moving Average
Triangular Moving Average
Weighted Moving Average
Triple Exponential Moving Average

You can find how to calculate the above MAs at [2]. Bollinger Bands provide a relative definition of high and low. Stockcharts.com has explanation article how to use Bollinger Bands. It also shows examples of signals.

So what follows from many articles about Bollinger Bands that Bollinger Bands technical indicators are powerful tool for technical analysis. If you are interesting to calculate Bollinger Bands in MS Excel you can use instructions for formulas in [5].

References:

1. Bollinger Bands From Wikipedia, the free encyclopedia

2. Moving Averages

3. Advanced Technical Indicators – Bollinger Bands

4. Bollinger Bands

5. Bollinger Band Calculation in MSExcel