QIF file format
---------------
The QIF is an old and rather broken file format defined by Intuit
for exporting Quicken data.  It is 'broken' because the format
is ambiguous in many places, non-standard between different releases
and applications, and even varies subtly from country to country (in
particular, the way dates and amounts are represented), and fails
to define important data (such as the currency denomination, or the
exchange rates when transferring between accounts marked in different
currencies).  Importing a QIF file can require significant manual
intervention by the user in order to get the data straight.


Extensions
----------
TEF -- Time and Expense Format (see below)

QFX -- also known as 'Web Connect' --  very similar, and is the
       'new' standard for on-line bank statement downloads.
       (??? or is it just 'ofx in a file' ???)


Type of account identifiers
----------------------------
!Type:Bank     Bank account
!Type:Bill     ??? (bill presentment ???)
!Type:Cash     Cash account
!Type:CCard    Credit Card account
!Type:Invoice  ??? (invoice presentment ???)
!Type:Invst    Investment account
!Type:Oth A    Asset account
!Type:Oth S    Asset account (German)
!Type:Oth L    Liability account
!Type:Tax      ???

!Account         Account list or which account applies to following
                 transactions

!Type:Cat        Category list
!Type:Class      Class list
!Type:Memorized  Memorized transaction list
!Type:Prices     Security prices

Note that !Account is used both to be a header for account information,
and to be a header for a list of transactions.

Also note that international versions of Quicken and MS Money often
translate the Type: tags into the local language.  But not always.


Account Information Format
--------------------------
The below typically follow an !Account identifier, and provide account
data.

Letter Definition
N      Name
T      Type of account
D      Description
L      Credit limit (only for credit card accounts)
/      Statement balance date
$      Statement balance amount
^      End of entry


Category Information Format
---------------------------
N      Category name:subcategory name
D      Description
T      Tax related if included, not tax related if omitted
I      Income category
E      Expense category (if category type is unspecified,
       assumes expense type)
B      Budget amount (optional, only appears in a Budget QIF file)
R      Tax schedule information
^      End of entry


Class Information Format
------------------------
N      Class name
D      Description
^      End of entry


Memorized Transaction Format
----------------------------
KC     Check transaction
KD     Deposit transaction
KP     Payment transaction
KI     Investment transaction
KE     Electronic payee transaction
T      Amount
C      Cleared status
P      Payee
M      Memo
A      Address
L      Category or Transfer/Class
S      Category/class in split
E      Memo in split
$      Dollar amount of split
1      Amortization: First payment date
2      Amortization: Total years for loan
3      Amortization: Number of payments already made
4      Amortization: Number of periods per year
5      Amortization: Interest rate
6      Amortization: Current loan balance
7      Amortization: Original loan amount
^      End of entry

Note that the K* entries must be the *last* entries in the transaction.
All fields are optional.  If this is an amortization record, then all
seven amortization fields much be present.


Investment transaction format
-----------------------------
Letter Definition
D      Date (optional)
N      Action
Y      Security
I      Price
Q      Quantity (# of shares or split ratio)
C      Cleared status
P      first line text for transfers/reminders
M      Memo
O      Commission
L      Account for transfer
       (category/class or transfer/class)
       (For MiscIncX or MiscExpX actions, this will be
       category/class|transfer/class or |transfer/class)
T      Amount of transaction
U      Amount of transaction (higher possible value than T)
$      Amount transferred
^      End of entry

Note that numbers for investment transactions are positive in most
cases.  The importation process automatically takes care of negating
the values for Actions that move funds out of an account (for example:
sales, expenses and transfers).

Be aware that GnuCash's file format stores the share quantity and the
total value of the transaction.  Prices are not stored.


Non-investment transaction format
---------------------------------
Letter Definition
D      Date
T      Amount
U      Transaction amount (higher possible value than T)
C      Cleared status
N      Number (check or reference number)
P      Payee/description
M      Memo
A      Address (up to 5 lines; 6th line is an optional message)
L      Category (category/class or transfer/class)

S      Category in split (category/class or transfer/class)
E      Memo in split
$      Dollar amount of split
%      Percentage of split if percentages are used
F      Reimbursable business expense flag
X      Small Business extensions
^      End of entry

Note that S,E and $ lines are repeated as needed for splits.


Time and Expense Format
-----------------------
The following QIF extension added by Iambic Software
to handle time and expense tracking.  This is used in particular
by handhelds (Palm and WinCE).  TEF is claimed to be a superset
of the QIF format.

TEF Files begin with the header:
#TEF VERSION X.YYY
Documented below is version 1.01

#      Any line beginning with # is a comment and not parsed
B      City
F      Reported
H      Report #
J      Attendees
K      Reimbursable
R      Receipt
U      Begin Odometer
V      End Odometer
W      Private
X      Exchange Rate
Z      User

1      Client
2      Project
3      Activity
4      Expense Type
5      Account
6      Vehicle
7      Currency
8      Task
9      (not used)
0      (not used)

@      Billing Code
!      Tax Amount
%      Uses Splits
(      SalesTaxRate1
)      SalesTaxRate2
=      Flat Fee Amount
\      Status1
/      Status2
&      Status3
<      Status4
>      Status5
?      Keyword: TIME, EXPENSE, CLIENT, PROJECT, ACTIVITY, TYPE,
       TASK, VEHICLE, PAYEE, CURRENCY. If absent, entry is
       assumed EXPENSE type as compatible with QIF

*      Duration hh:mm:ss

+      Timer On
[      Start time
]      End Time
{      TimerLastStoppedAt
}      (not used)
|      Notes


When importing type CLIENT, PROJECT, ACTIVITY, TYPE, TASK, VEHICLE,
PAYEE, CURRENCY the following are used:

N      Name
C      Code
R      Rate
L      Link
W      Private


Security Prices
---------------
The records in a list of security prices do not use any letter
identifiers, and take the following form:
"<symbol>",<price>,"<date>"
where <symbol> is the security's ticker symbol, <price> is the security
price, and <date> is the date the security had that price.
The price can be either a decimal number of a whole number followed by
a practional price.  For example, for shares of Intuit updated 6/30/98,
with a price of $50.50 per share, the price record would be:
"INTU",50 1/2,"6/30/98"
or
"INTU",50.50,"6/30/98"
Each price is followed by a ^ (end of entry indicator).


=====================================================================
General Notes
=====================================================================

Dates
-----
Dates in US QIF files are usually in the format MM/DD/YY, although
four-digit years are not uncommon.  Dates sometimes occur without the
slash separator, or using other separators in place of the slash,
commonly '-' and '.'.  US Quicken seems to be using the ' to indicate
post-2000 two-digit years (such as 01/01'00 for Jan 1 2000).  Some
banks appear to be using a completely undifferentiated numeric string
formateed YYYYMMDD in downloaded QIF files.

European QIF files may have dates in the DD/MM/YY format.


Monetary Amounts
----------------
These typically occur in either US or European format:

10,000.00  Ten Thousand Dollars (US format)
10.000,00  Ten Thousand Francs  (European format)

An apostrophe is also used in some cases:

10'000.00  Ten Thousand Dollars (Quicken 4)
10'000,00  Ten Thousand Francs  (unconfirmed)

Within a given QIF file, the usage of a particular numeric format
appears to be consistent within a particular field but may be
different from one field to another.  For example, the Share Amount
field can be in European format but the Split Amount in US.  No
radix-point is required and no limit on decimal places is evident, so
it's possible to see the number "1,000" meaning "1 franc per share"
"1,000" meaning "one thousand shares" in the same transaction (!).


Investment Actions
------------------
The N line of investment transactions specifies the "action" of the
transaction. Although not a complete list, possible values include
the following:

QIF N Line    Notes
============  =====
Aktab         Same as ShrsOut.
AktSplit      Same as StkSplit.
Aktzu         Same as ShrsIn.
Buy           Buy shares.
BuyX          Buy shares. Used with an L line.
Cash          Miscellaneous cash transaction. Used with an L line.
CGMid         Mid-term capital gains.
CGMidX        Mid-term capital gains. For use with an L line.
CGLong        Long-term capital gains.
CGLongX       Long-term capital gains. For use with an L line.
CGShort       Short-term capital gains.
CGShortX      Short-term capital gains. For use with an L line.
ContribX      Same as XIn. Used for tax-advantaged accounts.
CvrShrt       Buy shares to cover a short sale.
CvrShrtX      Buy shares to cover a short sale. Used with an L line.
Div           Dividend received.
DivX          Dividend received. For use with an L line.
Errinerg      Same as Reminder.
Exercise      Exercise an option.
ExercisX      Exercise an option. For use with an L line.
Expire        Mark an option as expired. (Uses D, N, Y & M lines)
Grant         Receive a grant of stock options.
Int           Same as IntInc.
IntX          Same as IntIncX.
IntInc        Interest received.
IntIncX       Interest received. For use with an L line.
K.gewsp       Same as CGShort. (German)
K.gewspX      Same as CGShortX. (German)
Kapgew        Same as CGLong. Kapitalgewinnsteuer.(German)
KapgewX       Same as CGLongX. Kapitalgewinnsteuer. (German)
Kauf          Same as Buy. (German)
KaufX         Same as BuyX. (German)
MargInt       Margin interest paid.
MargIntX      Margin interest paid. For use with an L line.
MiscExp       Miscellaneous expense.
MiscExpX      Miscellaneous expense. For use with an L line.
MiscInc       Miscellaneous income.
MiscIncX      Miscellaneous income. For use with an L line.
ReinvDiv      Reinvested dividend.
ReinvInt      Reinvested interest.
ReinvLG       Reinvested long-term capital gains.
Reinvkur      Same as ReinvLG.
Reinvksp      Same as ReinvSh.
ReinvMd       Reinvested mid-term capital gains.
ReinvSG       Same as ReinvSh.
ReinvSh       Reinvested short-term capital gains.
Reinvzin      Same as ReinvDiv.
Reminder      Reminder. (Uses D, N, C & M lines)
RtrnCap       Return of capital.
RtrnCapX      Return of capital. For use with an L line.
Sell          Sell shares.
SellX         Sell shares. For use with an L line.
ShtSell       Short sale.
ShrsIn        Deposit shares.
ShrsOut       Withdraw shares.
StkSplit      Stock split.
Verkauf       Same as Sell. (German)
VerkaufX      Same as SellX. (German)
Vest          Mark options as vested. (Uses N, Y, Q, C & M lines)
WithDrwX      Same as XOut. Used for tax-advantaged accounts.
XIn           Transfer cash from another account.
XOut          Transfer cash to another account.


Category/Transfer/Class line
----------------------------
The "L" line of most transactions specifies the category, transfer
account, and class (if any) of the transaction.  Square brackets
surrounding the contents mean the transaction is a transfer to the
named account.  A forward slash separates the category/account from
the class.  So overall, the format is one of the following:

   LCategory of transaction
   L[Transfer account]
   LCategory of transaction/Class of transaction
   L[Transfer account]/Class of transaction

In stock transactions, if the 'N' field (action) is MiscIncX or
MiscExpX, there can be *two* account/class pairs on the L line, with
the second guaranteed to be a transfer.  I believe they are
separated by a '|', like so:

   D01/01/2000
   NMiscExpX
   T1000.00
   Lexpense category/expense class|[Transfer account]/transfer class


Cleared Status line
-------------------
The "C" line of specifies the cleared status. The second character
in the line, if present, may be any of:

* Cleared
c Cleared
X Reconciled
R Reconciled
? Budgeted
! Budgeted


=====================================================================
Sample Files
=====================================================================

Investment Transactions
-----------------------
!Account
NAssets:Investments:Mutual Fund
TInvst
^
!Type:Invst
D10/30/2006
Q0.9
T500
PPurchase
NBuyX
L[Assets:Investments:Mutual Fund:Cash]
YFOO
^
!Type:Invst
D11/28/2006
Q0.897
T100
PSale
NSellX
L[Assets:Investments:Mutual Fund:Cash]
YFOO
^
