%%HP: T(3)F(.); @ 'CFLOW' BYTES  ==>  #8961h  1175.5
@ CFLOW, by Ted A Smith
DIR
  Total
    \<< 1 \GSGet 2 \GSGet DOT
    \>>
  NPV
    \<<
      IF
        I
      THEN
        CFEval DROP
      ELSE
        Total
      END
    \>>
  NUS
    \<<
      IF
        I
      THEN
        CFEval EXPM NEG / I * 100 /
      ELSE
        1 \GSGet 2 \GSGet \-> v c
        \<< v c DOT c c 1 CON DOT 1 - / \>>
      END
    \>>
  NFV
    \<<
      IF
        I
      THEN
        CFEval EXP /
      ELSE
        Total
      END
    \>>
  IRR
    \<<
      \<< NPV \>> 'I'
      IFERR
        DUP RCL
      THEN
        DROP 0
      END
      ROOT
    \>>
  CFEval
    \<< I 100 / DUP LNP1 NEG \-> i lni
      \<< \GSGet2 OBJ\-> 1 GET 2 * 2 + \-> s
        \<< -1 0 s 4
          FOR j
            j ROLL j ROLL \-> n t v r
              \<< r n + lni r * EXPM lni n * EXP * v * t + \>>
            -2
          STEP
          i / NEG SWAP lni *
        \>>
      \>>
    \>>
  \GSGet2
    \<< 1 PREDV DROP
      \GSDAT DUP SIZE 1 2 PUT 0 CON
      { 1 '\GSPAR (1)' } 1 PUT
      { 2 ' \GSPAR(2)' } 1 PUT
      TRN *
    \>>
  \GSGet
    \<< 1 PREDV DROP
      \GSDAT DUP SIZE 2 2 SUB 0 CON
      \GSPAR 4 ROLL GET 1 PUT *
    \>>
  CST { { "Total" \<< Total "Total" \->TAG \>> }
        { "I"     { \<< 'I' STO 'I' RCL "I" \->TAG \>>
                    \<< IRR "IRR" \->TAG \>>
                    \<< IFERR 'I' RCL THEN DROP IRR END "I" \->TAG \>> } }
        { "NPV"   \<< NPV "NPV" \->TAG \>> }
        { "NUS"   \<< NUS "NUS" \->TAG \>> }
        { "NFV"   \<< NFV "NFV" \->TAG \>> } }
END
