Code covered by the BSD License  

Highlights from
FinMetrics

  • fm(varargin) This source file is subject to version 3 of the GPL license,
  • AssetThis source file is subject to version 3 of the GPL license,
  • AssetUniverseThis source file is subject to version 3 of the GPL license,
  • AxlThis source file is subject to version 3 of the GPL license,
  • CashPositionThis source file is subject to version 3 of the GPL license,
  • CashTransactionThis source file is subject to version 3 of the GPL license,
  • Config This source file is subject to version 3 of the GPL license,
  • ConsoleMenuThis source file is subject to version 3 of the GPL license,
  • ConsoleMenuItemThis source file is subject to version 3 of the GPL license,
  • CurrencyAssetThis source file is subject to version 3 of the GPL license,
  • ExchangeTradedAssetThis source file is subject to version 3 of the GPL license,
  • FinMetricsThis source file is subject to version 3 of the GPL license,
  • PortfolioThis source file is subject to version 3 of the GPL license,
  • PositionThis source file is subject to version 3 of the GPL license,
  • StatisticsThis source file is subject to version 3 of the GPL license,
  • StockPositionThis source file is subject to version 3 of the GPL license,
  • StockTransactionThis source file is subject to version 3 of the GPL license,
  • TextUIThis source file is subject to version 3 of the GPL license,
  • TextUILocaleThis source file is subject to version 3 of the GPL license,
  • TextUIQuestionThis source file is subject to version 3 of the GPL license,
  • TextUIQuestionnaireThis source file is subject to version 3 of the GPL license,
  • TransactionThis source file is subject to version 3 of the GPL license,
  • View all files

FinMetrics

by

 

Open source/open architecture quantitative portfolio management environment.

Axl
classdef Axl < handle  
% This source file is subject to version 3 of the GPL license, 
% that is bundled with this package in the file LICENSE, and is 
% available online at http://www.gnu.org/licenses/gpl.txt
%
% This source file can be linked to GPL-incompatible facilities, 
% produced or made available by MathWorks, Inc.

    properties
    end
    
    methods (Static)
        function ret = GetRFR()
            conn = fred;
            if (~isconnection(conn))
                ret = 0;
            else
                DTB3 = fetch(conn, 'DTB3');
                ret = DTB3.Data;
                close(conn);
            end 
        end
        
        function ret = GetEquityQuote(symbol) 
            conn = yahoo;
            if (~isconnection(conn))
                ret = NaN;
            else
                ret = fetch(conn, symbol);                
                close(conn);
            end             
        end
        
        function ret = GetOptionChain(underlying, filter)
            
            if nargin > 1
                cmd = sprintf('perl %s/getOptionChain.pl -u %s -f %s', FM.Config.PerlScriptDir, underlying, filter);
            else
                cmd = sprintf('perl %s/getOptionChain.pl -u %s', FM.Config.PerlScriptDir, underlying);
            end
            [status, chain] = system(cmd);
            if (status ~= 0) 
                ret = NaN;
            else
                cmat = textscan(chain, '%s %s %s %s %s %s %s %s %s %s %s %s %s', 'delimiter', ',', 'EndOfLine', '\n', 'EmptyValue', 0);
                ret = [ cmat{1}, cmat{2}, cmat{3}, cmat{4}, cmat{5}, cmat{6}, cmat{7}, cmat{8}, cmat{9}, cmat{10}, cmat{11}, cmat{12}, cmat{13}];
            end            
        end
        
        function ret = FidelityPositions2Portfolio(filename, portfolioName)
            CurrencyAsset = 'FCASH';
            
            fd = fopen(filename);
            if (fd == -1)
                ret = -1;
                return;
            end
            
            posMatrix=textscan(fd, '%s "%[^"]" "%[^"]" "%[^"]" %s %s %s %s %s %s %s %s %s %s %s %*[^\n]',  'delimiter', ',', 'EndOfLine', '\n', 'EmptyValue', 0, 'HeaderLines', 1);
            
            symbolVector =  posMatrix{1:end, 3};
            quantVector =   str2num(char(posMatrix{1:end, 5}));            
            
            for i=1:size(symbolVector)
                if (strcmp(symbolVector{i}, CurrencyAsset))
                        assetVector{i} = FM.CurrencyAsset('USD', 'Cash', symbolVector{i});
                        transVector{i} = FM.CashTransaction(struct('Action', 'Deposit', 'Asset', assetVector(i), 'Quantity', quantVector(i)));
                elseif (size(symbolVector{i}) <=4)                         
                        assetVector{i} = FM.ExchangeTradedAsset(symbolVector{i}, 'NSE', 'Equity', 'Stock');                        
                        
                        if (quantVector(i) > 0) 
                            Action = 'Buy';
                            posQuant = quantVector(i);
                        else
                            Action = 'Sell Short';
                            posQuant = abs(quantVector(i));
                        end
                        transVector{i} = FM.StockTransaction(struct('Action', Action, 'Asset', assetVector(i), 'Quantity', posQuant) );
                end
            end
            
            ret = FM.Portfolio(portfolioName);

            for i=1:size(transVector,2)
                ret.AddTransaction(transVector{i});
                ret.CommitTransaction(i,now);
            end
            
            fclose(fd);
        end
    end
    
end

Contact us