Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FIFO Logic Question
Message
 
To
02/11/2004 14:57:11
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00957052
Message ID:
00957425
Views:
12
This is a proposed plan to pull from lots the shares sold. It would need a transaction file to detail the lot transactions and to afford a weighted average cost of sale. We can do that next providing this proposal seems to be usable. It could be more elegant - but I thought it would be more understandable this way:

Okay - now if this were my project I would have a lot file like
FundLots.DBF (fields)
cLot_Numb  c(4)    && Lot sequence FI = low number LI = higest number
cLot_Stat  c(1)    && '1' for shares available, '0' for no shares (depeleted)
cFundName  c(6)    && Example 'AAAA'
nOrigShare n(10)   && Original Shares  Purchased
nBalnShare n(10)   && Current shares (these may have decimals) 
nPricShare n(10,4) && Price per share at purchase
                   && Would be used to weight the cost (average cost)
                   && of purchase
Index on cLot_Stat+cFundName+cLot_Numb tag LotPullOrder
* Now some sample INTIAL data (I won't use all the fields) x LotPullOrder
cLot_Stat  cFundName  cLot_Numb nBalnShare
    0      AAAA           1              0
    1      AAAA           2           1000
    1      AAAA           3           1000
    1      AAAA           4            300
* Now lets pull 1500 shares of Fund 'AAAA'
nSellShares=1500 && Total shares to be pulled from lots 
nPulledShares=0  && Accumulated shares pulled
SET EXACT OFF  && want to ignore required (sequencing/FIFO) cLot_Numb field
IF SEEK("1"+"AAAA  ","FundLots","LotPullOrder")
   SET EXACT ON 
   * Process this lots to accrued nSellShares
   DO WHILE !EOF("FundLots") AND FundLots.cFundName="AAAA  "
   * nNeededShares is working pulled balance forward
   nNeededShares = nSellShares - nPulledShares  
   IF FundLots.nBalnShare >= nNeededShares
      nPulledShares = nPulledShares + nNeededShares
      REPLACE nBalnShare with nBalnShare - nNeededShares ;
              IN FundLots
      * Write this lot's shares to a transaction file
   ELSE && Not enough available shares in FundLots.nBalnShare
      nPulledShares=nPulledShares+FundLots.nBalnShare
      REPLACE FundLots.nBalnShare with 0
      * Write this lot's shares to a transaction file
   ENDIF &&FundLots.nBalnShare >= nNeededShares
   IF FundLots.nBalnShare = 0
      REPLACE cLot_Stat with '0' in FundLots
   ENDIF &&FundLots.nBalnShare = 0
   IF nPulledShares=nSellShares
      EXIT &&!EOF("FundLots") and FundLots.cFundName="AAAA  "
   ENDIF 
   SKIP IN FundLots
   ENDDO &&WHILE !EOF("FundLots") and FundLots.cFundName="AAAA  "
   
   IF nPulledShares=nSellShares
      * Enough shares pulled
   ELSE
      * Not enough shares pulled
   ENDIF &&nPulledShares=nSellShares
ELSE && SEEK FAILED
   SET EXACT ON
ENDIF &&SEEK("1"+"AAAA  ","FundLots","LotPullOrder")
* Resulting Quantities in FundLots.DBF
cLot_Stat  cFundName  cLot_Numb nBalnShare
    0      AAAA           1              0
    0      AAAA           2              0 && Not cLot_Stat='0'
    1      AAAA           3            500 
    1      AAAA           4            300
* In the sections replacing FundLots.nBalnShare, you
* would write one record each for each lot contribution
* to the accumulation of shares to be sold.
* The trick is setting cLot_Stat to 0 when all shares
* for lot are depleted.
>New lots are created for each fund purchase. If I purchase fund AAA three times over a period. Three new lots are created. Then when there is a sales transaction. They want to see which fund(s) the sale came from. It is assumed that there will never be more sold than there is on hand.
>
>
>
>>Okay - what happens when fund shares are purchased - are new lots created, or can 0 qty lots (at the top of FIFO queue) be reused?
>>
>>>Sorry I wasn't clear enough. The sale goes to the first lot draw until depleted, then continues until the order is filled. There will be no interface.
>>>
>>>>Does a sale go to the first lot draw as much as it can from there until it is zero, and the go to the next lot and continue to draw (from each lot) until the shares to be sold matches the sales order?
>>>>
>>>>Or do the "puller" retrieve (sale) from each lot based on the lots percentage of total shares in the fund?
>>>>
>>>>Or does the interface allow an operator to determine which lots the shares are to be pulled from?
>>>>
>>>>>I have a Transaction table with fund c(6), amount Y, and lot C(10). They are in date order but date doesn't matter for example. There are also multiple funds but again, for simplicity.
>>>>>
>>>>>Fund is a fund code. Amount is how much fund in transaction + is buy, - is sell.
>>>>>
>>>>>For a purchase, increment the lot# and store in the table with its transaction.
>>>>>For a sale, the lot number needs to show which lot or portions of lot were sold. FIFO style. Therefore Lot could be 2,3 or 2,3,4 etc.
>>>>>
>>>>>ORIGINAL INFO
>>>>>FUND AMOUNT LOT
>>>>>AAA 1000
>>>>>AAA 1000
>>>>>AAA - 500
>>>>>AAA 50
>>>>>AAA -2050
>>>>>
>>>>>
>>>>>RESULT TABLE
>>>>>FUND AMOUNT LOT
>>>>>AAA 1000 1
>>>>>AAA 1000 2
>>>>>AAA - 500 1
>>>>>AAA 50 3
>>>>>AAA -1550 1,2,3
>>>>>
>>>>>All I need to do is store the lot(s) in the original table.
>>>>>
>>>>>
>>>>>I'm looking for a simple logical way to do this. Speed is not primary but woud be considered. Arrays or working table is my though.
>>>>>Any ideas?
Imagination is more important than knowledge
Previous
Reply
Map
View

Click here to load this message in the networking platform