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.

CashTransaction
classdef CashTransaction < FM.Transaction
% 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 (SetAccess = private, GetAccess = public)        
        % Cash transaction type, possible options Deposit and Withdrawal
        Action = '';
        % Amount of cash in transaction.
        Quantity = 0;
    end
    
    methods
        function CTobj = CashTransaction(params)           
            CTobj.Action = params.Action;
            CTobj.Asset = params.Asset;
            CTobj.Quantity = params.Quantity;
        end                
                
        function rslt = Summary(CTobj)
            rslt = sprintf('%s-%s: %s %.2f%s', CTobj.Asset.AssetClass, CTobj.Asset.AssetCategory, CTobj.Action, CTobj.Quantity, CTobj.Asset.Currency);
            if (isempty(CTobj.CommittedOn) == false)
                rslt = sprintf('%s, committed on: %s', rslt, datestr(CTobj.CommittedOn));
            elseif (isempty(CTobj.PreviouslyCommittedOn) == false)
                rslt = sprintf('%s, uncommitted. Previouse commitment was on: %s', rslt, datestr(CTobj.PreviouslyCommittedOn));
            end
        end
        
        function rslt = Reverse(CTobj)
            switch upper(CTobj.Action)
                case 'DEPOSIT'
                    Action = 'Withdrawal';
                case 'CREDIT'
                    Action = 'Debit';
                case 'WITHDRAWAL'
                    Action = 'Deposit';              
                case 'DEBIT'
                    Action = 'Credit';
                otherwise
                    rslt = '';
                    return;
            end
            
            rslt = FM.CashTransaction(struct('Asset', CTobj.Asset, 'Action', Action, 'Quantity', CTobj.Quantity));
            rslt.CommittedOn = CTobj.CommittedOn;
            rslt.PreviouslyCommittedOn = CTobj.PreviouslyCommittedOn;
            % rslt.CounterTransaction = CTobj.CounterTransaction;
        end
        
        function pos = GenPosition(CTobj)
        
            switch upper(CTobj.Action)
                case { 'DEPOSIT', 'CREDIT' }
                    dir = 'Long';
                    quant = CTobj.Quantity;
                case { 'WITHDRAWAL', 'DEBIT' }
                    dir = 'Long';                    
                    quant = CTobj.Quantity * (-1);                
                otherwise
                    pos = '';
                    return;                    
            end
            
            pos = FM.CashPosition(CTobj.Asset, dir, quant);
        end
        
        function ret = UpdateAsset(CTobj, asset)
            ret = false;
            
            if ~(CTobj.Asset == asset)
                return;
            else
                CTobj.Asset = asset;
                ret = true;
            end
        end    
    end
    
end

Contact us