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.

CurrencyAsset
classdef CurrencyAsset < FM.Asset
% 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
        % Currency - underlying currency (USD, YEN, RUR, etc).
        Currency = '';
    end
    
    properties (SetAccess = private, GetAccess = public)            
        % TimeSeries of the stock
        TimeSeries = fints;
    end
    
    methods
        function Cobj = CurrencyAsset(currency, class, category)
            Cobj.AssetClass = class;
            Cobj.AssetCategory = category;
            Cobj.Currency = upper(currency);
            Cobj.SupportedEvents = { 'UpdateAssetPrices' };
        end

        function detail = Detail(Cobj)
            detail = sprintf('Asset Class: %s\nAsset Category: %s\nCurrency: %s', Cobj.AssetClass, Cobj.AssetCategory, Cobj.Currency);
            dataAvail=ftsbound(Cobj.TimeSeries);
            
            if (~isempty(dataAvail)) 
                detail = sprintf('%s\nTime Series available for: %s :: %s\n', detail, datestr(dataAvail(1)), datestr(dataAvail(2)));
            else
                detail = sprintf('%s\nTime Series available for: NONE\n', detail);
            end
        end   

        function ret = Plot(Cobj)
            ret =  false;
            if (~isempty(ftsbound(Cobj.TimeSeries))) 
                chartfts(Cobj.TimeSeries);
                ret = true;
            end
        end
        
        function ret = ListenForEvent(Cobj, AUobj, event)
            % Check if event is supported.
            ret = false;
            if ~(ismember(event, Cobj.SupportedEvents))
                return;
            end
            
            switch upper(event)
                case 'UPDATEASSETPRICES'
                    addlistener(AUobj, event, @Cobj.updateAssetPricesEvent);                     
                    ret = true;
                otherwise                    
                    return;                    
            end                        
        end
                
        function ret = UpdatePrice(Cobj, startDate, endDate)            
            ret = false;
            
            if (startDate > endDate) 
                return;
            end
            
            % Generate business date vector
            bdays = busdays(startDate,endDate);
            % Generate vertical vector of ones equal to number of days in
            % bdays.
            one = ones(size(bdays,1),4);
            
            if (size(Cobj.TimeSeries) == 0)
                Cobj.TimeSeries = fints(bdays, one, { 'OPEN', 'HIGH', 'LOW', 'CLOSE' }, 'd');
            else
                newData = fints(bdays, one, { 'OPEN', 'HIGH', 'LOW', 'CLOSE' }, 'd');
                Cobj.TimeSeries = merge(Cobj.TimeSeries, newData);
            end

            Cobj.TimeSeries.desc = Cobj.Ident();
            ret = true;
        end

        
        function ident = Ident(Cobj)
            ident = sprintf('%s_%s_%s', Cobj.AssetClass, Cobj.AssetCategory, Cobj.Currency);
        end             
        
        function assetFile = Save(Cobj, assetDir)
            eval(sprintf('%s = Cobj;', Cobj.Currency));
                                        
            if (nargin == 1)
                assetFile = [ Cobj.Currency, '.mat' ];
            else
                assetFile = [ assetDir, '/', Cobj.Currency, '.mat' ];
            end
            
            save(assetFile, Cobj.Currency);
        end    
        
        function ret = eq(a, b)
            
            if (strcmp(class(a), class(b)))                    
                if (strcmp(a.Currency, b.Currency) && strcmp(a.AssetClass, b.AssetClass) && strcmp(a.AssetCategory, b.AssetCategory) )
                    ret = true;
                else
                    ret = false;
                end
            else
                ret = false;
            end
        end
    end
    
    methods (Access = private)               
        function ret = updateAssetPricesEvent(Cobj, eventSrc, eventData)            
            if (size(Cobj.TimeSeries) > 0)
                datesbound = ftsbound(Cobj.TimeSeries);
                startDate = addtodate(datesbound(2), 1, 'day');
                endDate = now-1;
            else
                startDate = FM.Config.BackfillStartDate;
                endDate = now-1;
            end
                                    
            ret = Cobj.UpdatePrice(startDate,endDate);
        end
    end

end

Contact us