matt's notes

Feb 26

Excellent Scraping/Form Posting/Mining Mechanize Examples/Scripts (that Work!!!))) hehe

WWW::Mechanize examples
Google
require ‘rubygems’
require ‘mechanize’

agent = WWW::Mechanize.new
agent.user_agent_alias = ‘Mac Safari’
page = agent.get(“http://www.google.com/”)
search_form = page.forms.with.name(“f”).first
search_form.q = “Hello”
search_results = agent.submit(search_form)
puts search_results.body
Rubyforge
require ‘mechanize’

agent = WWW::Mechanize.new
page = agent.get(‘http://rubyforge.org/’)
link = page.links.text(/Log In/)
page = agent.click(link)
form = page.forms[1]
form.form_loginname = ARGV[0]
form.form_pw = ARGV[1]
page = agent.submit(form, form.buttons.first)

puts page.body
File Upload
This example uploads one image as two different images to flickr.
require ‘rubygems’
require ‘mechanize’

agent = WWW::Mechanize.new

# Get the flickr sign in page
page = agent.get(‘http://flickr.com/signin/flickr/’)

# Fill out the login form
form = page.forms.name(‘flickrloginform’).first
form.email = ARGV[0]
form.password = ARGV[1]
page = agent.submit(form)

# Go to the upload page
page = agent.click page.links.text(‘Upload’)

# Fill out the form
form = page.forms.action(‘/photos_upload_process.gne’).first
form.file_uploads.name(‘file1’).first.file_name = ARGV[2]
agent.submit(form)
Pluggable Parsers
Lets say you want html pages to automatically be parsed with Rubyful Soup. This example shows you how:
require ‘rubygems’
require ‘mechanize’
require ‘rubyful_soup’

class SoupParser e
$stderr.puts “#{e.class}: #{e.message}”
end
end
end
end

TestMech.new.process


Jan 14
[Flash 9 is required to listen to audio.]

Jan 12
[Flash 9 is required to listen to audio.]

Synthetic wants look and feel like the one’s from the past.

(?) To diffuse an argument, you must cut the red wire first. It is possible for what some people to find interesting, others may not like. Emergency Dogs may be called throughout the day to provide extra power whenever neccessary =)


Jan 10
“The new model is: to start a very small fund; to include a significant amount of the general partners own money; to make small investments in capital efficient businesses which can become profitable early and with no more than a couple of million dollars; and to pay the general partner exclusively with carried interest after the principal have been returned to the investors. Such startup opportunities exist and are ignored by the big fund coupon clippers. If you can find such a fund, with good solid partners, you can still make a (smaller) investment with a reasonable expectation of an appropriate return.”

this is spot on

The Twilight of Venture Capital

(via fred-wilson)

Oct 11

Fair value and limit book spreads and confirmation of what I suspected…

http://mediaserver.thinkorswim.com/transcripts/102506_Penny_Pricing_and_Index_Options.mp3

This guy is talking about how retail customer limit orders frequently adjust and move ask/bid marks and fair value calculations, etc… (because of mid-value between bid/ask) —— I have realized this myself frequently in the past month.

This is back from 2006, but it is still relevant information I think. It confirms my thinking that my limit orders can effect bid/asks in the limit book, and also the calculations performed on them (since a lot of the time a mid-point is used between the bid/ask to base them on). Anyway, it is talked about and hit on a little bit for a second I think right around half way through the entire talk….

I am not sure who this guy is talking yet, but he is very good and has a very great perspective from (from my interpretation at least) the larger institutional / market maker end perspective) … which I am becoming very obsessed in…


Oct 10

An interesting strategy I found in TOS Orderbook

I wouldn’t use these prices, but the Trailing stop up and conditional RIMM price is a strategy that I have been thinking about, but especially, I wouldn’t execute a trade like this without first having it check that it’s above it’s low trade or within x range of it’s high or something… etc… But yeah, just noting this so I can remember it later.

(Actually everything on here that I post to remember later, I have never looked at - I need to organize this stuff.) Argh. Tried using a wiki but I always lose it or forget where it’s installed at and make another. So at least I can’t delete this by accident. :)

1. Wait until the following condition is satisfied: RIMM MARK AT OR ABOVE 70.01. This order will show a WAIT COND status during waiting;

2. Submit the following order: BUY +23 VERTICAL RIMM 100 OCT 08 70 CALL TRAIL STOP LIMIT.

This order contains both a TRAIL STOP and a LIMIT price. The LIMIT order is submitted when the TRAIL STOP component is triggered. The TRAIL STOP is triggered when the bid price is at or above the calculated TRAIL STOP price. The trail stop price is calculated from the market ask of the security when the order is submitted plus +1.10. The trail stop price is continually updated if and when the bid price moves lower, but does not change if the bid price moves up. That is, the trail stop price is automatically adjusted when the bid price moves in a “favorable” direction. The LIMIT order is to execute at the market ask at the LIMIT part activation time or better. This order will show a WAIT STOP status as it waits for the stop to be triggered. The order is valid until it is either filled or cancelled;


Sample data file in ta-lib tests

It’s located in ta-lib-0.4.0-src.tar.gz\ta-lib\src\tools\ta_regtest directory …

Mainly test_data.c, but I am assuming it’s the same data that is written in ta_gDataClose.c, ta_gDataHigh.c, ta_gDataLow.c, and ta_gDataOpen.c — except just contained in one. Didn’t really look though.

But anyway, interesting, I had in mind of analyzing intraday bid/ask/sale data in the same format …… And also, in an uinrelated note, Google Finance’s data is sent across to the browser in a similar format for their real-time as can be Flash-based graphs. If anybody would care then I would love to write more on the subject (actually, more so on other dissections of other more important and serious systems that I’ve been digging in)..


Oct 4

2 more Finance::Quote code examples

#!/usr/bin/perl -w
#
# example script showing how to use the Quote perl module.
# gets prices for some stocks, for some mutual funds
#
# This script was originally part of GnuCash.

use lib '../lib';
use Finance::Quote;

my $q = Finance::Quote->new();

# -----------------------------------
# get quotes for two stocks ...
%quotes = $q->yahoo ("IBM", "SGI"); 

# print some selected values 
print "NYSE by Yahoo: ", $quotes {"IBM", "name"},  
       " last price: ", $quotes {"IBM", "last"},  "\n";
print "NYSE by Yahoo: ", $quotes {"SGI", "name"},   
       " last price: ", $quotes {"SGI", "last"},  "\n";
       
# loop over and print all values.
# Notes that values are stored ion a multi-dimensional associative array
foreach $k (sort (keys %quotes)) {
     ($sym, $attr) = split ($;, $k, 2);
     $val = $quotes {$sym, $attr};
     # $val = $quotes {$k};     # this also works, if desired ...
     print "\t$sym $attr =\t $val\n";
} 
print "\n\n";

# -----------------------------------
# get quotes from Fidelity Investments
@funds = ("FGRIX", "FNMIX", "FASGX", "FCONX");
%quotes = $q->fidelity (@funds);

foreach $f (@funds) {
     $name = $quotes {$f, "name"};
     $nav = $quotes {$f, "nav"};
     print "Fidelity Fund $f $name \tNAV = $nav\n";
}
print "\n\n";

# -----------------------------------
@funds = ("FGRXX");
%quotes = $q->fidelity (@funds);

print "Not all funds have a NAV; some have Yeilds:\n";
foreach $f (@funds) {
     $name = $quotes {$f, "name"};
     $yield = $quotes {$f, "yield"};
     print "\tFidelity $f $name 30-day Yield = $yield percent\n";
}
print "\n\n";

# -----------------------------------
# demo T. Rowe Price -- same as above
@funds = ("PRFDX", "PRIDX");
%quotes = $q->troweprice (@funds);

foreach $f (@funds) {
     $nav = $quotes {$f, "nav"};
     $dayte = $quotes {$f, "date"};
     print "T. Rowe Price $f NAV = $nav as of $dayte\n";
}
print "\n\n";


# -----------------------------------

# demo for ASX.  Grab the price of Coles-Myer and Telstra
@funds = ("CML","TLS");
%quotes = $q->asx(@funds);
foreach $f (@funds) {
	print "ASX Price of $f is ".$quotes{$f,"last"}." at ".
	      $quotes{$f,"date"}."\n";
}
print "\n\n";

# Demo for TIAA-CREF.
@funds = qw/CREFstok BOGOname TIAAreal CREFmony/;
%quotes = $q->tiaacref(@funds);
foreach $f (@funds) {
        if ($quotes{$f,"success"} == 1) {
	print "TIAA-CREF Price of ".$quotes{$f,"name"}." is ".$quotes{$f,"nav"}.
              " at ".$quotes{$f,"date"}."\n";
	} else {
	print "Error: ".$quotes{$f,"errormsg"}." for ".$f."\n";
	}
}
print "\n\n";


#!/usr/bin/perl -w
use strict;
use lib '../lib';
use Finance::Quote qw/asx/;

=head1 NAME

chkshares.pl - Check share information.

=head1 USAGE

chkshares.pl australia TLS CML ITE

=head1 NOTES

Example program.  Demonstrates how to use one of the interface to
Finance::Quote.  The first argument must be the market.

=cut

my ($name, $date, $last, $p_change, $high, $low, $volume, $close);

format STDOUT_TOP =

                                 STOCK REPORT

TICKER         DATE      LAST  %CHANGE       HIGH      LOW    VOLUME     CLOSE
-------------------------------------------------------------------------------
.

format STDOUT =
@<<<<<< @>>>>>>>>>>  @###.### @###.###   @###.### @###.### @>>>>>>>>  @###.###
$name,  $date,       $last,   $p_change, $high,   $low,    $volume,   $close
.

my $quoter = Finance::Quote->new();
my $market = shift || die "Usage: $0 market stocks\n";

my %quote = $quoter->fetch($market,@ARGV);

foreach my $code (@ARGV) {
	unless ($quote{$code,"success"}) {
		warn "Lookup of $code failed - ".$quote{$code,"errormsg"}."\n";
		next;
	}
	$name = $code;
	$date = $quote{$code,'date'};
	$last = $quote{$code,'last'};
	$p_change = $quote{$code,'p_change'};
	$high = $quote{$code,'high'};
	$low = $quote{$code,'low'};
	$volume = $quote{$code,'volume'};
	$close = $quote{$code,'close'};
	write;
}


Finance::Quote example

#!/usr/bin/perl -w
#
# example script showing how to use the Quote perl module.
# gets prices for some stocks, for some mutual funds
#
# This script was originally part of GnuCash.

use lib '../lib';
use Finance::Quote;

my $q = Finance::Quote->new();

# -----------------------------------
# get quotes for two stocks ...
%quotes = $q->yahoo ("IBM", "SGI"); 

# print some selected values 
print "NYSE by Yahoo: ", $quotes {"IBM", "name"},  
       " last price: ", $quotes {"IBM", "last"},  "\n";
print "NYSE by Yahoo: ", $quotes {"SGI", "name"},   
       " last price: ", $quotes {"SGI", "last"},  "\n";
       
# loop over and print all values.
# Notes that values are stored ion a multi-dimensional associative array
foreach $k (sort (keys %quotes)) {
     ($sym, $attr) = split ($;, $k, 2);
     $val = $quotes {$sym, $attr};
     # $val = $quotes {$k};     # this also works, if desired ...
     print "\t$sym $attr =\t $val\n";
} 
print "\n\n";

# -----------------------------------
# get quotes from Fidelity Investments
@funds = ("FGRIX", "FNMIX", "FASGX", "FCONX");
%quotes = $q->fidelity (@funds);

foreach $f (@funds) {
     $name = $quotes {$f, "name"};
     $nav = $quotes {$f, "nav"};
     print "Fidelity Fund $f $name \tNAV = $nav\n";
}
print "\n\n";

# -----------------------------------
@funds = ("FGRXX");
%quotes = $q->fidelity (@funds);

print "Not all funds have a NAV; some have Yeilds:\n";
foreach $f (@funds) {
     $name = $quotes {$f, "name"};
     $yield = $quotes {$f, "yield"};
     print "\tFidelity $f $name 30-day Yield = $yield percent\n";
}
print "\n\n";

# -----------------------------------
# demo T. Rowe Price -- same as above
@funds = ("PRFDX", "PRIDX");
%quotes = $q->troweprice (@funds);

foreach $f (@funds) {
     $nav = $quotes {$f, "nav"};
     $dayte = $quotes {$f, "date"};
     print "T. Rowe Price $f NAV = $nav as of $dayte\n";
}
print "\n\n";


# -----------------------------------

# demo for ASX.  Grab the price of Coles-Myer and Telstra
@funds = ("CML","TLS");
%quotes = $q->asx(@funds);
foreach $f (@funds) {
	print "ASX Price of $f is ".$quotes{$f,"last"}." at ".
	      $quotes{$f,"date"}."\n";
}
print "\n\n";

# Demo for TIAA-CREF.
@funds = qw/CREFstok BOGOname TIAAreal CREFmony/;
%quotes = $q->tiaacref(@funds);
foreach $f (@funds) {
        if ($quotes{$f,"success"} == 1) {
	print "TIAA-CREF Price of ".$quotes{$f,"name"}." is ".$quotes{$f,"nav"}.
              " at ".$quotes{$f,"date"}."\n";
	} else {
	print "Error: ".$quotes{$f,"errormsg"}." for ".$f."\n";
	}
}
print "\n\n";





Rpad is REALLY cool

Rpad is an interactive, web-based analysis program. Rpad pages are interactive workbook-type sheets based on R, an open-source implementation of the S language. Rpad is an analysis package, a web-page designer, and a gui designer all wrapped in one. Rpad makes it easy to develop powerful data analysis applications that can be shared with others (most likely on an intranet). The user doesn’t have to install anything—everything’s done through a browser.

It uses DOJO!  By far the greatest usage of it that I’ve ever seen. This is a great application, I’m 100% sure playing and (possibly) expanding on this is going to fill up a huge chunk of my time in the short term…………

And also, check out Quantian - it is a live linux cd that includes Rpad as well as A LOT of other relevant analytic/stat/calc tools…..


Trading Research Analyst
San Francisco, CA

Barclays Global Investors (BGI) is America’s largest money manager,
providing structured investment strategies such as indexing,
risk-controlled active products, and exchange traded funds to investors
worldwide. For 35 years, BGI has been at the forefront of developing
innovative investment ideas, applying science and technology to the
investment process. Headquartered in San Francisco and winning first
place in the SF Business Times’ ”Best Places to Work in the Bay Area
2008” Awards (Large Companies category), the Barclays PLC subsidiary
employs over 3,700 people globally and manages approximately $2 trillion
in assets.

Overview

As one of the largest asset managers, BGI is a top-three holder in every
security resulting in the need to be extremely careful around how it
enters and exits investments so as not to move the market or erode its
alpha signals. BGI’s answer to this problem is its unique Global Trading
Research team and its implementation of electronic trading strategies.

We use a highly customized version of a third party vendor product
called FlexTrader to implement trading signals and strategies for the
equity and currency trading teams. This is a high profile group where
we are in a position to directly impact the performance of our funds by
providing tools for traders to make intelligent decisions on trade
timing and strategy. Working market hours and sitting on the trading
floor, Trading Research members are very close to the excitement of the
markets.

We are seeking a new member to join the real time analytics team to not
only help us support and enhance our electronic trading application, but
also to continue to develop innovative tools for our traders. We are
looking to expand across additional asset classes as well as expanding
the depth of our analytics, to implement automatic trading algorithms
using real time statistics on trading signals. The job requires a strong
technical background as well as a basic understanding of the equity
markets.

http://sourceforge.net/mailarchive/forum.php?thread_name=6A3D2E0157CC4C419E94B75A99CAE7FE04A5C2FD%40calnte2k034.insidelive.net&forum_name=quantlib-jobs

Page 1 of 9