Exchange Rates
Suppose that we are Mexico, and the rest of the world consists of one other country, the United States.

 On the left hand side of the diagram above, we have all the activities for which Mexicans want dollars.  Mexicans who want U.S. goods or U.S. securities need to get hold of U.S. dollars to buy them. On the right hand side of the diagram above, we have all the activities in which U.S. citizens want pesos.  Someone in the U.S. who wants Mexican goods or Mexican assets needs to get hold of pesos to buy them.

(In this diagram we are looking at gross financial flows, not just net flows.  The net foreign investment (If) that we use in macro would be this "gross foreign investment" minus "gross foreign savings."  Gross foreign investment is our (Mexico's) total purchases of U.S. securities; gross foreign savings is total U.S. purchases of Mexican securities.  To remind yourself of what the whole diagram looked like, go back to the flows tutorial.)

The foreign exchange market is where people with dollars who want pesos meet people with pesos who want dollars:

This market should arrive at an exchange rate, which is the peso price of the dollar or the dollar price of the peso.  We can use a standard micro model, which we develop below, to depict how the price is set.

Setting up the Model
First, we need to decide whether to draw the diagram for flows of the home currency or flows of the foreign currency.  Some people draw the diagram for the home currency, in which case the price is that of the home currency in foreign units, and since we are looking at flows of the home currency, supply comes from home and demand from abroad.  Other people draw the diagram in terms of the foreign currency.  In that case the price is that of the foreign currency in home units, thus supply of the foreign currency comes from abroad and demand for the foreign currency comes from home.  Either way gets you the same answers in the end.  Below we follow the latter convention, modeling the foreign currency, which for Mexico is the dollar.

 When we model the flow of the foreign currency, the terms we use fit nicely with balance of payments accounting.  In the BoP, we assign a plus sign to any kind of transaction that is a source of foreign excnange, and a minus sign to any transaction that is a use of foreign exchange.  Therefore:  Exports, sales of assets to foreigners, and transfers from foreigners are all sources of foreign exchange (+ in the BoP).  From Mexico's viewpoint sources of dollars -- in other words these activities account for the supply of dollars to the foreign exchange market.  Imports, purchases of assets from foreigners, and transfers to foreigners represent uses of foreign exchange (- in the BoP).  From Mexico's viewpoint these are all reasons why Mexicans demand dollars.

Now we can start setting up our diagram:
 Since we are showing the market in the foreign currency, we will put on the vertical (price) axis the price of the foreign currency in terms of our own currency: the peso price of the dollar.  Notice: when this price "rises" it takes more pesos to buy a dollar and the peso is "weaker."  When it falls dollars are cheaper and the peso is "stronger."    On the horizontal axis we are showing flows -- amounts traded in some period of time.  For the sake of simplicity we won't specify units.

When you build these things, you want to reason from the price to the quantity.  So ask: how would the supply of dollars to this market be affected by the number of pesos you can get for a dollar?  Because more pesos to the dollar will make Mexican goods more attractive to dollar-holders, causing more dollars to be offered on the foreign exchange market, the curve representing the supply of dollars slopes up.

Then ask: as it takes more pesos to buy a dollar, what will happen to the demand for dollars (from peso holders)?  As dollars get more expensive so do U.S. goods, so Mexicans will demand fewer dollars in the foreign exchange market.

Those are two adjustment stories.  You can use the same model to show what happens if the demand for or supply of dollars fell.  Those are all examples of how a floating exchange rate works.  The main problem with floating exchange rates is that any change in demand by foreigners for our goods or securities is likely to move the exchange rate,  which will then affect every other kind of demand, especially for goods.  The result can be considerable volatility and uncertainty.  On the other hand trying to fix the rate can cause problems as well.

Before manipulating the diagram let's be sure we're clear on what it shows.

At an exchange rate of 3 pesos to the dollar, the same quantity of dollars will be supplied as dollars demanded.  If the exchange rate were higher, say four pesos to the dollar, a much greater quantity of dollars would be supplied than demanded.  If it were lower, say two pesos to the dollar, far fewer dollars would be supplied than demanded.

Suppose that something happened to increase the supply of dollars: Mexico became a more popular vacation spot, or Mexican bonds became more attractive to U.S. wealth-holders.

We would indicate that change in supply conditions by an outward shift of the supply curve -- for any given exchange rate, there would now be a greater quantity of dollars supplied to the foreign exchange market.

At the old 3:1 rate, the supply of dollars would exceed demand.  Dollar-holders, competing among each other for pesos, would drive the price down to 2 pesos to the dollars.  The peso strengthens.  (Can you see that a sudden U.S. interest in Mexican bonds would hurt Mexican exporters?)

If Mexicans earned higher incomes and wanted more U.S. goods, that would change conditions of demand for the dollar -- at any given exchange rate, Mexicans would want more dollars.

At the old rate of 3:1, the quantity of dollars demanded now exceeds the quantity supplied.  Mexicans compete among themselves for the available dollars,  and end up having to pay more pesos per dollar.  The peso weakens.

How to Fix or "Peg" an Exchange Rate
In the two examples above, what caused the exchange rate to move was the existence of either an excess demand for dollars or an excess supply of dollars at the old exchange rate.  In order to fix or "peg" the rate,  the central bank has to be willing and able to step in and fill those gaps.

If the supply of dollars increased and the Mexican government did not want to allow the peso to strengthen, then it would buy dollars and sell pesos to fill this gap.

(In a modern credit-money system, a central bank can issue as much of its own currency as it likes.)  Thus the additional U.S. citizens coming into this market get the extra pesos they want to  buy more Mexican bonds.  Problems?  This will increase the Mexican money supply (moe pesos in circulation) and may encourage inflation.  But the Mexican Central Bank does increase its foreign reserves -- the dollars it holds.

Another effect may be that the increased money supply pushes down Mexican interest rates.  That might make Mexican bonds less attractive to foreigners.

If Mexico got tired of this it could "revalue" its currency by lowering the pegged rate to 2:1.  Or it could float.

If on the other hand the demand by Mexicans for dollars increased, the Mexican central bank would have to do the opposite: buy pesos and sell dollars to meet the excess demand for dollars.

This is a little harder, because while the Mexican central bank can make pesos it cannot make dollars.  It needs to accumulate dollars as in the example above.  So Mexico will sell accumulated dollars to Mexicans who want them, in exchange for pesos.   If it does this too long it will run out of foreign reserves, and it will have to devalue -- raised the pegged rate to 4:1.  Or it could float.

(Advanced topic -- Monetary effects:  In the first case above the  Mexican money supply (pesos in circulation) rose.  That should tend to lower the interest rate (the cost of borrowing money).  A lower interest rate makes Mexican securities less attractive, reducing foreign demand for pesos.  In the second case buying pesos removes them from circulation and the interest rate would rise, making Mexican bonds more attractive to foreigners.  That would increase foreign demand for pesos.  So in both cases these interest-rate effects may ease the task of adjustment.)