<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://illuminatedcomputing.com/">
  <id>https://illuminatedcomputing.com/</id>
  <title>Illuminated Computing</title>
  <updated>2015-08-01T00:00:00Z</updated>
  <link rel="alternate" href="https://illuminatedcomputing.com/" type="text/html"/>
  <link rel="self" href="https://illuminatedcomputing.com/tags/money/atom.xml" type="application/atom+xml"/>
  <author>
    <name>Paul A. Jungwirth</name>
    <uri>https://illuminatedcommputing.com/</uri>
  </author>
  <entry>
    <id>tag:illuminatedcomputing.com,2015-08-01:/posts/2015/08/ledger_with_autosync/</id>
    <title type="html">Ledger with Autosync</title>
    <published>2015-08-01T00:00:00Z</published>
    <updated>2015-08-01T00:00:00Z</updated>
    <link rel="alternate" href="https://illuminatedcomputing.com/posts/2015/08/ledger_with_autosync/" type="text/html"/>
    <content type="html">
&lt;p&gt;A while back I started tracking my finances with &lt;a href="https://github.com/ledger/ledger"&gt;legder-cli&lt;/a&gt;, a command-line tool for double-entry bookkeeping. It’s been a lot of fun, but one of the stumbling blocks is recording each transaction by hand. Fortunately almost every bank nowadays offers an API so you can download your recent account activity in a format like OFX (Open Financial Exchange) or QFX (Quicken’s extended OFX), and ledger has tools to import that data.&lt;/p&gt;

&lt;p&gt;For this I use &lt;a href="https://github.com/egh/ledger-autosync"&gt;ledger-autosync&lt;/a&gt;, which is built on top of &lt;a href="https://github.com/captin411/ofxclient"&gt;ofxclient&lt;/a&gt;. First you run &lt;code&gt;ofxclient&lt;/code&gt; to create a &lt;code&gt;~/ofxclient.ini&lt;/code&gt; file with the details of all your accounts. Then you run &lt;code&gt;ledger-autosync&lt;/code&gt;, which will first read your ledger file (whatever &lt;code&gt;$LEDGER_FILE&lt;/code&gt; points to), then contact the banks and print out any new transactions. It tries to guess expense categories, but often you need to correct these. Still, that’s a lot easier than typing in everything!&lt;/p&gt;

&lt;p&gt;Because of this step, I like to have &lt;code&gt;ledger-autosync&lt;/code&gt; append to a &lt;code&gt;review.ldg&lt;/code&gt; file, which I periodically edit to correct expense categories, then cut-and-paste into my regular &lt;code&gt;$LEDGER_FILE&lt;/code&gt;. I also do some extra tweaking to format the entries how I like them. Here is the command I use:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;div class="code"&gt;&lt;pre&gt;&lt;code class="language-sh"&gt;ledger-autosync \
  -l ~/share/accounting/in-progress.ldg \
  -i 2 \
  | sed 's,^\([0-9]\{4\}\)/\([0-9]\{2\}\)/\([0-9]\{2\}\),\1-\2-\3,' \
  &amp;gt;&amp;gt; ~/share/accounting/review.ldg&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That uses two spaces for indents (&lt;code&gt;-i 2&lt;/code&gt;) and rewrites the dates.&lt;/p&gt;

&lt;p&gt;Also note how I override &lt;code&gt;$LEDGER_FILE&lt;/code&gt; with the &lt;code&gt;-l&lt;/code&gt; option. That’s a trick to keep &lt;code&gt;ledger-autosync&lt;/code&gt; from entering the same transactions twice into &lt;code&gt;review.ldg&lt;/code&gt;. The contents of &lt;code&gt;in-progress.ldg&lt;/code&gt; are just this:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;div class="code"&gt;&lt;pre&gt;&lt;code class="language-sh"&gt;# This file exists so that ledger-autosync will read review.ldg
# and not download entries it's already pulled down
# but we haven't yet reviewed.

include pj.ldg
include review.ldg&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s it! This setup makes it pretty painless keeping track of everything. I don’t have to do a lot of typing, and nothing slips through the cracks. I actually kind of like that categorizing forces me to look at expenses every week or so. If you are thinking about using ledger, hopefully this helps you out!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>tag:illuminatedcomputing.com,2010-02-05:/posts/2010/02/decline-in-inverse-and-leveraged-etfs/</id>
    <title type="html">Decline in Inverse and Leveraged ETFs</title>
    <published>2010-02-05T00:00:00Z</published>
    <updated>2010-02-05T00:00:00Z</updated>
    <link rel="alternate" href="https://illuminatedcomputing.com/posts/2010/02/decline-in-inverse-and-leveraged-etfs/" type="text/html"/>
    <content type="html">
&lt;p&gt;So this post isn’t about programming, but it has a lot of math, and it’s about understanding how something works. Lately my investing has used some ETFs, but I’ve read that if your ETF is inverse or leverage, then it gradually loses money over time—simply because of the mathematics. I wanted to investigate just how this worked.&lt;/p&gt;

&lt;p&gt;First, &lt;a href="http://www.fool.com/investing/etf/mutual-funds-v-etfs.aspx"&gt;a bit of background&lt;/a&gt;: an ETF is an Exchange-Traded Fund, a pretty new thing. It’s not a stock, but a type of derivative used to track something else, such as a sector of stocks. In this regard it’s a bit like an index, but more flexible. So you could have an ETF tracking the performance of pharmaceutical stocks, or financial stocks, or the S&amp;amp;P 500. They are a little different from index-based mutual funds. You can trade them any time during the day, and they don’t have the high minimum purchases required by some mutual funds. On the other hand, you pay a commission, unlike a non-load mutual fund. (In &lt;a href="https://web.archive.org/web/20240813065545/https://www.benzinga.com/110871/ivv-buying-the-s-p-500-without-commissions"&gt;some cases&lt;/a&gt; this may not be true.)&lt;/p&gt;

&lt;p&gt;But the really interesting thing about them is that they can be leveraged or inverse. A leveraged fund aims to achieve some multiple of the daily change of the underlying index. So while the SPY fund tracks the S&amp;amp;P 500, you can get 2x the S&amp;amp;P 500 (both up and down) with the SSO fund. This greater volatility gives you the potential for more profit with each trade, diminishing the relative size of the commission. It’s a bit like you invested twice as many dollars as you actually have.&lt;/p&gt;

&lt;p&gt;An inverse fund is a leveraged fund with a negative multiplier. You can get funds at -1x, -2x, or I think even -3x. This essentially lets you short the market, something difficult for retail investors to manage. Also, unlike with shorting, you don’t risk an unlimited amount of money. You only risk the money you use to buy the ETF.&lt;/p&gt;

&lt;p&gt;The fly in the ointment is that ETFs, when leveraged or inverse, gradually decline in value. Let’s say we have an index that start at 100, declines to 80 (-20%), then goes back up to 100 (+25%). Now let’s say we were tracking it with four ETFs, a 1x, a -1x, a 2x, and a -2x. They all start at 40. Here are the results:&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;Fund&lt;/th&gt;
&lt;th&gt;t&lt;sub&gt;0&lt;/sub&gt;
&lt;/th&gt;
&lt;th&gt;t&lt;sub&gt;1&lt;/sub&gt;
&lt;/th&gt;
&lt;th&gt;t&lt;sub&gt;2&lt;/sub&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Index&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1x ETF&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-1x ETF&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;48&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2x ETF&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-2x ETF&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;56&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt; As you can see, all our ETFs lost money, except the 1x version. Conspicuously, the -1x and 2x ETF lost the same amount, but the -2x ETF lost more. If we had reversed the order of changes (100 to 125 to 100), we would see the same results.&lt;/p&gt;

&lt;p&gt;So I set out to analyze the mathematics behind all this. Let’s start with some equations describing our targeted fund, the index. I’ll call its initial value T. Our intermediate value will be T’. Our final value will be T’‘—but of course this is equal to T. Let’s call the first percent change d, and the second percent change d’. That gives us these equations:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;T’ = T + dT T = T’‘ = T’ + d’T’ If we substitute T for T’ and solve for d’, we get: T = (T + dT) + d’(T + dT) 0 = dT + d’(T + dt) -dT / (T + dT) = d’ d’ = -d / (1 + d) Now let’s write out the equations for our derived fund, D (the ETF). We’ll use D, D’, D’‘ to correspond with T, T’, T’‘. The multiplier of our ETF will be f. So in a 1x ETF, f = 1, but in a -2x ETF, f = -2. That gives us these equations: D’ = D + fdD D’‘ = D’ + fd’D’ Substituting, we get: D’‘ = (D + fdD) + f * (-d/(1+d)) * (D + fdD) So far so good, but I’m really interested in the percent lost for each up-and-down cycle. The absolute loss is D - D’‘, so the percent loss is (D - D’‘) / D. Let’s call this L. That gives us: L = (D - D’‘) / D L = (D - ((D + fdD) + f * (-d/(1+d)) * (D + fdD))) / D L = (D - D - fdD - f * (-d/(1+d)) * (D + fdD)) / D L = -fd - f * (-d/(1+d) * (1 + fd) L = fd/(1+d) * (1 + fd) - fd L = fd(1+fd) / (1+d) - fd(1+d) / (1+d) L = (fd(1+fd) - fd(1+d)) / (1+d) L = fd(1+fd-1-d) / (1+d) L = fd(fd-d) / (1+d) L = fd&lt;sup&gt;2&lt;/sup&gt;(f-1) / (1+d) L = f(f-1) * d&lt;sup&gt;2&lt;/sup&gt; / (1+d) That final equation tells us that the loss is proportional to f and d. Well, d is kind of obvious: the more our underlying index changes, the more the ETF will change. But f is quite interesting. The more leveraged we are, the more we lose on each cycle. Although neither factor is as simple to write out as we might like, consider this. f(f-1) is almost f*f, or f&lt;sup&gt;2&lt;/sup&gt;: f*(f-1) &amp;lt; f*f f*(f-1) &amp;lt; f&lt;sup&gt;2&lt;/sup&gt; The effect of f is almost a square. We could imagine this as f&lt;sup&gt;1.9&lt;/sup&gt;, although that isn’t quite right.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At first glance, it seems we could make a similar simplification with d, since d&lt;sup&gt;2&lt;/sup&gt;/(d+1) is a little less than d&lt;sup&gt;2&lt;/sup&gt;/d:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;d&lt;sup&gt;2&lt;/sup&gt;/(d+1) &amp;lt; d&lt;sup&gt;2&lt;/sup&gt;/d d&lt;sup&gt;2&lt;/sup&gt;/(d+1) &amp;lt; d So d’s effect would be a little less than d: sort of like d&lt;sup&gt;0.9&lt;/sup&gt;. But this is misleading, because d&lt;sup&gt;2&lt;/sup&gt;/(d+1) only approximates d for large values, and our d will (probably) never go above 1. In fact it’s only interesting for values like 0.01 or 0.1 or maybe (gulp) 0.5. At that range, we get values like:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;d&lt;/th&gt;
&lt;th&gt;d&lt;sup&gt;2&lt;/sup&gt;/(d+1)&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.01&lt;/td&gt;
&lt;td&gt;0.00009&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.02&lt;/td&gt;
&lt;td&gt;0.00039&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.03&lt;/td&gt;
&lt;td&gt;0.00087&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.04&lt;/td&gt;
&lt;td&gt;0.00153&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;td&gt;0.00238&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;td&gt;0.00909&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.20&lt;/td&gt;
&lt;td&gt;0.03333&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.30&lt;/td&gt;
&lt;td&gt;0.06923&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.40&lt;/td&gt;
&lt;td&gt;0.11428&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.50&lt;/td&gt;
&lt;td&gt;0.16666&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The graph looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="/img/etf_decline.jpg"&gt;&lt;img alt="" class="alignnone size-full wp-image-112" height="310" src="/img/etf_decline.jpg" title="etf_decline" width="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or at close range, like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="/img/etf_decline_closeup.jpg"&gt;&lt;img alt="" class="alignnone size-full wp-image-113" height="309" src="/img/etf_decline_closeup.jpg" title="etf_decline_closeup" width="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All this means that comparatively speaking, f has a greater effect than d.&lt;/p&gt;

&lt;p&gt;We could chart f’s effect for different levels of leverage:&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;f&lt;/th&gt;
&lt;th&gt;f(f-1)&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-2&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-3&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-4&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-5&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt; In other words, each “step” up in leverage increases your loss, and going inverse counts as one additional “step.”&lt;/p&gt;

&lt;p&gt;By multiplying these values with those from d’s table, you can see your loss for each cycle. For a 2x or -1x ETF, you lose about 2% of your investment for each 10% cycle, or 0.02% for each 1% cycle. For a -2x ETF, you lose about 6% for a 10% cycle or 0.06% for a 1% cycle. Best not to stay in these investments for too long!&lt;/p&gt;

&lt;p&gt;The next question is: how long is right? I guess you could look at the last few years to count the number of cycles, and try to figure out an ETF’s theoretical decline if the market had no net change. But the conventional wisdom answer seems to be about a week, and this sounds right to me. You’re really betting on the direction of the next move, and if you get that wrong, it’s going to cost you. So to make money with these ETFs, you need to get not just the direction right, but the timing, too. It’s hard enough just to get the direction! This need to be right about timing makes them risky for the same reason options are risky: your bet only has so long to play out.&lt;/p&gt;

&lt;p&gt;Now here is another thought. Take a look at a graph of f(f-1):&lt;/p&gt;

&lt;p&gt;&lt;a href="/img/etf_decline_f.png"&gt;&lt;img alt="" class="alignnone size-full wp-image-115" height="334" src="/img/etf_decline_f.png" title="etf_decline_f" width="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, between 0 and 1, this graph dips below 0. That means that if you had a x0.5 ETF, say, you would actually &lt;em&gt;make&lt;/em&gt; money over time. I wonder if there are practical reasons to prevent this, or if the return is just too small, so you’d do better putting your money in a bank. Anyway, it’s an interesting thought… .&lt;/p&gt;
</content>
  </entry>
</feed>

