Code covered by the BSD License  

Highlights from
View and add transaction to portfolios on Google Finance

image thumbnail

View and add transaction to portfolios on Google Finance

by

ted p teng

 

10 Jul 2011 (Updated )

View and add transactions to portfolios on Google Finance. A Google account will be required.

googlePortfolioHoldingsExample.m
%% googlePortfolioHoldingsExample
% before running this example script (press F5),
% you will need to fill in the variables on line 11, 13 and 17 correctly.
%
% note: Users running Windows 7 may have trouble running this.

close all;clear all;clc;

%% input Google Portfolio info.
%your account email
username = 'INSER_GMAIL_ID_HERE@gmail.com';
%your password
password = 'INSERT_PASSWORD_HERE';
%your portfolio id (this will be an integer, you will need to create a porfolio first in
%finance.google.com.  The portfolio id can be retrieved from the web
%address linked when you access the portfolio.)
portfolioId = INSERT_PORTFOLIO_INT_HERE;


%% input transaction info.
%types of transactions ('Buy' 'Sell' 'Sell Short' 'Buy to Cover');
action = 'Buy'; 
%ticker symbol
tickerId = 'NASDAQ:GOOG';  %note the need to specify market: before the symbol.
%amount of shares
shares = 200;
%price per share.
price = 500; %currency of price will be according to the market currency of tickerId.
              %stock price can also be retrieved online from yahoo/google at the time of function execution
              %please see http://luminouslogic.com/stock-market-get-quote-matlab.htm or
              %browse functions in Matlab File Exchange to implement this.
%how much your broker charges per transaction
comission = 7.99;

tic
%buy some virtual stocks ( buy buy buy!!! ).
if setGooglePortfolioHoldings(username,password,portfolioId,tickerId,action,shares,price,comission),
    display('transaction complete!');
end
toc

%% show portfolio holdings
holdings = getGooglePortfolioHoldings(username,password,portfolioId);

% display holdings
if numel(holdings)>0,
    display('current holdings:')
    for count = 1:numel(holdings)
        display(sprintf('%s, shares: %d',holdings(count).symbol, holdings(count).share));
    end
else
    display('no holdings in specified portfolio');
end

%refs/related readings:
%http://code.google.com/apis/finance/docs/2.0/developers_guide_protocol.html
%http://www.mathworks.com/help/techdoc/ref/xmlread.html
%http://www.justinspradlin.com/programming/putting-google-finance-to-rest-with-ruby/
%http://blog.thycoticsolutions.com/2010/10/21/how-to-build-a-google-finance-client-app-with-windows-phone-7/?like=1
%http://blodgett.doof.me.uk/2010/10/01/hateyhatey/

Contact us