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.

CashPosition
classdef CashPosition < FM.Position
% 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
        function CPObj = CashPosition(asset, direction, quantity)
            CPObj.Asset = asset;
            CPObj.Direction = direction;
            CPObj.Quantity = quantity;
        end
        
        function ret = plus(a,b)
            % First check if we work with oranges only
            if (a.Asset == b.Asset)
                if (strcmpi(a.Direction, 'Long') && strcmpi(b.Direction, 'Long'))
                    dir = 'Long';
                    quant = a.Quantity + b.Quantity;
                    if (quant < (FM.Config.FloatTol * -1))
                        ret = false;
                        return;
                    end                    
                elseif (strcmpi(a.Direction, 'Short') && strcmpi(b.Direction, 'Short'))
                    dir = 'Short';
                    quant = a.Quantity + b.Quantity;
                    if (quant > FM.Config.FloatTol)
                        ret = false;
                        return;
                    end                
                else
                    ret = false;
                    return;
                end
                
                ret = FM.CashPosition(a.Asset, dir, quant);
                ret.OpenDate = a.OpenDate;
                return;                                        
            else
                ret = false;
                return;
            end
        end

        function rslt = Summary(SPobj)
            rslt = sprintf('Open on %s %s %s-%s %.2f%s', datestr(SPobj.OpenDate), SPobj.Direction, SPobj.Asset.AssetClass, SPobj.Asset.AssetCategory, SPobj.Quantity, SPobj.Asset.Currency);
        end
        
        function ret = UpdateAsset(CPObj, asset)
            ret = false;
            
            if ~(CPObj.Asset == asset)
                return;
            else
                CPObj.Asset = asset;
                ret = true;
            end
        end    
    end
    
end

Contact us