Tuesday, 15 January 2013

Oscillators and Wavelets

And a belated happy new year to all !

There are lots of views on this blog from around the world - if you have any questions or comments please comment or email.

Working hard over the holidays, have got into oscillators and wavelets (coming across Reimann again) and setting this up as I type. My thinking is that I have noticed oscillations within the life span of a stock and I am going to normalise these and then carry out a transform (Fourier like) to get the frequencies and phase, and from these we should be able to produce a reverse transform to produce a time map and compare to the present day.

The system is getting quite complex now and so spending a lot of time documenting and mapping processes.

The tweeting server is now being restricted to the highest grade information - no subsequent repeat days and only greater than 95% Markov probability of success.

Wednesday, 7 November 2012

Candlesticks - burning at both ends

Candlesticks have proven to be pretty complex and really quite interesting. (I've also been on holiday).

The whole premise of Candlesticks is that the relationship between the open, high, low and close of a stock in the previous 2 to 3 periods (days in our case), indicates, through the use of pattern recognition, probabilities of rises.

So my thinking is this:

1. calculate the Markov Chains for each period indicating the:
-1a. 3 open/close situations (3 periods, today, yesterday and the day before and if the open is above or below the close),percentage increase over the subsequent 5 days
-1b. 3 individual indicators stating the usual Candlestick derivatives 
-1c. 2 relative indicators detailing the relationship between the periods
-1d. the percentage increases for the subsequent 5 days

(1b, 1c and 1d taken together with an indicated rise or fall can be thought of as the well known Candlestick indicators that have been observed to indicate  patterns that if popular have been given names (hanging-man lines, dark-cloud covers, evening stars, etc))

2. Calculate the daily Candlestick indicators and compare to the Markov Chains created previously

3. Tweet results

The Markov Chains are currently set at greater than 11.5% rise for greater than 80% of the time for the subsequent 5 days, and yield results such as:

...
72.4         uuu0202020804       BAC           6       100       6       0
81.42       uuu0202021808       BAC           5       100       5       0
88.83       uuu0202021313       NLMA       181       98.34       178       3
33.79       uuu0202021313       IHTD         38       97.37       37       1
73.63       uuu0202020808       BAC          34       97.06       33       1
49.4         uuu0303031212       EEE           32       96.88       31       1
121.01     uuu0202021313       YKBD       291       96.56       281       10
...

The columns indicate, the percentage increase, the Candlestick indicator, the company, the number of times this indicator has triggered, the percentage that this indicator has been over 11.5%, the number of times it has been over the 11.5% and the number of times it has been less than 11.5%.


So we see above, finding an indicator for the company NLMA of uuu0202021313 today would indicate a 98.34% chance that over the next 5 days this stock will rise more than 11.5%, but the current average percentage increase is 88.83% for a result set of 181 times this Candlestick indicator has been triggered.

The '...' indicate that this is in the middle of a report.
Lets see some interesting Candlesticks that indicate a rise 100% of the time:

...
22.56       uuu0202021818       LTHP       22       100       22       0
34.29       uuu0505051717       CRL       14       100       14       0
15.84       uuu0202021313       GLDE       12       100       12       0
34.34       uuu0202021919       INDG       9       100       9       0
16.5         ddd0505051818       HAMP       9       100       9       0
37            uuu0202021819       INDG       8       100       8       0
159.43     uuu0202022004       BAC       8       100       8       0
36.97       uuu0202021918       INDG       7       100       7       0
15.99       uuu0202021413       GLDE       7       100       7       0
73.96       uuu0602020108       BAC       7       100       7       0
16.97       ddd0404041313       PCH       7       100       7       0
32.91       uuu0202021414       CMCI       7       100       7       0
...

Even though we get figures on LTHP, I cannot find this company on LSE, but looking at CRL (Creightons), for uuu0505051717, this should indicate a greater than 11.5% increase over the subsequent 5 days, and currently an average increase of 34.29% over the last 14 times this has occurred.

From the above, one can see that the first 3 period indicators are usually either all up or all down  - as an example, for PCH (Pochins Share Price (PCH)), just for these 3 indicators, if the close is lower than the open on 3 successive days, and that the other indicators are 04,04,04,13,13; then we currently have a 100% chance (out of a set of 7 instances) that PCH will rise more than 11.5% over the next 5 days, with the current average being a price rise of 16.97%.

I am now tweeting these under the indicator 'LSE_cs' - see at the top for the Twitter page.

Friday, 2 November 2012

Oracle ACL

New security rules on Oracle 11g predicate that one must setup an ACL (Access Control List) to access outside websites. To to this, follow the following setup scripts:


BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
acl => 'utl_http.xml',
description => 'http access',
principal => 'YOUR_SCHEMA',
is_grant => TRUE,
privilege => 'connect');
COMMIT;
END;
/
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE (
acl => 'utl_http.xml', 
principal => 'YOUR_SCHEMA',
is_grant => TRUE, 
privilege => 'connect',
position => null);
COMMIT;
END;
/
BEGIN
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL (
acl => 'utl_http_mlee.xml', 
host => 'your_hostname');
COMMIT;
END;
/

Sunday, 30 September 2012

Tweeting directly from Oracle

Finally set up the bespoke Oracle Twitter using OAuth rather than using RSS/XML from Twitterfeed.

{easy once you've spent a couple of days working out what the hell is all the fuss about OAuth}

The steps are:

1. set up an application on your Twitter account here

2. make a note of the consumer and account keys and secrets

3. in Oracle create urlencode function:
-=-=-=-=-=-=-

create or replace function urlencode( p_str in varchar2 ) return varchar2
as
    /* FROM: http://www.orafaq.com/forum/t/48047/0/
     * POSTED BY USER: http://www.orafaq.com/forum/u/45693/0/
     * KUDOS!
     */
    l_tmp   varchar2(6000);
    l_bad   varchar2(100) default ' >%}\~];?@&<#{|^[`/:=$+''"';
    l_char  char(1);
begin
    for i in 1 .. nvl(length(p_str),0) loop
        l_char :=  substr(p_str,i,1);
        if ( instr( l_bad, l_char ) > 0 )
        then
            l_tmp := l_tmp || '%' ||
                            to_char( ascii(l_char), 'fmXX' );
        else
            l_tmp := l_tmp || l_char;
        end if;
    end loop;

    return l_tmp;
end;
-=-=-=-=-=-=-=





4. update the XXXXX codes below with the relevant values from step 1 and run code within an SQL worksheet window - create a package from this, go on you know how - :

-=-=-=-=-=


SET SERVEROUTPUT ON

DECLARE

  l_oauth_request_token_url CONSTANT VARCHAR2 (500) := 'http://api.twitter.com/1/statuses/update.xml';
  l_oauth_consumer_key CONSTANT VARCHAR2 (500) := 'XXXX';
  l_oauth_token  CONSTANT VARCHAR2 (500) := 'XXXXX';
  l_oauth_secret CONSTANT VARCHAR2 (500) := 'XXXXX';
  l_oauth_nonce VARCHAR2 (500);
  l_oauth_signature_method CONSTANT VARCHAR2 (10) := urlencode ('HMAC-SHA1');
  l_oauth_timestamp VARCHAR2 (100);
  l_oauth_version CONSTANT VARCHAR2 (5) := urlencode ('1.0');
  l_oauth_consumer_secret CONSTANT VARCHAR2 (500) := 'XXXXXX';

  l_http_method VARCHAR2 (5) := 'POST';
  l_oauth_base_string VARCHAR2 (2000);

  l_oauth_key VARCHAR2 (500) := l_oauth_consumer_secret || '&' || l_oauth_secret ;

  l_sig_mac RAW (2000);
  l_base64_sig_mac VARCHAR2 (100);

  http_req UTL_HTTP.req;
  http_resp UTL_HTTP.resp;

  l_update_send VARCHAR2(2000);
  l_oauth_header  VARCHAR2(2000);

  l_line  VARCHAR2(1024);

  resp_name  VARCHAR2(256);
  resp_value VARCHAR2(1024);

  l_content varchar2(140) := urlencode('hello world');

  l_random varchar2(15);

BEGIN

select dbil.urlencode((sysdate - to_date('01-01-1970','DD-MM-YYYY')) * (86400)) into
l_oauth_timestamp from dual;

  -- RANDOM oauth_nonce
  SELECT dbms_random.string('A', 15)
  INTO l_random
  FROM DUAL;

  SELECT dbil.urlencode (UTL_ENCODE.base64_encode(UTL_I18N.string_to_raw (l_random, 'AL32UTF8')))
  INTO l_oauth_nonce
  FROM DUAL;



  l_oauth_base_string := l_http_method
                          || '&'
                          || urlencode (l_oauth_request_token_url)
                          || '&'
                          || urlencode ( 'oauth_consumer_key'
                              || '='
                              || l_oauth_consumer_key
                              || '&'
                              || 'oauth_nonce'
                              || '='
                              || l_oauth_nonce
                              || '&'
                              || 'oauth_signature_method'
                              || '='
                              || l_oauth_signature_method
                              || '&'
                              || 'oauth_timestamp'
                              || '='
                              || l_oauth_timestamp
                              || '&'
                              || 'oauth_token'
                              || '='
                              || l_oauth_token
                              || '&'
                              || 'oauth_version'
                              || '='
                              || l_oauth_version
                              || '&'
                              || 'status'
                              || '='
                              || l_content);
                           
  DBMS_OUTPUT.put_line (l_oauth_base_string);

  l_sig_mac := dbms_crypto.mac (  utl_i18n.string_to_raw (l_oauth_base_string, 'AL32UTF8')
                                , DBMS_CRYPTO.hmac_sh1
                                , UTL_I18N.string_to_raw (l_oauth_key, 'AL32UTF8'));
                             
  DBMS_OUTPUT.put_line ('Combined sig: ' || l_oauth_key);
                             
  l_base64_sig_mac := UTL_RAW.cast_to_varchar2 (UTL_ENCODE.base64_encode (l_sig_mac));

  DBMS_OUTPUT.put_line ('MAC Signature (Base64-encoded): ' ||  l_base64_sig_mac);

  l_update_send := l_oauth_request_token_url || '?status=' || l_content;
                 
    http_req := UTL_HTTP.begin_request (  l_update_send
                                        , l_http_method
                                        , UTL_HTTP.http_version_1_1);
                                     
   DBMS_OUTPUT.put_line ('UPDATE URL ' || l_update_send);
 
   UTL_HTTP.set_response_error_check (TRUE);
   UTL_HTTP.set_detailed_excp_support (TRUE);
 


    l_oauth_header := 'OAuth oauth_nonce="' || l_oauth_nonce || '", '
                      || 'oauth_signature_method="'|| l_oauth_signature_method || '", '
                      || 'oauth_timestamp="'|| l_oauth_timestamp || '", '
                      || 'oauth_consumer_key="'|| l_oauth_consumer_key || '", '
                      || 'oauth_token="' || l_oauth_token || '", '
                      || 'oauth_signature="' || urlencode (l_base64_sig_mac) || '", '
                      || 'oauth_version="' || l_oauth_version || '"';
                   
    utl_http.set_header ( r => http_req,
                          NAME => 'Authorization', VALUE => l_oauth_header);
                       
    DBMS_OUTPUT.put_line  ('HEADER: ' || l_oauth_header);                      
                       
    utl_http.write_text(  r => http_req, DATA => l_content);
   
    http_resp := utl_http.get_response(r => http_req);
   
   DBMS_OUTPUT.put_line('GETTING RESPONSE HEADERS! ');
 
   FOR i IN 1..utl_http.get_header_count(http_resp) LOOP
    utl_http.get_header(http_resp, i, resp_name, resp_value);
    dbms_output.put_line(resp_name || ': ' || resp_value);
   END LOOP;
 
  DBMS_OUTPUT.put_line('Getting content:');
  BEGIN
      LOOP
        utl_http.read_line(http_resp, resp_value, TRUE);
        dbms_output.put_line(resp_value);
      END LOOP;
   
      EXCEPTION
      WHEN utl_http.end_of_body THEN
        DBMS_OUTPUT.put_line('No more content.');
  END;

   utl_http.end_response(r => http_resp);


  EXCEPTION
    when others then
      DBMS_OUTPUT.put_line('HTTP ERROR: ' || utl_http.get_detailed_sqlerrm);

END;



-=-=-=-=-=

And that's it - you should be tweeting away from your Oracle Database - comment if you have any difficulties.

I am in the process now of changing the twitter feeds to contain all information rather than just the top 5.

Thursday, 27 September 2012

Candlestick/Markov/Trace

Just back from hols and will be documenting here the new Candlestick/Markov/Trace analysis that I have been working on - isnt that what holidays are for ?

But as a quick indicator, I am up to my eighth straight 11.5%; just had TOM, WSG, SEA and BRT.

Wednesday, 5 September 2012

AHT and new system

AHT did rather well yesterday, I was out at 11.5%, but its still going up.

New system delivered and setup - to the right is the new system screen shot of processor cores under calc mode - oasis is parallel processing

Currently into SEA, KMG, SIE, SLE.

Saturday, 1 September 2012

AHT

Today's AHT success coefficients are 1900/221 which are pretty good