Abstract:
An artificial expert system and method for determining whether to buy, sell, or hold a specific Individually Traded Unit (ITU) of publicly traded units residing in a securities or investment portfolio owned or controlled by a user, wherein the portfolio comprises of at least the trading statistics of each ITU. In one embodiment, the invention provides a user with a rational basis: to sell the optimum number of ITU&#39;s to unload at the optimum ITU sale price or buy the optimum number of ITU&#39;s to purchase at the optimum ITU purchase price or recommend that the user neither buy nor sell any of the selected ITU&#39;s.

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
     This application claims the benefit of priority from U.S. Provisional Patent Application Ser. No. 60/864,124 (filed Nov. 2, 2006). 
    
    
     STATEMENT REGARDING FEDERALLY SPONSORED RESEARCH OR DEVELOPMENT 
     Not Applicable. 
     BACKGROUND OF THE INVENTION 
     This invention relates generally to portfolio management systems, the primary markets discussed in detail herein are the publicly-traded stock markets. However, the invention can be used to trade on other public markets (e.g., FOREX, commodities, options, etc.). Therefore, for the examples and discussion will use the U.S. publicly-traded stock market. 
     For many years, there have been two different schools of thought regarding stock market trading. The prevailing school preaches a detailed analysis of a company&#39;s financial reports and activities to determine an actual value of the shares of stock or Individually Traded Units (ITU) of the company. If the current market price of the company&#39;s total outstanding ITU&#39;s is lower than the computed actual value, then the ITU price will probably increase. If the current market price is higher, then the ITU price will probably decrease. This predictive technique is flawed in that the current market price is affected by many other factors such as supply and demand, world events, expected earnings vs. actual earnings, etc. The general worth of a broker that uses this school of thought is determined by his intuitive abilities to take all of these factors into account to attain more accurate predictions than his or her competition. 
     The second, and for many years the less prevalent school of thought preaches an analysis technique known as technical trading. Generally, technical traders perform very little analysis of the company&#39;s financial reports and activities. They watch the current market price with a given frequency in order to determine pricing trends. If the price of an ITU (correcting for minor fluctuations) has been increasing for a long time period in the past and into the present, then it will probably continue to increase for at least a short time period in the future. Conversely, a past long-term trend of decreasing prices tend to forecast a continuation of falling prices. For many years prior to the computer information age, technical traders would graph the stock prices for a given company over time. Most frequently, they would use the daily closing market price to plot discreet points on a graph. They would then plot trend lines in an effort to predict the future price of an ITU.  FIG. 1  shows an upward price trend, while  FIG. 2  shows a downward price trend. Note the use of the trend line to compensate for daily fluctuations. Technical traders would use these trend lines to predict the future price. Trend lines were used as a method of linearly “smoothing” the graph (i.e., disregarding pricing fluctuation over a long time period). Often the price graph would show familiar patterns. One such pattern is the “head and shoulders” illustrated in  FIG. 3 . Here, a series of upward and downward trends merge into a general upward trend to form a “head” and two “shoulders,” and a downward trend develops from the second “shoulder.” Typically, such a pattern results in a long-term downward trend during the time period following the formation of the second “shoulder.” There is no logical reason for this to occur. However, past experience with this type of pattern provides a strong prediction for future pricing of the ITU. An entire repertoire of pricing patterns exist for the technical trader to use in order to predict future pricing. 
     For many years prior to the application of computers to technical trading, traders needed to be satisfied with ITU pricing sample points taken only from closing market prices. However, computer technology presented technical traders with the opportunity to sample pricing points much more frequently. Today, sampling intervals of minutes or seconds are used. The availability of the larger number of data samples permitted technical traders to develop sophisticated computer software to more accurately predict pricing trends. Based upon these trends, short-term recommendations could be made by technical trading brokers to customers to buy, sell, or hold a given stock. 
     Upon review of the existing state of the art as represented by issued patents and published applications it should be noted that computerized systems implementing investment strategies that analyze each separate stock within a portfolio to determine if the present trading price should be used to either buy, hold, or sell additional shares of that stock have been the subject of several earlier patent documents. 
     Of particular interest is the patent application publication US 2005/0154658 to Bove et al., which describes a system for automatic investment planning using a computerized scheme that automates investment planning for a client. In the scheme, data regarding the client&#39;s desired asset allocation, current asset portfolio and preferred domain (e.g., stocks, bonds, etc.) are input into a computer for processing. The data are used to automatically generate financial transaction recommendations for modifying the client&#39;s current asset portfolio to reach as close as possible, the desired asset allocation and the preferred domain. The generated recommendations include specific recommendations for selling amounts of selected current assets and specific recommendations for buying amounts of one or more investment funds. The recommendations are displayed on a summary report for review by the client or the client&#39;s financial manager, or the recommendations are electronically communicated to a trade execution computer which automatically performs the necessary transactions to execute the buy/sell recommendations. The recommendations are selected in a manner which minimizes the tax impacts and transaction costs of potential sell transactions. 
     Furthermore, the U.S. Pat. No. 6,484,152, issued to Robinson, shows a method of automatically selecting a securities portfolio from a plurality of securities, selecting investment characteristics and investment limits considered important for investment objectives. The method establishes a safety level for the portfolio constructing a matrix having entries corresponding to: (a) the selected characteristics and limits; and, (b) the candidate securities; thereby establishing an objective function corresponding to the constructed matrix and then determining the securities portfolio based on the matrix and the objective function. The investment characteristics may include dividends, rate of growth of earnings, financial strength, safety, predictability of earnings, and performance rankings provided by an advisory service. The safety level may be provided by determining a number of different stocks to be included in the specific portfolio. The selected investments may be determined by limitations imposed on the amount of investment in each candidate security. At least one selected investment limit may relate to a standardized commercial rating or a measure of financial strength. 
     In addition, the patent application publication US 2005/0234809, issued to Criner, describes a method that, given a price-time trajectory, seeks the policies that optimize portfolio performance over that trajectory. The method is based on the result of a program of research that succeeded in portfolio optimization. A controlled theoretic approach included: 1) developing a measure of profitability of the trading portfolio; 2) computationally modeling the trading process operating on the price-time histories; 3) calculating estimates of the price-time histories using functions with well-known mathematical characteristics; 4) calculating, using the calculated estimates, derived functions of the price-time histories about which control variables are known and about which there is prior knowledge; and 5) simulating, using the derived functions, the trading policies and seeking the values of the control variables that maximize the portfolio&#39;s trading performance over the life of the trades. 
     The above-listed references were selected to illustrate patent documents in the field of formula investment strategies that analyze each separate stock within a portfolio to determine if the present trading price should be used to determine whether to: buy, hold, or sell additional shares. 
     SUMMARY OF THE INVENTION 
     The Present Invention is a computer program which performs analysis on a portfolio of Individually Traded Units (ITU) which for purposes of this discussion are best thought of as publicly traded stocks. But they could be any publicly traded entity (stock options, commodities, mutual fund shares, index funds, etc) provided that there is timely and publicly available price data for each ITU. For the purposes of this write-up and familiarity with the terms in use, the invention will be discussed from this point on using normal stock market terminology (stock portfolio, individual stock, shares held, price quote, “buy/sell/hold”, etc.). 
     More specifically, the invention uses an artificially intelligent expert system to analyze each separate stock within a given portfolio to determine if the currently reported trading price of the stock should be used to buy, hold, or sell shares. To make this decision, the software derives the current moving mean, exponentially smoothed average, variance, and standard deviation based on the current calculated optimum sample size. When the current trading share price of an active stock within the portfolio increases by more than one standard deviation greater than the moving mean, and the trading price is greater then both the exponentially smoothed average and mean cost to acquire the stock; then the difference is used to calculate a transaction (number of shares and share price) to recommend that the user sell a specific number of shares based on the difference calculation. However, if the price were to fall below the current mean minus one standard deviation and fall below the exponentially smoothed average, the system then analyzes the difference and recommends that the user buy a specific number of shares (at a specific share price) that directly relates to the difference calculation. 
     The invention also immediately processes and adjusts for “stock splits” and unusual market activity (e.g., the “market collapse” resulting from the events of Sep. 11, 2001). 
     The computer program simply executes a main program “loop” through each of the stocks in the user&#39;s portfolio (total collection of different stocks) calling in sequence various functions (i.e., “subroutines”) which assist in the calculation of certain statistical properties of each stock in the portfolio. Based on these statistical properties a two-part decision is made: first, to buy, sell, or hold the particular stock and if buy or sell how many shares at a given price. 
     Experimentation has shown that this computer program predicts ITU pricing trends with very high accuracy. The recommendations to buy, sell, or hold specific stocks within a given portfolio have proven to be valid over a wide range of securities. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         FIG. 1  illustrates how an upward trend line is created from rising stock prices. 
         FIG. 2  illustrates how a downward trend line is created from falling stock prices. 
         FIG. 3  illustrates a “head and shoulders” as a typical pattern used to predict future stock prices. 
         FIG. 4  is a flowchart of the MAIN processing routine; 
         FIG. 5  is a flowchart of the SETSAMPLESIZE subroutine; 
         FIG. 5(A)  is a flowchart of the AUTOSAMPLESIZE function; 
         FIG. 6  is a flowchart of the ESMOOTH subroutine; 
         FIG. 7  is a flowchart of the CALCULATEADVICE subroutine; 
         FIG. 8  is a flowchart of the BUYDOWN3 function; 
         FIG. 9(A)  is the first part of the BUYADVICE flowchart. 
         FIG. 9(B)  is the second part of the BUYADVICE flowchart of  FIG. 9(A) . 
         FIG. 9(C)  is a flowchart of the AUTOTRADEFACTOR function; 
         FIG. 10(A)  is the first part of the SELLADVICE flowchart. 
         FIG. 10(B)  is the second part of the SELLADVICE flowchart. 
         FIG. 11  is a flowchart of the USEDFUNDS function; 
         FIG. 12  is a flowchart of the AVERAGECOST function; and, 
         FIG. 13A-1  is a printout of the first part of a spreadsheet produced by the present invention; 
         FIG. 13A-2  is a continuation of the printout shown in  FIG. 13A-1 ; 
         FIG. 13A-3  is a continuation of the printout shown in  FIG. 13A-2 . 
         FIG. 13(B)  is a further printout of the spreadsheet of  FIG. 13A-1 . 
     
    
    
     Similar reference characters denote corresponding features consistently throughout the attached drawings. 
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     Flowcharts of the entire software system are shown in  FIGS. 4 through 12 , and are divided into principle modules. Commented pseudo-code for all the modules is shown in the Appendix. The Appendix sections are divided into modules, and they have the same designations as the figures corresponding to those modules. 
     The program comprises a MAIN program that initializes itself by clearing certain control variables and retrieving from an appropriate source(s) the current price for each different issue in the portfolio (it is assumed for purposes of this discussion that these are the current ASK price on the U.S. exchanges, e.g., NASDAQ, NYSE and AMEX). The primary storage media for all this stock related data can be a Microsoft Excel spreadsheet. Portions of a sample spreadsheet are shown in  FIG. 13 . 
     After initialization and loading of stock price data into the spreadsheet, the MAIN program comprises of a simple loop that passes through the users portfolio starting with the first stock and proceeding to the last stock in the portfolio, and performs the calculations necessary to determine a decision for that particular time period (i.e., end-of-day) whether to buy, sell, or hold that stock as well as a recommendation of the number of shares to buy or sell at the quoted (i.e., retrieved) price.  FIG. 4  represents the flowchart for the MAIN program, and the code with comments for the MAIN routine is shown in the Appendix for  FIG. 4 . The principal sub-functions are:
         CalculateAdvice (shown in  FIG. 7 ),   ExponentialMethod_BuyAdvice (shown in  FIGS. 9A and 9B ), and   ExponentialMethod_SellAdvice (shown in  FIGS. 10(A) and 10(B) .       

     The steps that are performed by the MAIN routine after the price data has been loaded consist of looping thru the following series of functions (For Z=1 to NIP, where NIP stands for number of stocks in portfolio, and CP stands for Current Price): 
     A. SetSampleSize (Refer to  FIG. 5 ) 
     This routine invokes a function called AutoSampleSize (shown in  FIG. 5(A) ) that determines the best sample size for a particular stock&#39;s latest sample set of prices. The determined sample size is stored in an array G_SampleSize(Z) which is the Z th  stock in the user&#39;s portfolio. The number of stocks in the user&#39;s portfolio varies from 1 to NIP, which is a global variable which is an acronym for Number In Portfolio. The smallest and largest sample sizes in the entire portfolio of stocks are maintained in G_SmallestSampleSize and G_LargestSampleSize. 
     1. AutoSampleSize (Refer to  FIG. 5(A) ) 
     This sub-function determines the “best” sample size to use for all calculations relating to this individual stock. The determination is made by calculating three (3) moving statistics: mean, variance, and standard deviation for the stock price over the range from G_MaxSampleSize stepping down to G_MinSampleSize and determining for what sample range its variance is the lowest. The sample size with the lowest variance, yet greater than zero, is defined to be the “best” sample, based on the rationale that the least variance represents the smallest difference between the members of the sample and its current moving mean. G_MeanPrice(Z) and G_Deviation(Z) can then be set to the calculated moving mean price and the calculated moving standard deviation for this stock using the best sample. The formulas for these calculations are well known in the art. 
     B. ESmooth 
     This function calculates an “exponentially smoothed” value of the price for each stock in the current portfolio. The current smoothed value (ESmooth(Z)) is checked to determine if it is equal to zero in which case, it is blank and not used, therefore the smoothed value for that stock is set to the current day&#39;s price. If the current smoothed value is not zero, the new smoothed value is calculated as:
 
 E Smooth( Z )=[ k×E Smooth( Z )]+[(1− k )×CurrentTradingPrice]
 
where k=0.7
 
C. CalculateAdvice
 
     This subroutine creates the actual recommendation (Buy/Sell/Hold) for each stock within the user&#39;s portfolio by iterating through a loop from 1 to NIP (the number of stocks in the user&#39;s portfolio). 
     The recommendation is based on a set of tests, starting with the “Buy” test, and if that is false, proceeding to the “Sell” test, and finally if neither is true, defaulting to the “Hold” status. If a buy or sell recommendation is made, the routine calculates the percentage of the holding which should be bought or sold and stores it as a decimal number in G_BuyAdvice(Z) or G_SellAdvice(Z), where again Z is an index to the stock entry in the user&#39;s portfolio. 
     The test for “Buying” is whether the current stock price is less than the mean price (G_MeanPrice(Z)) minus the standard deviation of the price (G_Deviation(Z)) and the current price is less than or equal to the exponentially smoothed price for the stock (G_ESmooth(Z)). This second test is an assurance against an incorrect sample size since the smoothed price is independent of sample size and only determined by the value of “k”; also, this second test will decrease the influence of older prices in an exponential manner. 
     If either test for buying is false, then the “Sell” test is performed. The sell determination involves three conditions versus the two in the buy test. The current stock price is greater than the mean price (G_MeanPrice(Z)) plus the standard deviation of the price (G_Deviation(Z)) and the current price is greater than or equal to smoothed price for the stock (G_ESmooth(Z)) and the current price is also greater than G_AC(Z), which is a portion of the Broker&#39;s fee plus the share price paid. This last test is to assure that the selling price is profitable, i.e., greater than the current average cost of acquiring the shares [(total price for shares+broker&#39;s commission)/shares bought]. 
     Both Buy and Sell use a positive, absolute value, version of the Student&#39;s t-distribution (Equation 3 below)
 
 L BuyFactor= Abs ( LCP−G _MeanPrice( Z ))/[( G _Deviation( Z )/ Sqrt ( G _SampleSize( Z ))]
 
When sample sizes are less then 30 elements, the student&#39;s t-distribution will function in place of the Z-score and used as the index root. For example:
 
|(1/| t |)−1|^(1/| t |)
 
 G _BuyAdvice( Z )= Abs ((1/ L BuyFactor)−1)^(1/ L BuyFactor)
 
which is the same formula as:
 
     
       
         
           
             
               G_BuyAdvice 
               ⁢ 
               
                 ( 
                 Z 
                 ) 
               
             
             = 
             
               
                  
                 
                   
                     ( 
                     
                       1 
                       
                          
                         t 
                          
                       
                     
                     ) 
                   
                   - 
                   1 
                 
                  
               
               
                  
                 t 
                  
               
             
           
         
       
     
     LBuyFactor is a single precision, floating point variable 
     LSellFactor is a single precision, floating point variable 
     LCP is the current price of the stock (at location Z in the user&#39;s portfolio) under consideration 
     G_MeanPrice(Z) is the mean price of the Z th  stock (determined using G_SampleSize(Z)). 
     The absolute value of the conventional Student&#39;s t-distribution will result in values which could take on any value, but potentially greater than 1.0 and less than 0.0 are not of interest and are useless. These values (=&gt;1 and &lt;=0) would be useless as a percentage of the current shares held to be bought/sold. The Student&#39;s t-distribution is significant, and therefore utilized because it represents the deviation of the individual price from the standard deviation. In order to utilize the Student&#39;s t-distribution, to generate a trading percentage, it should be transformed into a value between (but not equal to) 0 and 1. The transform used by CalculateAdvice is determined as:
 
 G _BuyAdvice( Z )= Abs ((1/ L BuyFactor)−1)^(1/ L BuyFactor)
 
 G _SellAdvice( Z )= Abs ((1/ L SellFactor)−1)^(1/ L SellFactor)
 
and results in a value for G_BuyAdvice(Z) or G_SellAdvice(Z) in the proper range (0&lt;X&lt;1) which is then used as the percentage of the current holding to Sell or of available cash reserve to buy.
 
     In order to keep a running count of the number of buys and sells the two counters: G_EMBuyCount and G_EMSellCount, are both initially set equal to zero and only incremented by one in an appropriate manner. 
     NOTE: At the conclusion of the major loop in CalculateAdvice (1 to NIP) each of the stocks will have an associated determination whether to buy, sell, or hold. If it is to buy or sell, a decimal percentage of current holdings is recommended. However, this only represents the first step of the process. What remains is to determine from all of the recommendations for the entire portfolio and the available cash what portion of each buy recommendation to actually execute. If the recommendations are just processed sequentially the earliest portfolio members will consume most of the available cash and the later members may have significantly limited cash available to acquire what may turn out to be excellent investment choices. Therefore all of G_BuyAdvice array should be examined in order to make an appropriate and more reasonable set of buy choices. Further analysis of the set of buy recommendations is done by the routine ExponentialMethod_BuyAdvice (shown in  FIGS. 9A and 9B ) The results yield approximately the same amount of available cash to be used for each individual “buy” (depending on the shares to be purchased and the price).
 
D. ExponentialMethod BuyAdvice (Refer to  FIGS. 9A and 9B )
 
     After determining if there are stocks for which a “buy” is recommended (G_EMBuyCount&gt;0) and that a crisis (like Sep. 11, 2001) has not caused a market plunge (tested by dividing the number of buy recommendations (G_EMBuyCount) by the number of issues in the portfolio (NIP) and seeing if that result is greater than the “G_Safety” a constant set by the user, a medium safety limit would be from 0.3 to 0.7) the normal processing can proceed. 
     A loop is executed through the entire portfolio in order to determine the stock with the lowest recommended purchase percentage. This is performed to allocate cash first to those stocks whose purchase price has changed the least and therefore are assumed to require the least attention. The purpose for doing this is so that the portions of each that are not used can be saved for those stocks with larger, thus more urgent, purchasing advice. 
     Before a buy can be made, certain “safety checks” are made throughout this routine. The primary check is to insure that the current price is not exceptionally low (a severe drop) by comparing it to a user defined variable if the default of 75% of the mean price as a lower limit. A value of 75% is used here as an example value to represent the user&#39;s choice, which is stored in a variable called “LBuyBarrierWarning”. 
     Normal processing of a buy order comprises invoking the AutoTradeFactor function (see  FIG. 9(C) ) which returns a decimal value that is applied (multiplied) to G_BuyAdvice in order to adjust it based on the amount of unused cash. A second safety check is done here to insure that the value of G_BuyAdvice does not exceed a preset maximum value (G_HighestAdviceLimit), if it does then the G_HighestAdviceLimit is used as the value for G_BuyAdvice. 
     Before the “buy” can be approved, a check is made to determine if the stock is in a temporary downward trend, indicating that buying should be avoided until the trend bottoms out. This check is made by the function BuyDown3 (refer to  FIG. 8 ) which will return a value unchanged (i.e., not negative) if the past history contains less then a specified number of “buys” (parameter passed to function) over a user specific past sample size (G_BuyDownSample). Conversely, if there are equal to or greater then the specified number of “buys”, the value of BuyDown3 is set to a negative number indicating to the calling routine to skip that recommended purchase. 
     If the “buy” is to proceed normally, the amount of available funds for the buy is computed by dividing the available cash (G_Cash) by a denominator equal to 2+the remaining number of “buys” to be processed. The slightly increased denominator (by 2) assures that exactly all of the available funds will not be allocated to only the current “buys”. Before the “buy” transaction proceeds to be approved, a check is made to assure that there are enough funds left (LSegmentedFunds) to cover the purchase of a single share plus any broker&#39;s fees (G_Broker). The number of shares, as an integer value, to acquire (LAcquire) is then computed with these two formulas:
 
 L SegmentedFunds= G _Cash/(2+ G   —   EM BuyCount− Y )
 
 L Acquire= Int ([ L SegmentedFunds* G _BuyAdvice( L Recall)]/ LCP )
 
The available cash is updated by deducting the cost of this buy ([Shares*Price] plus Broker&#39;s fee) and the remaining housekeeping (updating of totals, etc.) is performed prior to conclusion of this routine.
 
1. BuyDown3 (Refer to  FIG. 8 )
 
     This function counts backward from the current day, and determines the segment of the past transactions (until either G_BuyDownSample is completed or G_BuyDownLimit number of buys has been found) are “buys”. If there are equal to or more “buys” then the G_BuyDownLimit specifies, a negative value is returned back to the calling statement. This negative return signals its calling statement not to buy because of a declining market. If there are not many “buys”, it returns a positive result indicating to proceed with the current buy transaction. 
     2. AutoTradeFactor (Refer to  FIGS. 9(A) Through 9(C) ) 
     This function returns a value which is used to adjust the percentage of the current position to buy (G_BuyAdvice) based on G_Cash after calling the function UsedFunds (see  FIG. 11 ). The returned value will equal the ratio unless it exceeds certain prescribed limits
 
( L MaxLimit&gt;=AutoTradeFactor&gt;= L MinLimit)
 
in this version of the pseudo-code the max is 4.5 and the min is 1.0. Yet both LMaxLimit and LMinLimit can be user specified.
 
3. UsedFunds (Refer to  FIG. 11 )
 
     This function determines the current value of the entire portfolio while utilizing a Boolean parameter which indicates if the true “profit” should be returned to the calling routine or not. If profit is requested, the value G_UnUsedCash is subtracted from the total value before returning. If “profit” is not the desired result (whereby the Boolean parameter&#39;s value=False), then G_UnUsedCash is not subtracted. 
     E. ExponentialMethod SellAdvice (Refer to  FIGS. 10(A) and 10(B) ) 
     The routine first verifies that there are recommended sell transactions to be processed by checking to see if G_EMSellCount is greater than zero. A loop passing through the entire portfolio (from 1 to NIP) looks at each entry to determine if G_SellAdvice(Z) is &gt;0 and that the user owns some shares of the stock (i.e., G_Own(Z)&gt;0). 
     The number of shares to be sold is determined in two steps. First, the AutoTradeFactor function is called to generate a value for G_SellScalar and G_SellAdvice(Z) is then multiplied by G_SellScalar; the result is an adjusted percentage of shares to be sold. A test is made to determine if there are only a small number of shares owned (G_Own(z)&lt;=5) in which case they are all sold by setting G_SellAdvice(Z) to 1.0 (100%). If more than a few shares are held, a second test is made to assure that not too many shares are sold by comparing G_SellAdvice(Z) to a constant (G_HighestAdviceLimit) used to prevent excessively large orders from being placed and thereby skewing the portfolio towards certain issues. Otherwise the new calculated value of G_SellAdvice(Z) is used to calculate LSwap the integer number of shares (out of G_Own(Z)) to be sold.
 
 L Swap= Int ( G _Own ( Z )* G _SellAdvice ( Z ))
 
LSwap is the number of shares to be sold.
 
G_Own(Z) is the number of shares currently held by the user.
 
     Before the sell order is made the following tests are performed: first, the number of shares (LSwap) has to be &gt;0; and then, the profit to be made on the sale is &gt;the Broker&#39;s fee; and finally, the cash on hand (G_Cash) is &gt;the Broker&#39;s fee. If these tests are all successful (true), then the sale is placed by notifying the user or brokerage firm via a outputted message or a spreadsheet. 
     The final step in the loop&#39;s processing is to update the various variables (G_Cash, G_Own(Z), G_AC(Z), and G_EMSoldCount) based on the agreed upon sale. The variable G_AC(Z) is calculated by the function AverageCost. 
     1. AverageCost (Refer to  FIG. 12 ) 
     This function calculates the average cost of the Z th  stock in the portfolio. If this routine was used recently with identical parameters, to save processing time, it will return the previously calculated value. The average cost is based on the transaction type: if a “buy” order were completed, then the total cost is based on the total amount formerly paid for the shares held of that stock (G_TotalCost(Z)) plus the shares traded or those now acquired (LST) times the current price (LCP) in addition to the Broker&#39;s fee (G_Broker); which is then divided by the number of shares (G_Own(Z)) held post the completion of this purchase transaction. 
     If the transaction type was a “sell”, then the total cost is based on the former average cost (G_AC(Z)) immediately prior to this transaction completion times the number of shares held (G_Own(Z)) plus the Broker&#39;s fee, which is then divided by the number of shares (G_Own(Z)). 
     F. SummarizeResults 
     This is a function that will calculate and adjust the values to be displayed. Note that this comment also applies to “T19.UpdateDisplay”. 
     G. Excel_Body 
     See  FIG. 13A-1  through  FIG. 13A-3 . 
     H. T19.UpdateDisplay 
     See SummarizeResults above. 
     I. Footer 
     J. Excel_ConcludingResults 
     See  FIG. 13(B) . 
     It is to be understood that the present invention is not limited to the embodiments described above, but encompasses any and all embodiments within the scope of the following claims.