matt's notes

Posts tagged quant stuff

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…..