Friday, December 5, 2008

CHAPTER 1 — Small Programs

CHAPTER 1 — Small Programs
In this chapter you will learn to write small programs in the computer programming language called QBasic. These small programs won't do very much. But in following chapters you will write programs that do much more.
Chapter Goals
• QBasic statements.
• The PRINT statement.
• The END statement.
• Arithmetic operators.
• Strings.
• Sequential execution.
• Syntax errors.
• Bugs.
The small programs in this chapter perform calculations similar to the arithmetic done with a electronic calculator. QBasic does much more than that. But in this chapter, pretend that QBasic is a calculator that uses a keyboard for input. Instead of punching buttons on a calculator, you will write a program.
QUESTION 1:
With a calculator does it matter in which order you push the buttons?

Answer:
Yes.
Programs



When you use a calculator to compute 10 plus 5, you must push:
10
+
5
=
... in exactly that order. Pushing
+
10
=
5
... will not work. The order is important. The same is true for computer programs.
A program is like a recipe for baking cookies: it is a list of instructions which are followed one-by-one in the correct order.

QUESTION 2:
Isn't it odd that a machine can follow a list of instructions?
Answer:
Yes. Until a few decades ago few people believed that this was possible. One of the intellectual goals of this course is for you to understand how machines can follow instructions.
Example Program
A QBasic program consists of lines of text, one after another, like a poem. Each line of a program (or a poem) stays by itself on one line. A line which has an instruction for the computer is called a statement. Not all lines are statements. Some lines are blank. Others are comments intended for a human reader, but not for the computer. Only a line that contains an instruction for the computer is a statement.
Usually the computer runs a program starting with the first statement and proceeding statement by statement until the end of the program is reached.
Here is a complete QBasic program as you see it when you are working with the QBasic system:

Look in Appendix B to see how to enter and run programs. You don't have to do that now to read this chapter. The picture shows many details that are not important right now. The QBasic program is just these two lines:
PRINT 10 + 5
END
The PRINT statement causes something to be printed on the screen of the computer monitor. The last statement in the program is END, which just tells the computer that the program is finished.
QUESTION 3:
How many statements are in this program?
Answer:
Two.
END is a statement. It tells the system to end this run of the program.
Two Statement Programs
Look at the program:
PRINT 10 + 5
END
If you run this program, the computer starts with the first statement:
PRINT 10 + 5
That statement says to:
• Add the number 10 to the number 5
• Print the result on the computer monitor (the computer screen).
This is like an electronic calculator where you enter 10, +, 5, and =. The calculator then shows 15.
In QBasic there are many things that can be done with the sum. To see the sum on the monitor, use PRINT.
QUESTION 4:
What do you think the above program prints on the computer monitor?
Answer:
15
The END Statement
The statement PRINT 10 + 5 adds 10 to 5 and then prints the result 15 on the monitor. Here is what you see on your computer's screen when you run this program:

Don't get lost in the details. The part that the program printed is the number "15". All the other stuff is unimportant and depends on what computer you are using.
Here is the program again:
PRINT 10 + 5
END
The last statement, END signals the end of the program. It is obvious where this program ends, but it is harder to tell with longer programs, so the END statement is necessary for them.
Answer:
15
The END Statement
The statement PRINT 10 + 5 adds 10 to 5 and then prints the result 15 on the monitor. Here is what you see on your computer's screen when you run this program:

Don't get lost in the details. The part that the program printed is the number "15". All the other stuff is unimportant and depends on what computer you are using.
Here is the program again:
PRINT 10 + 5
END
The last statement, END signals the end of the program. It is obvious where this program ends, but it is harder to tell with longer programs, so the END statement is necessary for them.
QUESTION 5:
Do you suppose that the following program is correct?
END
PRINT 10 + 5
Answer:
No, the program is not correct. The computer follows instructions in order. If the first instruction is END the computer ends its run of the program.
Comments
If you run the program again, the computer will start at the first statement again (and end immediately, as before). Here is another program:
' Program to add two numbers
PRINT 10 + 5
END
The first line of this program is called a comment. A comment starts with an apostrophe ( ' ). This is the character just left of the Enter key on the computer's keyboard. Comment lines tell humans what the program does, or what parts of the program do. When the program is run, the computer does not look at the comments at all. The comment lines have no effect on what the program does.
QUESTION 6:
What does the above program do?
Answer:
The program adds 10 to 5 and prints 15 on the monitor.
Comments are Ignored by QBasic
The new program does exactly the same thing as the old program. The two programs are the same except for the comment in the new program. Since comments are ignored, the two programs do the same thing when they are run.
Comments are intended to make it easier for humans to figure out what a program does. When you write a program, you should use comments to explain what you are doing. QBasic ignores comments and just does what the statements ask.
QUESTION 7:
Write a program that adds 1.5 to 4.2 and prints the result on the monitor.
(Write the program with paper and pencil. You can just think the answer, if you want, but please try to answer before continuing.)
Answer:
' Program to add two numbers
PRINT 1.5 + 4.2
END
If you run this program it prints 5.7 on the computer monitor.
Floating Point Numbers
The numbers that you use with QBasic are the same as those you use with an electronic calculator. You can use numbers that include a decimal fraction such as the two numbers above.
Numbers such as 1.5 or 3.14159 or 123.821 are called floating point numbers because the decimal point "floats" among the digits to get to the correct location. A number without a decimal point, such as 12 or -23 or 194, is called an integer.
QBasic can do anything an electronic calculator can do (and much more). For example, it can multiply numbers. To multiply numbers, use * instead of the usual multiply symbol (which is not on the computer keyboard). The character * is on the same key as "8" on the computer keyboard.
QUESTION 8:
Write a program that MULTIPLIES 12.1 by 2 and prints the result on the monitor. (Write the program on a scrap of paper.)
Answer:
' Program to multiply two numbers
PRINT 12.1 * 2
END
If you run this program it prints 24.2 on the computer monitor.
Strings
Computers do more than arithmetic. You have probably used a computer for word processing or for viewing documents on the Web (such as this one). QBasic may be used with words, too. Here is a program that writes Hello World onto the monitor screen:
' Program to write words to the monitor
PRINT "Hello World"
END
In this program the PRINT statement has exactly what you want printed inside quotes (" "). When the program runs, the characters inside the quotes are printed. The quotes are not printed. The "Hello World" is called a string because what you want to print is a string of characters inside the quotes.
QUESTION 9:
Write a program that prints
The sky is falling.
to the computer monitor.
Answer:
' Chicken Little's Alarm
PRINT "The sky is falling."
END
Of course, the comment in your program might not be the same as mine.
Sequential Execution
Characters inside of quotes are printed literally--upper and lower case are printed exactly as in the string, and punctuation (such as the period at the end of the sentence) is printed.
When the computer system performs a command given by a QBasic statement, we say that the statement is executed. Look at the program in the question (below). There are two PRINT statements. The first PRINT statement is executed first (of course), then the second PRINT statement is executed. Finally the END statement ends the program. Unless directed otherwise, a QBasic program starts with the first statement and then executes the statements in sequential order until an END is reached.
QUESTION 10:
What do you suppose this program writes to the computer monitor?
' Program to demonstrate sequential execution
PRINT "Cross patch, draw the latch,"
PRINT "Sit by the fire and spin."
END
Answer:
Cross patch, draw the latch,
Sit by the fire and spin.
The characters (including punctuation) inside the quote marks are printed. The quote marks are not printed.
Strings and Arithmetic in Print Statements
A PRINT statement can print more than one item. Examine the following program.
' Printing two items
PRINT "The sum of 1 plus 10 is", 1 + 10
END
The PRINT statement has two items to print:
• A string: "The sum of 1 plus 10 is"
• The result of an adding two numbers: 1+10
The two items are separated by a comma ( , ). When the program runs it prints the following to the monitor:
The sum of 1 plus 10 is 11
The string is printed unchanged, character for character. The next item is separated from the first with some spaces, then the result of the arithmetic is printed. It is useful to list two (or more) items in one PRINT statement.
QUESTION 11:
Here is a program that calculates 12 times 12. The program prints a sting and then prints the answer. But is the program correct?
' Compute 12 times 12
PRINT "The square of 12" is 12*12
Answer:
No. The PRINT statement is wrong. The words inside the quotes must include the is. The first item to print must be followed by a comma. It is very easy to overlook such small mistakes.
Here is the correct version of the program:
' Computing 12 times 12
PRINT "The square of 12 is", 12*12
END
Syntax Errors
If you tried to run the incorrect version of the program it would not work. You would see something on your screen like this:

(These notes have not explained how to run programs yet. Just pretend you tried to run the program). The gray box contains an error message that does not make much sense. To get rid of the box, hit the TAB key on your keyboard until the OK in the error message is selected, and then hit ENTER. (Unless you fix the mistake the error message will appear the next time you run the program.)
QBasic did not execute the PRINT statement because it has a Syntax Error. Syntax in programming languages means nearly the same as grammar means in human languages. It means "the rules for creating a correctly formed statement."
A statement without syntax errors is formed correctly. It might not make any sense. This is true with English also. The following is not an English sentence:
be you force may the with
It does not follow English syntax rules and is just a jumble of words. The following sentence has no syntax errors. But it does not make sense:
The distant corners softly remember grape soda.
Answer:
No. The PRINT statement is wrong. The words inside the quotes must include the is. The first item to print must be followed by a comma. It is very easy to overlook such small mistakes.
Here is the correct version of the program:
' Computing 12 times 12
PRINT "The square of 12 is", 12*12
END
Syntax Errors
If you tried to run the incorrect version of the program it would not work. You would see something on your screen like this:

(These notes have not explained how to run programs yet. Just pretend you tried to run the program). The gray box contains an error message that does not make much sense. To get rid of the box, hit the TAB key on your keyboard until the OK in the error message is selected, and then hit ENTER. (Unless you fix the mistake the error message will appear the next time you run the program.)
QBasic did not execute the PRINT statement because it has a Syntax Error. Syntax in programming languages means nearly the same as grammar means in human languages. It means "the rules for creating a correctly formed statement."
A statement without syntax errors is formed correctly. It might not make any sense. This is true with English also. The following is not an English sentence:
be you force may the with
It does not follow English syntax rules and is just a jumble of words. The following sentence has no syntax errors. But it does not make sense:
The distant corners softly remember grape soda.

QUESTION 12:
Is there a syntax error in the following program?
' Computing 12 times 12
PRINT The square of 12 is, 12*12
END

Answer:
Yes. The string in the PRINT statement does not have quotes around it.
Bugs
The program should be:
' Computing 12 times 12
PRINT "The square of 12 is", 12*12
END
If you try to run the incorrect version you get a message window on your computer screen that lists the problem. (Often the message is hard to understand. Some syntax errors confuse the QBasic system so badly it does not know what to do.) Hopefully you can figure out the syntax error, correct it, and run the program.
Programs can have errors other than syntax errors. Just as you can say something in grammatical English that is incorrect, you can write a program in QBasic that has no syntax errors but computes an incorrect result. Such a program has one or more bugs.
QUESTION 13:
Does the following program make sense?
' Computing 12 times 12
PRINT "The square of 12 is", 12 * 0
END
Answer:
No. The PRINT statement
PRINT "The square of 12 is", 12 * 0
is correct in syntax, but it does not calculate what it should. 12 * 0 means to multiply 12 by 0, which results in a zero, which is not what is wanted. This program has a bug.
More Bugs
The buggy program:
' Computing 12 times 12
PRINT "The square of 12 is", 12 * 0
END
. . . has a comment line that says what is wanted, and even has a string in the PRINT statement that said what the result should be. But the arithmetic is wrong, and a wrong number is printed.

QUESTION 14:
Does the following program have a syntax error or a bug?
' Computing 23.8 plus 5.2
PRINT "The sum is", 23.8 * 5.2
Answer:
If the comment is correct, then the program has a bug since in the PRINT statement the two numbers are multiplied, not added.
A Story Problem
Here is the corrected program:
' Computing 23.8 and 5.2
PRINT "The sum is", 23.8 + 5.2
END
Often the numbers in a computer program are the values of things in real life. For example, say that one number is "the number of hours you have worked". The other number is "the number of dollars you are paid per hour". These are very interesting numbers. The two numbers multiplied together give the number of dollars you are paid (before deductions).
QUESTION 15:
Write a QBasic program that calculates how much you are paid if you work 16 hours and your rate of pay is 7.25 dollars per hour.
Answer:
' Calculate gross pay
PRINT "The pay is", 16 * 7.25
END
If you run this program it writes:
The pay is 116
Arithmetic Operators
So far we have seen the QBasic commands for adding two numbers (+) and for multiplying two numbers (*). The + and * are called arithmetic operators. Here is a list of more of them:
Arithmetic Operators
operator meaning example in words
^ power 3^2 3 to the power 2
- negation -23 negative 23
* multiply 1.5 * 8 1.5 times 8
/ divide 12 / 4 12 divided by 4
+ addition 4.2 + 3 4.2 plus 3
- subtraction 9 - 2 9 minus 2
Here is a program that calculates the number of miles per gallon for a car that has burned 10 gallons of gas and gone 245.4 miles:
' Calculate miles per gallon
' 245.4 miles with 10 gallons of gas
'
PRINT "MPG is", 245.4 / 10
END
It is important to get the two numbers in the correct order. The program is correct because it divides the number of miles, 245.4, by the number of gallons, 10. The program prints its output to the monitor:
MPG is 24.54
This program has three comment lines. This is fine; comments are ignored by the computer. You can have many of them. The third comment line has nothing on it except for the apostrophe ( ' ) that makes it a comment. This is fine. You can use a blank line if you want.
QUESTION 16:
Write (on paper, in your head, or on a computer) a program to answer the following problem:
A bird watcher bought 25 pounds of bird food for an outdoor bird feeder. The birds ate all the food in 15 days. How many pounds of bird food per day did the birds eat?
Answer:
' Calculate the number of pounds of food
' birds eat in a day if they eat 25 pounds of food
' in 15 days
'
PRINT "Daily seed use is ", 25 / 15, " pounds per day"
END
Your program probably has different strings in the PRINT statement. The division is correct: 25 pounds divided by the number of days gives pounds per day. The other arrangement 15/25 is incorrect.
Three items in the PRINT statement
The PRINT statement has three items to print. This is OK, and makes the program's output more understandable. Each item is separated by a comma. The three items to print are:
1. A string -- "Daily seed use is "
2. An arithmetic result -- 25 / 15
3. A string -- " pounds per day"
When printed, each item is separated from the previous item by a tab. This is like pushing the tab key on a typewriter or wordprocessor. The comma "," separating items is replaced with several spaces (not always the same number of spaces).
The above program writes the following to the computer monitor screen:
Daily seed use is 1.66666667 pounds per day
QUESTION 17:
The electricity used in a household was 1679 kilowatt hours during 41 winter days. The same household used 752 kilowatt hours during 31 summer days. Write a program which uses two PRINT statements to write out the average kilowatt hours used per day in the winter and the average kilowatt hours used per day in the summer.
Answer:
' Calculate the average KWH per day for winter and summer.
' 1679 KWH used in 41 winter days.
' 752 KWH used in 31 summer days.
'
PRINT "Average WINTER use is ", 1679/41, " KWH per day"
PRINT "Average SUMMER use is ", 752/31, " KWH per day"
END
This program uses sequential execution. The first PRINT statement executes, then the second PRINT statement executes. Then the END statement stops the program. The program prints this to the monitor:
Average WINTER use is 40.95122 KWH/day
Average SUMMER use is 24.25806 KWH/day
Negative Numbers
Look at the table of arithmetic operators. The symbol - (minus) appears twice in the table. This is because it has two meanings:
• The first meaning is "negative number".
• The second meaning is "subtraction".
Arithmetic Operators
operator meaning example in words
^ power 3^2 3 to the power 2
- negation -23 negative 23
* multiply 1.5 * 8 1.5 times 8
/ divide 12 / 4 12 divided by 4
+ addition 4.2 + 3 4.2 plus 3
- subtraction 9 - 2 9 minus 2
These two meanings are the same as in ordinary arithmetic. You may be so familiar with these two meanings that you may have trouble seeing them. For example, look at the following, which might be found in a math book (or in any textbook):
-25 negative 25
-5.2 negative 5.2

18.1 - 2.4 18.1 minus 2.4
12 - 6 12 minus 6
The "-" sign is used for two purposes in the above. QBasic uses it for the same two purposes.
QUESTION 18:
What does the "-" do in the following program?
PRINT "Usual gain in buying a lottery ticket ", -1
END
Answer:
The "-" sign makes a negative number.
Automatic Formatting of Arithmetic
Often, both uses of "-" appear in one calculation. Examine the following:
-25 + 10 negative 25 plus 10 = -15
-5.2 - 3.1 negative 5.2 minus 3.1 = -8.3
18.4 - 2.4 18.4 minus 2.4 = 16.0
-12/6 minus 12 divided by 6 = -2
The QBasic system makes this less confusing by adjusting what you type. QBasic adjusts what you type so that:
• When "-" means "negative number" it is placed right up against the number it is for.
• When "-" means "subtraction" it is separated from the numbers to be subtracted by one space on each side.
For example, if you type:
PRINT - 25
END
QBasic adjusts this to:
PRINT -25
END
(The adjustment is not done until after the cursor has left the line.)
QUESTION 19:
You type the following:
PRINT - 25-4
How will QBasic adjust this line?
Answer:
PRINT -25 - 4
The first minus sign means "negative number" and is moved right up against the 25. The second minus sign means "subtract" and is separated by spaces on either side.
More about Negative Numbers
The above statement subtracts 4 from a negative 25. This results in -29.
QUESTION 20:
What will the following program print on the monitor?
PRINT -16 + 4
END
Answer:
The statement PRINT -16 + 4 causes -12 to be printed on the monitor. The arithmetic -16 + 4 means "add four to negative sixteen." The - sign indicates a negative number.
Exponents
The exponentiation operator is ^ (on the same key as 6). It means "to the power of".
3^2 means three to the power two, = 3 * 3 = 9

4^3 means four to the power three, = 4 * 4 * 4 = 64

2.5^2 means 2.5 to the power two, = 2.5 * 2.5 = 6.25

10^1.2 means ten to the power 1.2, = 15.8489
You may not have seen fractional powers before as in the last example. Don't worry. We won't use them. But if your need it in the future, QBasic can do it.
QUESTION 21:
What (do you suppose) that the following program writes?
' Number of square inches in a square foot
PRINT "Square inches = ", 12 ^ 2
END
Answer:
Square inches = 144
Several Operators in a Row
Sometimes you want more than one arithmetic operator in the same statement. For example, here is a program to calculate the number of fluid ounces in a gallon:
' Number of fluid oz. in a gal.
'
' There are 16 oz. per pint
' There are 2 pints per quart
' There are 4 quarts per gal.
'
PRINT "Fluid ounces = ", 16 * 2 * 4
END
When you see two or more of the same operator, start at the left and do them one at a time:
16 * 2 * 4
32 * 4
128
------
do first
Often it makes no difference in what order you do the arithmetic when all operators are the same. In more complicated floating point arithmetic it sometimes makes a difference.
QUESTION 22:
Write a program that calculates the number of Winter days in a year.
• There are 11 Winter days in December
• There are 31 Winter days in January
• There are 28 Winter days in February (usually)
• There are 19 Winter days in March
Answer:
' Number of Winter Days
'
PRINT "Winter Days = ", 11 + 31 + 28 + 19
END
When all the operators are the same, start at the left and do the arithmetic one operator at a time. Doing this for the above:
11 + 31 + 28 + 19 42 + 28 + 19 70 + 19 89
-------- -------- -------
do first do second do third
End of the Chapter
You have reached the end of this chapter. Only 23 more to go. You may wish to review the following:
• Computer program
• Statement
• END statement
• Comment
• Floating point number
• String
• Sequential execution
• Syntax error
• Bug
• Arithmetic operators
• Two uses of the "-" sign
• Exponentiation "^"
For more exciting Story Problems, and lots more Math, be sure to look for Chapter 2, coming soon to a screen near you.
You have reached the end of the chapter.

Monday, November 10, 2008

Fx trading

Introduction to Trading Forex


Foreign Exchange

This short introduction explains the basics of trading Forex online, a brief explanation of the markets and the major benefits of trading Forex online. There are also two scenarios describing the implications of trading in a bear as well as a bull market to better acquaint you with some of the risks and opportunities of the largest and most liquid market in the world.
As an additional aid for those who are new to Forex, there is also a glossary at the bottom of this text which explains some of the terms used in connection with currency trading.
Overview
Foreign exchange, Forex or just FX are all terms used to describe the trading of the world's many currencies. The Forex market is the largest market in the world, with trades amounting to more than USD 3 trillion every day. Most Forex trading is speculative with only a low percentage of market activity representing governments' and companies' fundamental currency conversion needs.
Unlike trading on the stock market, the Forex market is not conducted by a central exchange, but on the “interbank” market which is thought of as an OTC (over the counter) market. Trading takes place directly between the two counterparts necessary to make a trade, whether over the telephone or on electronic networks all over the world. The main centres for trading are Sydney, Tokyo, London, Frankfurt and New York. This worldwide distribution of trading centres means that the Forex market is a 24-hour market.


Trading Forex
A currency trade is the simultaneous buying of one currency and selling of another one. The currency combination used in the trade is called a cross (for example, the euro/US dollar, or the GB pound/Japanese yen.). The most commonly traded currencies are the so-called “majors” – EURUSD, USDJPY, USDCHF and GBPUSD.
The most important Forex market is the spot market as it has the largest volume. The market is called the spot market because trades are settled immediately, or “on the spot”. In practice this means two banking days.


Forward Outrights
For forward outrights, settlement on the value date selected in the trade means that even though the trade itself is carried out immediately, there is a small interest rate calculation left. The interest rate differential doesn't usually affect trade considerations unless you plan on holding a position with a large differential for a long period of time. The interest rate differential varies according to the cross you are trading. On the USDCHF, for example, the interest rate differential is quite small, whereas the differential on NOKJPY is large. This is because if you trade e.g. NOKJPY, you get almost 7% (annual) interest in Norway and close to 0% in Japan. So, if you borrow money in Japan, to finance the trade and buying NOK, you have a positive interest rate differential. This differential has to be calculated and added to your account. You can have both a positive and a negative interest rate differential, so it may work for or against you when you make a trade.



Trading on Margin
Trading on margin means that you can buy and sell assets that represent more value than the capital in your account. Forex trading is usually conducted with relatively small margin deposits. This is useful since it permits investors to exploit currency exchange rate fluctuations which tend to be very small. A margin of 1.0% means you can trade up to USD 1,000,000 even though you only have USD 10,000 in your account. A margin of 1% corresponds to a 100:1 leverage (or “gearing”). (Because USD 10,000 is 1% of USD 1,000,000.) Using this much leverage enables you to make profits very quickly, but there is also a greater risk of incurring large losses and even being completely wiped out. Therefore, it is inadvisable to maximise your leveraging as the risks can be very high. For more information on the trading conditions of Saxo Bank, go to the Account Summary on your SaxoTrader and open the section entitled “Trading Conditions” found in the top right-hand corner of the Account Summary.

Why Trade Forex?
24 hour trading
One of the major advantages of trading Forex is the opportunity to trade 24 hours a day from Sunday evening (20:00 GMT) to Friday evening (22:00 GMT). This gives you a unique opportunity to react instantly to breaking news that is affecting the markets.
Superior liquidity
The Forex market is so liquid that there are always buyers and sellers to trade with. The liquidity of this market, especially that of the major currencies, helps ensure price stability and narrow spreads. The liquidity comes mainly from banks that provide liquidity to investors, companies, institutions and other currency market players.
No commissions
The fact that Forex is often traded without commissions makes it very attractive as an investment opportunity for investors who want to deal on a frequent basis.
Trading the “majors” is also cheaper than trading other cross because of the high level of liquidity. For more information on the trading conditions of Saxo Bank, go to the Account Summary on your SaxoTrader and open the section entitled “Trading Conditions” found in the top right-hand corner of the Account Summary.
100:1 Leverage
Leverage (gearing) enables you to hold a position worth up to 100 times more than your margin deposit. For example, a USD 10,000 deposit can command positions of up to USD 1,000,000 through leverage. You can leverage the first USD 25,000 of your investment up to 100 times and additional collateral up to 50 times.
Profit potential in falling markets
Since the market is constantly moving, there are always trading opportunities, whether a currency is strengthening or weakening in relation to another currency. When you trade currencies, they literally work against each other. If the EURUSD declines, for example, it is because the US dollar gets stronger against the euro and vice versa. So, if you think the EURUSD will decline (that is, that the euro will weaken versus the dollar), you would sell EUR now and then later you buy euro back at a lower price. In case that the EURUSD indeed declines, then you can take your profit. The opposite trading scenario would occur if the EURUSD appreciates.

Important Forex Trading Terms
Spread
The spread is the difference between the price that you can sell currency at (Bid) and the price you can buy currency at (Ask). The spread on majors is usually 3 pips under normal market conditions. For more information on the trading conditions at Saxo Bank, go to the Account Summary on your Client Station and open the section entitled “Trading Conditions” found in the top right-hand corner of the Account Summary.
Pips
A pip is the smallest unit by which a cross price quote changes. When trading Forex you will often hear that there is a 3-pip spread when you trade the majors. This spread is revealed when you compare the bid and the ask price, for example EURUSD
is quoted at a bid price of 0.9875 and an ask price of 0.9878. The difference is USD 0.0003, which is equal to 3 “pips”.

On a contract or position, the value of a pip can easily be calculated. You know that the EURUSD is quoted with four decimals, so all you have to do is cancel out the four zeros on the amount you trade and you will have the value of one pip. Thus, on a EURUSD 100,000 contract, one pip is USD 10. On a USDJPY 100,000 contract, one pip is equal to 1000 yen, because USDJPY is quoted with only two decimals.

Trading Scenario – Trading Rising Prices
If you believe that the euro will strengthen against the dollar you'll want to buy euro now and sell it back later at a higher price.


• You buy euro We quote EURUSD at Bid 0.9875 and Ask 0.9878, which means that you can sell 1 euro for 0.9875 USD or buy 1 euro for 0.9878 USD.

In this example you buy euro 100,000, at the quote price of 0.9878 (ask price) per euro.

• The market moves in your favor Later the market turns in favour of the euro and the EURUSD is now quoted at Bid 0.9894 and Ask 0.9896.

• Now you sell your euro and get the profit You sell euro at a Bid price of 0.9894.

• The profit is calculated as follows Sell price-buy price x size of trade
(0.9894 minus 0.9878) multiplied by 100.000 = USD 140 Profit
(Note that the profit or loss is always expressed in the secondary current



Trading Scenario – Trading Falling Prices
If, on the other hand, you believe that the euro will weaken against the dollar, you'll want to sell EURUSD.


• You sell euro We quote EURUSD at a Bid price of 0.9875 and Ask price of 0.9880 and you decide to sell euro 100,000 at a Bid price of 0.9875.

• The market moves in your favour The euro weakens against the dollar and the EURUSD is now quoted at bid 0.9744 and ask 0.9749.

• Now you buy back your euro You buy EUR at an ask price of 0.9749.


• Your profit/loss is then Sell price-buy price x size of trade
(0.9875 minus 0.9749) multiplied by 100.000 = USD 1260 Profit
Remember that trading EUR 100,000 as we have done in our examples, does not mean that you have to put up euro 100,000 yourself. On a 2% margin means that you have to deposit 2.0% of euro 100,000, which is euro 2,000 on margin as a guarantee for the future performance of your position.



Further Reading
To see how you can trade the Forex market and benefit from our toolbox of information and live quotes, please proceed to the Forex Quick Start found under the Trading menu of SaxoTrader.



Glossary

• Appreciation
An increase in the value of a currency.

• Ask
The price requested by the trader. This usually indicates the lowest price a seller will accept.

• Base currency
The currency that the investor buys or sells (i.e. EUR in EURUSD).

• Bear
Someone who believes prices are heading down. A bear market is one in which there has been a sustained fall in prices and which does not look like it will recover quickly.

• Bid
The price offered by the trader. This usually indicates the highest price a purchaser will pay.

• Bid/Ask
The Bid rate is the rate at which you can sell. The Ask (or offer) rate is the rate at which you can buy.

• Bull
Someone who is optimistic about the market. A bull market is characterised by enthusiastic and sustained buying.

• cross
When trading with currencies, the investor buys one currency with another. These two currencies form the cross: for example, EURUSD.

• Cross rate
An exchange rate that is calculated from two other exchange rates.

• Depreciation/decline
A fall in the value of a currency.

• Exchange rate
What one currency is worth in terms of another, for example the Australian dollar might be worth 58 US cents or 70 yen.

Currencies traded freely on foreign-exchange markets have a spot rate (applying to trades settled “spot”, i.e., two working days hence) and a forward rate. Countries can determine their exchange rates in a variety of ways.
1. A floating exchange rate system where the currency finds its own level in the market.
2. A crawling or flexible peg system which is a combination of an officially fixed rate and frequent small adjustments which in theory work against a build-up of speculation about a revaluation or devaluation.
3. A fixed exchange-rate system where the value of the currency is set by the government and/or the central bank.

• EURUSD
Means that you trade EUR against dollars. If you buy euro you pay in dollars and if you sell euro you receive dollars.

• FX, Forex, Foreign Exchange
All names for the transaction of one currency for another, e.g. you buy GBP 100.00 with USD 150.25 or sell USD 150.25 for GBP 100.00.

• Interbank
Short-term (often overnight) borrowing and lending between banks, as distinct from a banks business with their corporate clients or other financial institutions.

• Interest rate differential
The yield spread between two otherwise comparable debt instruments denominated in different currencies.

• Leverage (gearing)
The investor only funds part of the amount traded.

• Long
To buy.

• Long position
A position that increases its value if market prices increase.

• Liquid (-ity)
The capacity to be converted easily and with minimum loss into cash. A liquid market is one in which there is enough activity to satisfy both buyers and sellers. Ultra-short-dated treasury notes are an example of a liquid investment.

• Margin
The deposit required when entering into a position as well as to hold an open position. Your margin status can be monitored in the Account Summary.

• NYSE
The New York Stock Exchange.

• Open position
A position in a currency that has not yet been offset. For example, if you have bought 100,000 USDJPY, you have an open position in USDJPY until you offset it by selling 100,000 USDJPY, thus “closing” the position.

• Over the counter
When trading takes place directly between two parties, rather than on an exchange. Over the counter trades can be customised whereas exchange-traded products are often standardised.

• Pips
A pip is the smallest unit by which a Forex cross price quote changes. So if EURUSD bid is now quoted at 0.9767 and it moves up 2 pips, it will be quoted at 0.9769.

• Position
Traders talk of “taking a position” which simply means buying or selling currency cross. “Position” can also refer to a trader's cash/securities/currencies balance, whether he or she is short of cash, has money to lend, is overbought or oversold in a currency, etc.

• Risk
Trying to control outcomes to a known or predictable range of gains or losses. Risk management involves several steps which begin with a sound understanding of one's business and the exposures or risks that have to be covered to protect the value of that business. Then an assessment should be made of the types of variables that can affect the business and how best to protect against unwelcome outcomes. Consideration must also be given to the preferred risk profile – whether one is risk – averse or fairly aggressive in approach. This also involves deciding which instruments to use to manage risk and whether a natural hedge exists that can be used. Once undertaken, a risk-management strategy should be continually assessed for effectiveness and cost.

• Secondary currency (variable currency or counter currency)
The currency that the investor trades the base currency against (i.e. USD in EURUSD).

• Short position
A position that benefits from a decline in market prices.

• Short
To sell.

• Speculative
Buying and selling in the hope of making a profit, rather than doing so for some fundamental business-related need.

• Spot
A Spot rate is the current market price of an asset.

• Spot market
The part of the market calling for spot settlement of transactions. The precise meaning of “spot” will depend on local custom for a commodity, security or currency. In the UK, US and Australian foreign-exchange markets, “spot” means delivery two working days hence.

• Spread
The difference between the bid and the ask rate.

Introduction to QuickBasic

Introduction to QuickBasic

Microsoft QuickBasic is a modern form of BASIC which is easy to learn. Learning QuickBasic will help you to learn Visual Basic and other programming languages.
A simplified version is QBasic. These notes give enough of QBasic for simple mathematical applications. Use the Help menu on the computer to learn more, or look at the following books:
Halvorson, M., and Rygmyr, D., 1989, Learn Basic Now, Microsoft Press. [KMUTT Mathematics Library number: COM H24]
Waite, M., Arnson, R., Gemmell, C., and Henderson, H., 1990, Microsoft Quickbasic Bible, Microsoft Press. [KMUTT Mathematics Library number: COM W7]
Contents
1. Example of a QBasic Program
REM Distance from the Origin
PRINT "Enter X and Y"
INPUT X, Y
LET Dist = SQR(X * X + Y * Y)
PRINT Dist
END
2. Lines and Keywords
A program consists of lines of text. The order of the lines in the program is the order in which the lines are read by the computer.
The lines in the program contain statements which tell the computer what to do. Each statement begins with a keyword. In the example above the keywords are
REM, PRINT, INPUT, LET, END.
The keyword REM means "remark". It states that what follows on the same line will be ignored by the computer. Remarks are useful for writing titles and subheadings in a program.
3. Constants
Numerical constants are written in the usual way, with or without a decimal point, and with or without a minus sign:
7, -54, 3.14159, -0.0065.
Numerical constants may also be written with a scale factor, which is a power of 10. The scale factor is the letter E followed by a positive or negative integer, for example:
2.75E4 means 27500, 2.75E-3 means 0.00275.
Symbolic constants are constants with a name defined by the keyword CONST, as in the following example:
CONST HalfPi = 1.570796
String constants are enclosed in quote marks. They may be used for printing messages during the running of a program. The string constant in the above example is:
"Enter X and Y".
4. Variables
A variable is the name of a location in the computer memory where a number or a string is stored. In the example above X, Y, and Dist are numerical variables.
A numerical variable consists of one or more letters, and may also contain digits. Two types of numerical variable are commonly used: integers (no decimal point), and single-precision numbers (with a decimal point and up to seven significant digits).
If the last character in the variable name is %, then the number stored is an integer. If the last character in the variable name is !, then the number stored is a single-precision number. For example,
n% is an integer variable
x! is a single-precision variable.
You may declare numerical variable types without % or ! by using the keywords DIM, AS, and INTEGER or SINGLE as follows:
DIM VariableName AS INTEGER
DIM VariableName AS SINGLE
A string variable is the name of a location in the computer memory where a string is stored. You may declare a variable to be a string by ending its name with the character $. For example, A$ is a string variable. You may also declare a string variable as follows:
DIM VariableName AS STRING

5. Arrays
Variables may be used as one-dimensional arrays (vectors), or as two-dimensional arrays (matrices). The keyword DIM is used to declare the number of subscripts and their maximum values. For example, the line
DIM X(11) AS SINGLE, A(3,4) AS SINGLE
declares X(11) to be a one-dimensional array of single precision numbers with values of the subscript from 0 to 11; the variable A(3,4) is a two-dimensional array of single precision numbers with values of the first subscript from 0 to 3 and values of the second subscript from 0 to 4.

6. Mathematical Expressions
Mathematical expressions are written in the usual way with the symbols +, -, *, / for addition, subtraction, multiplication, and division. Multiplications and divisions are calculated before additions and subtractions, unless the order is changed by brackets. For example, if A = 1, B = 2, and C = 3, then A + B*C is 7, and (A + B)*C is 9.
Powers are represented by the symbol ^, so A^B means A to the power B. Powers are calculated before the other mathematical operations, unless the order is changed by brackets.

7. Assignment Statements
Assignment statements contain the keyword LET, a numerical variable, the symbol =, and a mathematical expression. For example, the line
LET X = A + 2.54
tells the computer to calculate A + 2.54 and store the result in the location named X. The keyword LET is optional: it may be omitted.

8. Input and Output
The keyword INPUT causes the computer to stop and wait for data to be entered with the keyboard. The data to be entered may consist of numerical constants separated by commas. For example, the line
INPUT A, B, C
accepts three numbers and stores them in locations named A, B, and C.
The keyword PRINT causes the computer to show output on the screen. The keyword PRINT may be followed by a list containing strings and numerical variables. The items in the list may be separated by commas or semicolons. If commas are used the items are printed with large spaces between them. If semicolons are used, the items are printed without spaces. For example, if X = 4.5, and Y = -4.5, the two lines
PRINT X,Y
PRINT "The first number is ";X
cause the following two lines to appear on the screen:
4.5 -4.5
The first number is 4.5

9. Built-in Functions
The following functions may be used in mathematical expressions:
ABS(X)
Absolute value of X.
SGN(X)
-1 when X<0, x="0,">0.
SQR(X)
Square root of X.
EXP(X)
Exponential X.
LOG(X)
Natural logarithm of X.
SIN(X)
Sine of X (X in radians).
COS(X)
Cosine of X (X in radians).
TAN(X)
Tangent of X (X in radians).
ATN(X)
Arctangent of X (result in radians).
The function RND is a random number in the interval [0,1). If RND is used alone, the same sequence of numbers is generated each time the program is run. This is because the numbers are "pseudo-random" numbers generated by an algorithm. You can get a different sequence each time by putting the line
RANDOMIZE TIMER
at the beginning of your program.
Floating point numbers are reduced to integers by the following functions:
INT(X!)
The largest integer less than or equal to X!
FIX(X!)
The integer part of X!
CINT(X!)
The nearest integer to X!
Examples:
INT(2.8) is 2, FIX(2.8) is 2, CINT(2.8) is 3
INT(2.1) is 2, FIX(2.1) is 2, CINT(2.1) is 2
INT(-2.1) is -3, FIX(-2.1) is -2, CINT(-2.1) is -2
10. Repetitions
A block of statements can be repeated a definite number of times using the keywords FOR, NEXT, and STEP, as in the following example:
FOR n% = 0 TO 12 STEP 3
Sum = V(n%) + V(n% + 1) + V(n% + 2)
PRINT Sum
NEXT n%
Here the variable n% takes the values 0, 3, 6, 9, and 12. If STEP 3 is omitted, then the step size is 1 and n% takes the values 0, 1, 2, ..., 11, 12. An integer variable should be used for counting the repetitions.
The keywords EXIT FOR can be used to exit before all the repetitions have been completed.
11. Conditional loops
Conditional loops can be written using the keywords DO, WHILE, and LOOP. The following form should be used:
DO WHILE condition
statements
LOOP
Here the statements are repeated while the condition is true. When the condition is false the computer jumps to the statements after LOOP. If the condition is false at the start, then the statements are not executed.
The keywords EXIT DO can be used to exit a loop before the condition has been satisfied.
The conditions can take the following forms:
X < x =" Y">= Y
X greater than or equal to Y.
X > Y
X greater than Y.
X <> Y
X not equal to Y.
Composite conditions can be written using the logical operators AND, OR, and NOT.

12. Conditional Statements
The keywords IF and THEN are used to make conditional statements as in the following example:
IF X = 0 THEN PRINT "Zero"
This causes the computer to print "Zero" when X is zero, and to jump to the next line when X is not zero. The keyword ELSE and another statement may be added to the line. For example, the line
IF X = 0 THEN PRINT "Zero" ELSE PRINT "Not zero"
causes the computer to print "Zero" when X is zero, and to print "Not zero" when X is not zero.
Blocks of conditional statements can be written with the keywords IF, THEN, ELSEIF, ELSE, and END IF as in the following example:
IF X < x =" 0">
13. The Select Case Structure
A structure using the keywords SELECT CASE sometimes makes a block of conditional statements easier to understand than an IF block. Here is an example:
SELECT CASE Month
CASE 11, 12, 1, 2
PRINT "Cool season"
CASE 3 TO 5
PRINT "Hot season"
CASE 6 TO 10
PRINT "Wet season"
END SELECT
If Month = 11, 12, 1, or 2 (November, December, January, or February), then the words "Cool season" appear on the screen. If Month = 3, 4, or 5 (March, April, or May), then the words "Hot season" appear on the screen. If Month is any number from 6 to 10 (June to October), then the words "Wet season" appear on the screen.
14. Miscellaneous Keywords
BEEP
causes the computer to make a sound to attract the attention of the user.
STOP
causes the computer to stop running the program. (Follow the instructions on the screen to continue running.)
END
marks the end of the program.
15. Procedures
A QBasic program consists of module-level code and a number of procedures. The module-level code is the main program controlling the computer. Procedures are separate blocks of statements used by the module-level code; they can be called by the module-level code any number of times.
Procedures divide the program into easily-managed parts. They are of two kinds: SUB procedures and FUNCTION procedures.
16. SUB Procedures
A SUB procedure is used by the programmer to define a new statement keyword. A SUB procedure is written as follows:
SUB Name (parameters)
statements
END SUB
The first line shows the name of the procedure and the parameters used in the procedure. When there are no parameters the brackets after the name of the procedure are left empty.
When there is a SUB procedure in your program you must put a statement in the form
DECLARE SUB Name (parameters)
at the beginning of your module-level code. Then you can use the name of the procedure as a statement keyword anywhere in your program.
When the SUB procedure works with variables in the module-level code you must add the keyword SHARED in the DIM statement that declares the variables in the module-level code.
Here is an example of a program with a SUB procedure.
DIM SHARED X AS SINGLE, Y AS SINGLE, Z AS SINGLE
DECLARE SUB NormalizeVector ()
PRINT "Enter vector"
INPUT X, Y, Z
NormalizeVector
PRINT "The normalized vector is "; X, Y, Z
END

SUB NormalizeVector
LET N! = SQR(X * X + Y * Y + Z * Z)
X = X/N!
Y = Y/N!
Z = Z/N!
END SUB
Here the SUB procedure named NormalizeVector takes the vector (X,Y,Z) from the module-level code and replaces it by the corresponding normalized vector.

17. FUNCTION Procedures
A FUNCTION procedure is used by the programmer to define a new function. It is written as follows:
FUNCTION Name (parameters)
statements
Name = expression
END FUNCTION
The first line shows the name of the function and the parameters used to calculate its value. The data type of the value of the function should be shown by a type suffix (%, !, or $) in the name. The statements below the first line give the procedure for calculating the value of the function; they must include a line assigning the calculated value to the function name.
The procedure for calculating the value of the function should not contain statements that change the values of the parameters. This is so that variables substituted for the parameters will not be changed when the function is used.
When there is a FUNCTION procedure in your program you must put a statement in the form
DECLARE FUNCTION Name (parameters)
at the beginning of your module-level code. Then you can use the function anywhere in the program.
Here is an example of a program with a FUNCTION procedure:
DIM A AS SINGLE, B AS SINGLE, C AS SINGLE
DECLARE FUNCTION Norm! (x!, y!, z!)
INPUT A, B, C
PRINT Norm!(A, B, C)
END

FUNCTION Norm! (x!, y! z!)
Norm! = SQR(x! * x! + y! * y! + z! * z!)
END FUNCTION
The output from this program is the norm of the vector you give as input when the program is run.
18. Module-Level and Local Symbolic Constants
A symbolic constant declared with the keyword CONST in the module-level code has the same value in every procedure.
A symbolic constant declared with the keyword CONST inside a procedure is local to that procedure: the same name outside the procedure does not refer to the local constant inside the procedure.
19. Module-Level and Local Variables
Variables declared in the module-level code with the keywords DIM and SHARED as follows
DIM SHARED N AS INTEGER, X AS SINGLE, A AS STRING
DIM SHARED A(3, 4) AS SINGLE, B(3) AS SINGLE
are called module-level variables. Every procedure can refer to these variables and change their values.
A variable that is used in a procedure, but is not declared with the keyword SHARED in the module-level code, is a local variable in that procedure. If the same name is used as a variable outside the procedure, the value of the local variable is not changed.
In these notes local variables and procedure parameters are written with the type characters %, !, and $. Module-level variables are declared without type characters using the keywords AS INTEGER, AS SINGLE, and AS STRING.
20. Sequential Data Files
A sequential data file is a list of numbers or strings stored on a disk. To use a data file you must first open it using the keyword OPEN as follows:
OPEN FileName FOR Mode AS #Number
FileName is the name of the file.
Mode is one of the following:
OUTPUT
for sending new data to the file (existing data are lost),
INPUT
for getting data from the file,
APPEND
for adding data to the file (existing data remain in the file).
#Number is #1, #2, etc, to identify the file in the program.
WRITE #1 is used to send numerical or string data to file #1.
INPUT #1 is used to get data from file #1.
EOF, which means "End Of File", is used to test whether or not all the data have been read from a file. EOF is true when the end of the file has been reached; otherwise EOF is false.
After you have used a file you must close it. CLOSE #1 closes file #1. The keyword CLOSE used alone closes all files.
21. Graphics
The graphics you can do depends on the monitor and the graphics adapter card you have in your system. The keyword SCREEN is used to set the resolution and the number of colors in the display.
PSET is used to plot points, and PRESET is used to erase points. LINE may be used for plotting straight lines and rectangular boxes. CIRCLE may be used for plotting circles and ellipses.
VIEW and VIEW PRINT are used to set areas of the display for graphics and text output.
WINDOW may be used to set the coordinates used for plotting points.
EXAMPLES OF PROGRAMS
Example 1:
REM Arithmetic Sequences
PRINT "Enter first term"
INPUT A
PRINT "Enter common difference"
INPUT D
PRINT "Enter number of terms"
INPUT N
PRINT "The sequence is"
T = A
S = 0
FOR i% = 1 TO N
PRINT T
S = S + T
T = T + D
NEXT i%
PRINT "The sum is "; S
Example 2:
REM Hyperbolic Functions
DECLARE FUNCTION Sinh! (X!)
DECLARE FUNCTION Cosh! (X!)
PRINT "Enter T"
INPUT T
PRINT Sinh!(T), Cosh!(T)
END

FUNCTION Cosh! (X!)
Cosh! = .5 * (EXP(X!) + EXP(-X!))
END FUNCTION

FUNCTION Sinh! (X!)
Sinh! = .5 * (EXP(X!) - EXP(-X!))
END FUNCTION
Example 3:
REM Arctan in Degrees
DECLARE SUB ComputeArctan (X!, Y!)
DIM SHARED Theta AS SINGLE
PRINT "Enter X and Y"
INPUT X, Y
ComputeArctan X, Y
PRINT Theta
END

SUB ComputeArctan (X!, Y!)
IF X!=0 THEN
Theta = 90*SGN(Y!)
ELSEIF X!>0 THEN
Theta = 57.29577*ATN(Y!/X!)
ELSEIF Y!=0 THEN
Theta = 180
ELSE
Theta = 180*SGN(Y!) + 57.29577*ATN(Y!/X!)
END IF
END SUB
Example 4:
REM Transformation of Vectors
DIM SHARED x AS SINGLE, y AS SINGLE
DECLARE SUB TransformVector (a11!, a12!, a21!, a22!)
PRINT "Enter vector x,y"
INPUT x, y
PRINT "Enter a11, a12, a21, a22"
INPUT a!, b!, c!, d!
TransformVector a!, b!, c!, d!
PRINT "The transformed vector is "; x, y
END

SUB TransformVector (a11!, a12!, a21!, a22!)
LET u! = a11! * x + a12! * y
LET v! = a21! * x + a22! * y
x = u!
y = v!
END SUB
By Ralph Engineer programmer

Saturday, November 1, 2008

agriculture

“If you look at the adoption of biotech crops, there’s been a fairly substantial upward curve in the area planted,” says Graham Brookes, an agricultural economist and director of . “The primary reason for that is very simple. It’s because the economic benefits that farmers get from the technology are so significant that once they’ve tried the technology, they will use it again. They will tell their friends, their peers, and more farmers will use the technology.”
Brookes recently completed a review of the, specifically in respect to greenhouse gas emissions and pesticide applications. “We were surprised at the magnitude of the benefits both economic and environmental — especially the environmental benefits,” says Brookes.