Monday, November 7, 2011

Image Editing Printing

Selecting part of a large pic in MS Paint

1) zoom out 50% or 25% (as required)
2) Select required area
3) Cut
4) Zoom in back to 100%
5) Paste. You are done.

Printing a large doc (pic) in A4 paper
1) Open the large pic in Adobe Photoshop
2) Click on 'Image' menu -> Image Size. Change the Pixel settings to 1280 * 800
3) Save it
4) Open Word (Insert -> Pic -> aaaa.jpg). Always use this procedure rather than copy-pasting
through clip-board to avoid large size document
5) To print a full page change the margin setting to 0,0,0,0 first and then check if there is any space
on top,right,bottom,left and again change the margin accordingly
6) Remember to change the margin settings for that particular page only Insert 'Next Page' Section break before and after that page. (V.Imp) otherwise all pages get the same margin settings.

Silverlight RIA services (without using entity framework) - The most basic example

1) Create a Silverlight (and its host ASP.NET Web App.) Project. While creating the same check on “Enable RIA Services”
2) Add a model Employee.cs in Web Project. Mark [KeyAttribute] to EmployeeId Property. This is necessary as all Entities in DomainServies should have this attribute.

3) Add a DomainService class to the Web Project and and make a method GetEmployees() returning IQueryable<Employee>. You can hard-code an IList and return list.AsQueryable<Employee>().

4) When you build the entire solution, do a “Show All Files” in Silverlight project. You will get an folder Generated_Code which has a class containing the DomainContext (with public methods converted to queries) and entities (generated from models).

5) Add the namespace for RiaControls and web Project using the following.
6) Add the RiaDataSource using the following.

<riaControls:DomainDataSource AutoLoad="True"                                                                           
                <my:EmployeeDomainContext />

OR (Pick it from Static Resources)

<riaControls:DomainDataSource AutoLoad="True"                                                                           
                                      QueryName="GetEmployeesQuery" DomainContext="{StaticResource myContext}">

For picking it from Static Resources, you have first define it in Static Resource

        <my:EmployeeDomainContext x:Key="myContext"/>

7) Add a Listbox and bind to RiaDataSource using the following.
<ListBox x:Name="listEmployee" ItemsSource="{Binding ElementName=employeeDomainDataSource,Path=Data}" Width="200" Height="100">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding EmployeeId}" Margin="5,0,0,0"/>
                        <TextBlock Text="{Binding EmployeeName}" Margin="5,0,0,0"/>

Option for beginners

An option is a contract that gives the buyer the right, but not the obligation, to buy or sell an underlying asset at a specific price (called the strike price) on or before a certain date. An option, just like a stock or bond, is a security. It is also a binding contract with strictly defined terms and properties.

The idea behind an option is present in many everyday situations. Say, for example, that you discover a house that you'd love to purchase. Unfortunately, you won't have the cash to buy it for another three months. You talk to the owner and negotiate a deal that gives you an option to buy the house in three months for a price of $200,000. The owner agrees, but for this option, you pay a price of $3,000.

Now, consider two theoretical situations that might arise:

1. It's discovered that the house is actually the true birthplace of Elvis! As a result, the market value of the house skyrockets to $1 million. Because the owner sold you the option, he is obligated to sell you the house for $200,000. In the end, you stand to make a profit of $797,000 ($1 million - $200,000 - $3,000).

2. While touring the house, you discover not only that the walls are chock-full of asbestos, but also that the ghost of Henry VII haunts the master bedroom; furthermore, a family of super-intelligent rats have built a fortress in the basement. Though you originally thought you had found the house of your dreams, you now consider it worthless. On the upside, because you bought an option, you are under no obligation to go through with the sale. Of course, you still lose the $3,000 price of the option.

This example demonstrates two very important points. First, when you buy an option, you have a right but not an obligation to do something. You can always let the expiration date go by, at which point the option becomes worthless. If this happens, you lose 100% of your investment, which is the money you used to pay for the option. Second, an option is merely a contract that deals with an underlying asset. For this reason, options are called derivatives, which means an option derives its value from something else. In our example, the house is the underlying asset. Most of the time, the underlying asset is a
stock or an index.

Calls and Puts
The two types of options are calls and puts:

call gives the holder the right to buy an asset at a certain price within a specific period of time. Calls are similar to having a long position on a stock. Buyers of calls hope that the stock will increase substantially before the option expires.
Definition of Long (or Long Position) :  The buying of a security such as a stock, commodity or currency, with the expectation that the asset will rise in value.

A put gives the holder the right to sell an asset at a certain price within a specific period of time. Puts are very similar to having a short position on a stock. Buyers of puts hope that the price of the stock will fall before the option expires.

Definition of Short (or Short Position) :  The sale of a borrowed security, commodity or currency with the expectation that the asset will fall in value.
Participants in the Options Market
There are four types of participants in options markets depending on the position they take:

1. Buyers of calls
2. Sellers of calls
3. Buyers of puts
4. Sellers of puts

People who buy options are called holders and those who sell options are called
writers; furthermore, buyers are said to have long positions(bullish) , and sellers are said to have short positions (bearish).

Here is the important distinction between buyers and sellers:
-Call holders and put holders (buyers) are not obligated to buy or sell. They have the choice to exercise their rights if they choose.
writers and put writers (sellers), however, are obligated to buy or sell. This means that a seller may be required to make good on a promise to buy or sell.
Why do People buy Options
1) Speculation
You can think of
speculation as betting on the movement of a security. The advantage of options is that you aren't limited to making a profit only when the market goes up. Because of the versatility of options, you can also make money when the market goes down or even sideways.

2) Hedging
The other function of options is
hedging. Think of this as an insurance policy. Just as you insure your house or car, options can be used to insure your investments against a downturn Imagine that you wanted to take advantage of technology stocks and their upside, but say you also wanted to limit any losses. By using options, you would be able to restrict your downside while enjoying the full upside in a cost-effective way

3) A Word on Stock Options
employee stock options aren't available to everyone, this type of option could, in a way, be classified as a third reason for using options. Many companies use stock options as a way to attract and to keep talented employees, especially management. They are similar to regular stock options in that the holder has the right but not the obligation to purchase company stock. The contract, however, is between the holder and the company, whereas a normal option is a contract between two parties that are completely unrelated to the company.

How Options Work
Let's say that on May 1, the stock price of Cory's Tequila Co. is $67 and the premium (cost) is $3.15 for a July 70 Call, which indicates that the expiration is the third Friday of July and the strike price is $70. The total price of the contract is $3.15 x 100 = $315. In reality, you'd also have to take commissions into account, but we'll ignore them for this example.

Remember, a stock option contract is the option to buy 100 shares; that's why you must multiply the contract by 100 to get the total price. The strike price of $70 means that the stock price must rise above $70 before the call option is worth anything; furthermore, because the contract is $3.15 per share, the
break-even price would be $73.15.

When the stock price is $67, it's less than the $70 strike price, so the option is worthless. But don't forget that you've paid $315 for the option, so you are currently down by this amount.

Three weeks later the stock price is $78. The options contract has increased along with the stock price and is now worth $8.25 x 100 = $825. Subtract what you paid for the contract, and your profit is ($8.25 - $3.15) x 100 = $510. You almost doubled our money in just three weeks! You could sell your options, which is called "
closing your position," and take your profits - unless, of course, you think the stock price will continue to rise. For the sake of this example, let's say we let it ride.

By the expiration date, the price drops to $62. Because this is less than our $70 strike price and there is no time left, the option contract is worthless. We are now down to the original investment of $315.

To recap, here is what happened to our option investment:

May 1
May 21
Expiry Date
Stock Price
Option Price
Contract Value
Paper Gain/Loss

The price swing for the length of this contract from high to low was $825, which would have given us over double our original investment. This is leverage in action.

Exercising Versus Trading-Out
So far we've talked about options as the right to buy or sell (exercise) the underlying. This is true, but in reality, a majority of options are not actually exercised.

In our example, you could make money by exercising at $70 and then selling the stock back in the market at $78 for a profit of $8 a share. You could also keep the stock, knowing you were able to buy it at a discount to the present value.

However, the majority of the time holders choose to take their profits by trading out (closing out) their position. This means that holders sell their options in the market, and writers buy their positions back to close. According to the CBOE, about 10% of options are exercised, 60% are traded out, and 30% expire worthless.

When does one sell a put option, and when does one sell a call option?

Selling a put option - An investor would choose to sell a put option if her outlook on the underlying security was that it was going to rise. The purchaser of a put option pays a premium to the writer (seller) for the right to sell the shares at an agreed upon price in the event that the price heads lower. Since the premium would be kept by the seller if the price closed above the agreed upon strike price, it is easy to see why an investor would choose to use this type of strategy.

Selling a 
call option without owning the underlying asset - An investor would choose to sell a call option if his outlook on a specific asset was that it was going to fall. The purchaser of a call option pays a premium to the writer for the right to buy the underlying at an agreed upon price in the event that the price of the asset is above the strike price. In this case, the option seller would get to keep the premium if the price closed below the strike price.

Naked Call Writing
In options terminology, "naked" refers to strategies in which the underlying stock is not owned and options are written against this phantom stock position. The naked strategy is a more aggressive, having a lot more risk, but it can be used to generate income as part of a diversified portfolio. If not used properly, however, a naked call position can have disastrous consequences since a stock can theoretically rise to infinity.
Naked call writing is the technique of selling a call option without owning any stock. Being long a call means that you have bought the right to buy shares at a fixed price. On the other side of the transaction, the person who sold the call is said to be "short" the call, and his or her position can either be secured by shares (the covered call scenario) or unsecured (naked calls). This might be confusing, so here's a diagram that summarizes it for you:
When selling a naked call, you would instruct your broker to "sell to open" a call position. Remember that since you do not have a position in the stock, you will be forced to buy shares at the market price and sell them at the strike price if your calls turn out to be in-the-money.
(Definition of in-the-money: For call options, the option is said to be in-the-money if the share price is above the strike price. A put option is in-the-money when the share price is below the strike price.) 
Now, let us consider the risks and payoffs in more detail.
The Risks and Rewards
A naked call position is much more risky than writing a simple covered call because you have essentially sold the right to something that you do not own. The closest parallel to such a transaction in the equity world is
shorting a stock, in which case you do not own the stock you are selling. In the case of writing naked calls, you have sold someone the right to buy shares at a fixed price; you aim to make a profit by collecting the premium.

Let us consider the following example: ABC's stock trades for $100 and the $105 call that is one month to expiry trades at $2. You, not owning any ABC stock, can sell (write) a naked call at $2 and collect $200. By doing so, you are speculating that ABC stock will be below $107 ($105 + $2 premium) at expiry (if it is below $107, you will make a profit). Consider the payoff diagram:

As you can see, the losses mount as the price of the stock goes above the breakeven price of $107. Note also that at any price below $105, the profit for the seller of the option stays only at $200, which is the premium that was received. The naked call writer, therefore, is faced with the unattractive prospect of a
limited profit and a seemingly limitless loss.

Debugging tips in Visual Studio

1)      Break on all Exceptions (even if it is handled) Go to Debug  > Exception (Ctrl Alt E). This will be useful when you are given an unknown application that collects all the errors and shows it at once on the top of the screen. You do not know the source of the error (or the exception). Just enable this option and find out directly.
2)       A faster way of debugging an error is to do it backwards i.e. go the known bottommost function and start doing a step out (Shift – F11) to climb up and see where it fails. This is better (faster) than debugging from start (top) and doing Next >> Next. The “starting from bottommost” technique will give all the call flows at once in the CallStack window.
3)      If you want to change value of any variable while debugging (during runtime), use immediate window and just write VAR1=”abc” in the window.
Or hover over the variable , write the value there itself and press Enter.
4)       Conditional BreakPoint in Loops: You can attach a breakpoint in a FOR or FOREACH loop and when it hits it, right-click on the breakpoint and you can put a CONDITION say when p.FirstName=="Paul". So you dont have to iterate through the  whole collection one by one. There are other options as well when you right click.
5)      To attach a breakpoint at every place for a particular function (called Function Breakpoint), Go to the breakpoints window à New à Break at function (or press Ctrl + B). Type the function name.