Notes: Bitcoin Exchange

Plan for an international fully electronic exchange.

* Objectives
  - eliminate latency arbitrage 
    . secretize info
      All bids submitted cryptographically?
      with market clearing at fixed intervals (once a sec)?
      should depth be published?
    . publicize info
      Distributed clearing algorithm, every participant must coordinate
      clearing occurs according to logical time
    + in both cases it seems necessary to encapsulate the clients algorithm into a jail
      so that it conforms to the clearing expectations. This means no more do high freq
      traders get access to the hardware or data from the wire. The sell for the exchange
      is that they can operate 24/7.
  - exchange requirements:
    1. Gather and enhance liquidity
    2. Preserve confidentiality + trust (usu. through anonymous orders)

* Who can trade?
  The exchange is marketed at large financial institutions, so that they can manage country risk.
  They can acquire a seat on the exchange by depositing a minimum (large) amount of gold in exchange for electronic currency.
  The exchange has a permanently fixed gold to e-currency ratio.

* What can be traded?
  Commodities, International Corporations, Currencies.
  The exchange is international, don't bother trading country-specific institutions, no matter how large.
** How does a company issue shares?
  Shares are analogous to a currency issued by a specific company, like money from a private bank.
  Each company traded on the exchange gets its own version of the same crypto-currency issued by the exchange.
  The company is given a named account, through which it can barter company shares with the exchange currency.
** Naked shorting?
  Equivalent to counterfeiting the company shares: prohibited.
** Shorting?
  The ability of individual participants to short is analogous to lending a company's currency.
  Should be possible to know, at all time, how much shorting, totaly, has occurred 
** Issuance of dividends?
  If it is possible for the currency issuer to know all participants holding shares,
  then it can directly transfer to those holders a dividend.
  The company deposits gold with the exchange, and pays the dividend in exchange currency.
  - what about derivatives/options, and lending?
** Market Making
  The ability of a company account to issue shares means that it has abilities that other market makers do not.

Consider: perhaps the currency issuer is the 3rd party to all transactions.
  Then, even though anonymity prevents knowing who is involved the issuer can reject lending operations after a certain amount.
  Thus the issuer is privy to, and controls the total amount of lending which occurs.

* When is the market open?
  24/7, barring technical difficulties which lead to outages fixed ASAP.
  Market remains open on holidays.

* How are things priced?
  All assets denominated in an electronic currency similar to bitcoin, with the following properties:
  - Transactions are auditable, cryptographically secure.
  - Secret binding of person/institution to account number keeps activity anonymous.
  - Exchange has to be able to create/destroy currency to keep ratio fixed with deposits.
  - It should not be possible to use the currency outside the exchange.
    This prevents the formation of a shadow market which would circumvent the exchange rules.
    Can be accomplished by making the exchange a required 3rd party which verifies all transactions.
  - Counterfeiting prohibited: only the exchange can issue money.
    For shares, only the company can issue shares.
  - Lending allowed: but always possible to compute the global amount of lending which has occurred.
    Might not be necessary:
     - Is lending necessary for margin? Option market also offers leverage.
     - Is lending necessary for shorting? Option market offers ability to bet on drop without recourse to borrowing shares.
  - 3rd party taggable: so that usage as collateral can be tracked.
    Would be good to tag the currency itself with a coroutine/continuation that ties the currency units to their obligation.
    This way, the money tracks itself and the exchange doesn't have remain a monitor.
    Not completely necessary, exchange can act as escrow
  - Currency must be taggable with programs:
    these programs track obligations, execute interest payments, dividends, and splits.
    if the exchange coordinates market clearing to be on-the-second, then the above programs execute on-the-half-second
  - Composibility of these programs?
    Can a borrower pledge asset X in as the interest for a loan of asset Y?
    more difficult to price: but I don't see why not.
    What if borrower pledges loaned funds as interest for the loan?
    Shall the lender accept these at face value? or according to a pricing model? who determines price model: borrower, lender, exchange?
    It get's too complicated for exchange to match sellers/buyers if the valuate differently the currency exchanged,
    which would happen if all currency gets tagged. Not exactly 'fair' for exchange to treat tagged money at face value,
    because then what is received via a bid for asset X carries unpredictable tag, because it is non-deterministically from a seller with tagged asset X.
    That would mean exchange is only smooth with 'pure' currency/shares. So options chains are difficult to setup/rollover.
    - Is there maybe a secondary exchange mechanism for transforming obligated instruments into 'pure' ones?

** Pricing Quanta?
  - How and to what level are is the crypto-currency divisible?
  - Can participants trade fractional amounts of shares?
** Lending and interest charges?
  - How shall participants lend shares/currency to each other?
  - How shall interest be calculated?

* How does the exchange maintain Profitability?
  - Either fees charged on per-transaction basis, or monthly dues.
    would prefer fixed monthly dues, because it simplifies algorithmic trading.
    actually, charging per-bid would dis-incentivize algos from flooding the market with cancellations.
  - Storage fees of the deposited gold.
    would prefer not, as an enticement to participate.
  - Fees on listings.
    charge companies for being listed on the exchange.
    would prefer not. Also, who would be charged for currencies and commodities?
  - Fees on computer usage.
    each participant pays a fee to have a computer that participates in the market clearing
    best option so far: electricity + facilities are a fixed cost relative to growth in participation
                        the institutions meant to participate are large, and can be charged exorbitantly
    however, it will restrict interest during launch phase

* Market Clearing?
  :todo: no idea yet. But would like to eliminate front-running and latency arbitrage.
  - would like to have a fully distributed clearing algorithm

Prob: If the exchange uses crypto verifiable transactions, then the market clearing algo is about matching
      actual sellers to actual buyers. That is, the exchange can't take the difference between bid and ask,
      because the transfer occurs directly between parties, and the exchange serves as 3rd party witness.

Advantage: The use of e-currency might make possible a market-wide audit.
     My idea of computing systemic risk might actually be realizable.
     Although it won't be possible to tie accounts to participants, if each account's position is open knowledge
     then the graph of interdependencies can be tracked: counter-party risk is assessable.

* Lending
 :problem: lending has default risk, because the borrower does not necessarily have the ability to pay interest.
   how shall interest be payed?
   have the lent money contain a tag indicating that interest is due?
   doesn't completely make sense for collateral to be pledged for a loan
 - what if the borrower pledges the interest (as downpayment)?
   That means the currency from the lender, and the interest become tied together.
   If the borrower spends the loan, then the obligation travels with the currency.
   The interest pledge is transferred from the original borrower to the receiver of the loaned funds.
   That is, the new holder of funds is now responsible for paying the interest.
   Any money tied up in a loan obligation is discountable in value by the interest pledge.
   Alternatively, the borrower could pay up the amount + discount (amount + interest pledge), to the new owner.
   The borrower then faces higher prices when using this currency: combats the inflationary (fractional-reserve) aspect of lending.
   The lender can sell the loan: this transaction merely rewrites which account receives the interest payments.
   The payment is guaranteed, because the original borrower couldn't borrow without pledging the total interest amount.
 - Perhaps I don't want to tag any monies lent.
   Rather, if every obligation on the borrower's account were known, the lender could make the decision.
   The borrower's account then bears an obligation. Assets pledged as collateral are tagged.
   The monies lent are unhampered, so the borrower can use them, as if they were his own.
 :problem: How to run a market for loans?
   - borrow puts in an "ask for x amount of y currency?"
   - the ask is broadcast to all lenders, each of which returns a bid?
     Is the bid an interest rate? Expiration date? Payment schedule? Required collateral (what currency)?
   - lender puts in a "bid for x amount of y currency at z interest rate?"
 :problem: If borrowers are allowed to fail, how to determine when they are insolvent?
   What protocols should be followed to retrieve the monies? Suspend account? Freeze real-world assets?
* Options
  NYSE once tried hosting derivatives market, but it didn't work to have both stock and deriv on same platform
  These rules prevent fraud in the option market.
  Collateral is always tagged as such, so counter-party risk is not an issue.
** Derivatives are not exactly free, because of the counter-party risk.
   Even with pledged collaterals, the chance that a buyer executes the option depends on the buyer.
   Perhaps it would be better to pool and average?
   If 80% of the buyers execute the option, then all sellers each pay 80% of the pledged collateral.
   Is this fair?
** Properties: strike price, expiration date, number shares
   How to clear a market with all these variables?
** Buying a Put: The buyer of the put, has the right, but not an obligation, to sell the asset at the strike price by the future date.
   The Put Buyer does not have to have the shares to back the put.
** Selling a Put: The seller of the put, has the obligation to buy the asset at the strike price if the buyer exercises the option.
   The Put Seller must have the currency to back the put (at strike price).
   The Exchange tags the currency as collateral (so it cannot be repledged).
** Buying a Call: The buyer of the call has the right, but not the obligation, to buy the asset at the strike price by the future date.
   The Call Buyer does not have to have the currency to back the purchase.
** Selling a Call: The seller of the call, has the obligation to sell the asset at the strike price if the buyer exercises the option.
   The Call Seller must have the asset to back the call.
   The Exchange tags the shares as collateral (so they cannot be repledged).

* Futures
  I have no ideas.

* Complex Contracts
  Some contracts, such as options and lending, have several variables that need to be simultaneously satisfied.
  I need a market making or market clearing algorithm that can take this variance into account.
  Today's approach is to standardize some of the variables.
  Bonds are for 1, 2, 3, 5, 10 years.
  Options are for 100 underlying shares, usually +/- .05 increments around the current stock price, in 1,2,3,6 month expirations.

* Competition:
  - ICE,
  - CME Group.

* Research
  - The WALRAS Algorithm:A Convergent Distributed Implementation of General Equilibrium Outcomes
  - Online Algorithms for Market Clearing

* Political Implications
  - the US and prolly also central bankers will not want to find their currency programs undermined
    will have to work alongside these influences, or be assassinated
  - When getting serious about these influences, use by Thomas Barnett
  - also consult James Turk (GoldMoney), James Rickards (Currency Wars)

* Decentralization
  instead of having a centralized market center, with racks in close proximity and orders coming in from the world
  can create an overlay network of trading hubs on the internet itself. (cf Yair Amir for implementation
  - Accelerando group has a whitepaper about bitcoin exchange
  Only thing necessary is an API.
  Adoption Problem: How to encourage critical mass participation?
   - Begin as service that offers 24/7 trade access to stocks that roll-over from NY-London-Tokyo
  Trust Problem: How to ensure that participants aren't simply naked shorting to raise funds?
   - market makers are arbitrageurs which will always help you 'cash out'?
   - full reserve backing on bets? (I don't know about options, presumably an escrow service)
   - immediate funds transfer (no waiting for end of day settling on accounts, result transfer/exchange can be used immediate)
    1. Find the goods/commodities/stocks
       - find a clearing house? in a registry?
       - find a price stream?
       - find a transaction partner?
    2. Transactions
       - 3rd party escrow?
       - price reporting (broadcast) mechanism
    3. Data
       - order book(s)? depth?
       - lamport clock of transactions?

* Enforcement
  If the data feed is controlled, you can cut it off as a penalty for bad behavior. Nobody wants to trade blind.
  No equivalent enforcement in a decentralized system. Anyone can come and go as they please.

* Adoption Problem
  As an independent ECN running on a separate currency, I won't have enough capital to ensure fair/fast trades with other ECNs + Exchanges for all securities.
  Have to encourage (or subsidize) those willing to play arbitrageur, market maker for the liquidity they provide.
  In a fully decentralized system, this is even more difficult, because won't be able to track these players in order to give them subsidy.
  How will other players be able to post (introduce) new goods (securities/currencies/commodities) into the market?
  How will people have enough trust that someone will take the opposite side of the trade, letting them 'cash out'?

* Liquidity evaporation problem:
  - when trust breaks down, the algos simply quit
  - can we take away ...
    - ability to cancel orders?
    - ability to stuff the order book?

* A Market of Markets
  Was reading in "A History of Nasdaq" that some firms are better suited to auction market, and other are better suited to dealer market.
  Would be nice if there were packages of software (essentially automating the specialist job, using firm capital) that would allow de-factor auctioneer in a dealer market.
  Will have to default to dealer market because of the decentralized nature.

* Funding the Exchange Itself (player incentives)
  - The exchange board gets money by charging listing fees
    The company must be in good staning:
    - May not list a company without first signing up market makers
    - May perform indep. financial audit
    - May not list company unless a member of exchange is promoting it
  - Exchange members make/break their career on IPOs.
    - have to find promising company
    - convince others it's a worthy investement
    - career advancement tied to finding successful companies
  - Traders don't want to invest in shady/risky companies
    - corps have to regularly report finances (in all required languages)
    - corps have to be solvent (pass minimal listings reqs)
    - corps pay exchange to list (access to the capital provided by market visibility)

* Found out that there is a forum, which already has discussions in this direction Blockchain security tracking/colored coins/smart contracts - short python script Distributed bond markets and pay-to-policy outputs Decentralized BTC Stock Market [Goodbye GLBSE]

* PeerMint: Decentralized and secure accounting for peer-to-peer applications (2005) David Hausheer, Burkhard Stiller
  - addresses the problem of free rider nodes.
    Could be good to use this as a market-based liquidity guarantee.
    Each node can elect to act as a broker, in which case it is rewarded for volume, matching, uptime, etc.
    The reward incentivizes nodes to elect for broker status.
  - Project homepage:

* Decentralized order handling [Wed Jan 30 20:42:21 PST 2013], talk with Thornton
    There is some server (or set of servers), hosting a market clearing algorithm
    they publish a timestamped price history, and can be found via a distributed hash table lookup
    clients submit orders, and handshake with the server to do so
    => order isn't considered good (entered in order book) unless the client agrees
    => order cancellation ??? should it be delayed for client ok? or immediate?

* Bittorrent: [Sun Mar  3 19:19:47 PST 2013], research on DHT
  - designates some web servers as trackers, they support simple HTTP
    trackers help peers find each other, providing contact info
    collects statistics
    build a random connection graph of downloaders
  - downloaders start by getting random piece, then switch to rarest first
    important to get a piece as quickly as possible
    end game by requesting all remaining pieces from all connections
  - peers reciprocate uploading to peers that upload to them
    rolling 20-sec average to determine speed rates, recalc every 10 sec (piggy-backs TCP transfer characteristics to saturate upload capacity)
  => bittorrent is not really a DHT, and has specific design for file transfer

* Outstanding problems: [Sun Mar  3 19:40:04 PST 2013]
  1. DHT to find an limit-order book given a company
     monetization: should I act as ICANN for 'the big board of listings'?
     - naturally formed among those peers that hold positions on the good
     - how to prevent order-book stuffing?
       entry requires solving crypto (or timeout) to cancel?
  2. Propagating new bids throughout the order-book