Tuesday, April 17, 2007

Gold Stocks - Trade Idea

Over the last year, I have benefited from one trading strategy involving gold stocks. First of all, I believe that gold will continue to rise, first as a hedge against inflation and second as a hedge against the falling us dollar.

With that said, it seems that gold stocks would be the place to be. My strategy is simple: write 'in the money' naked put options on gold stocks that I wouldn't mind owning for the amount of shares that I am willing to buy.

The seller of a put option has the obligation to buy shares in a company at a specified price at a certain time. In return for this obligation, a put seller gains a premium. Most gold companies are volatile, thus garnering larger premiums.

As an example, take Barrick Gold Corp (ABX on the NYSE; ABX on the TSX). Currently, this stock is trading at around $30 USD per share. Assuming that you thought this stock was going to follow the price of gold higher and that you wanted to buy 500 shares, then following the strategy above, you would:
  • sell 5 put contracts (uncovered) for the month of May for a premium of around $1 per contract
  • ensure that your account has enough money in it to finance the trade (in this example, $15,000)
Doing this, you would gain $500 (minus commissions) and come the third Friday of May, if the stock is trading less than $30, you are obliged to purchase 500 shares at $30 dollars. Otherwise, you keep the $500 and repeat the strategy the next month if you still are bullish on Barrick and the price of Gold.

Keep in mind that there are numerous gold producing companies out there, not just Barrick Gold and that those companies that exhibit wild fluctuations in daily share price, usually garner larger premiums.

Good luck.

Disclaimer:
  • I am not be liable for any investment decision made or action taken based upon the information on this page.
  • I suggest you check with a broker or financial adviser before making any stock investing decisions.
  • I am not offering financial advise, but rather commenting on widely available investment strategies.
  • Finally, Caveat emptor!

Friday, March 02, 2007

Solving Pesky ssh Issues in Cygwin

Every time that I re-install cygwin and I use ssh for the first time, I encounter minor annoyances. My biggest annoyance is the fact that no matter how many times I log into a remote machine, cygwins' ssh utility tells me the following:

Could not create directory '/home/ME/.ssh'.
The authenticity of host 'xxx.yyy.zzz.ca (1xx.82.67.xx)' can't be established.
RSA key fingerprint is 6c:59:15:64:ed:c8:67:35:d6:ed:1c:a2:ee:87:2b:3f.
Are you sure you want to continue connecting (yes/no)?
Once I enter 'yes', I get the following:

Failed to add the host to the list of known hosts (/home/ME/.ssh/known_hosts).

So that message occurs every single time that I attempt to login to the remote machine.

So the question is, how do I solve this problem? The solution was actually quite simple!

First locate the file called 'passwd' in your C:\path\to\cygwin\etc directory and open it with wordpad.

Second, replace the text
/home/YOUR_NAME
with
/cygdrive/c/Documents and Settings/YOUR_NAME

Finally, save the file.

In hindsight, the solution is very straightforward, but it took me hours to finally figure out. Hopefully, I can save your time!

Saturday, February 03, 2007

Maven, Windows and Deploying to a Remote Location

If you are a programmer on Windows, some tasks take longer to perform than others. Attempting to set up maven so that you can deploy files to a remote machine is one of those tasks!

Here is what you need to get the job done:
  1. Download plink
  2. Download puttygen
  3. Download pscp
If the above links do not work, use Google and search for "putty download".

Once you download them, place them in a folder called putty and move that folder to your root drive (C:\). The next thing that you should do is add that folder to the PATH. Not sure how to do that?
  1. press the windows key and 'pause break' at the same time.
  2. A system properties panel will appear. Click on the 'Advanced' tab.
  3. Click on the 'Environment Variables' button.
  4. Locate the PATH variable from the System variables portion of the panel and choose 'Edit'.
  5. Append, without quotations, ';c:\putty;' to the end of the PATH value.
  6. close the panels and you are done!

Now you need to create a private key from the remote server that you would like to deploy your files to.
  1. ssh into the remote machine
  2. execute the following command on the remote machine
    ssh-keygen -b 1024 -f ssh_host_key -N '' -t rsa
    This will create a file called ssh_host_key.
  3. On your local machine, create a folder called c:\ssh and place the file, ssh_host_key, in that folder from the remote machine.

The key that we generated on the remote machine will now be used to create one that is compatible with putty. We will now use puttygen to create a 'putty' private key.
  1. Double click the file puttygen.
  2. Make sure that you select you select 'ssh-2 RSA' at the bottom of the page.
  3. Next choose, Conversion -> import.
  4. Select c:\ssh\ssh_host_key.
  5. Save the generated key (save both the public/private key) in c:\ssh.

Most of the 'hard' stuff is now done. Next we will add our remote server to our local maven configuration. To do this, we will have to modify the file settings.xml.

The settings.xml file is usually located in
c:\Documents and Settings\<user>\.m2.

Before proceeding, you should back up the file. Open settings.xml in Wordpad and add the following fragment of xml into the file:

<server>
<id>remote-repository-id</id>
<username>your_username_here</username>
<password>your password here</password>
<privateKey>c:/ssh/your_private_key.pkk</privateKey>
<configuration>
<sshExecutable>plink</sshExecutable>
<scpExecutable>pscp</scpExecutable>
</configuration>
</server>
That piece of xml goes in the servers portion of the file. Add it and modify the bold pieces of the text.

That's really all there is to do. However, if you are lazy, like myself, then create a windows batch file that does the deploying for you!

Below is one that I use. You will have to modify the lines in bold. Run it without arguments first, to have it display the usage!

@echo off
if "%1"=="" GOTO ERROR
if "%2"=="" GOTO ERROR
GOTO DEPLOY

:ERROR
@echo off
echo There was an error deploying file.
echo usage:
echo %0 jar pom [repository_id]
goto END

:DEPLOY
setlocal
set REPO=%3
if "%3"=="" set REPO=remote-repository-id
@echo on
REM should be on one line!
mvn deploy:deploy-file -Dfile=%1 -DpomFile=%2 -Durl=scpexe://remote_server_domain/:/remote/path/to/maven/ -DrepositoryId=%REPO%
REM end one line
endlocal
@echo off
GOTO END

:END
@echo off