Tuesday, April 21, 2009

Old Undocumented Project: Turtel

Going through my source files, I came across one of my old projects. A very interesting one...that I eventually somehow forgot about..till I saw it today. I had code-named the project 'Turtel'. It's undocumented in the sense that I never mentioned it in the Blog.

The project was an attempt to understand the effectiveness of different indicators and strategies if used in the stock market.

I was also exploring Design Patterns at this time. The project became multi-purposed - to improve my understanding of the patterns (I seemed to have used the Strategy Pattern and the Factory pattern in my implementation) and explore the effectiveness of investment strategies.

Here is a link to the last version (I believe) - where I left off - Project Turtel

The page above is not very interactive. But what it does is very cool (imo :)). You pass along 5 variables in the query string: fee, P, K, symbol, days, show

Fee is the transaction fee per purchase/sale
P and K are used for cross-overs I believe - values of 10 and 2 for example mean when the 10 day SMA crosses the 2 day SMA etc...
Symbol is the stock symbol - as listed in Yahoo (for example RIM would be RIM.TO)
Days indicates the number of days of data to use - a value of 100 would mean use the last 100 days of data
Show indicates whether to show the dates and quantities of transactions. A value of 1 means "yes, do show"; anything else means "no, don't"

Two strategies were implemented at the time - SMA cross-over and I think MACD cross-over. The outputs are based on these two.

Here is an example of the URL with the query string. The bolded parts are what you would change to see the output for the new values.

http://www.ai-projects.info/Turtel/sim/driver.php?P=10&K=2&days=501&show=1&symbol=RIM.TO&fee=0

May be I shall continue this project some day. But for now its probably going to stay in its suspended state. This is one of the reasons I like to look into my old stuff - I usually find something interesting :)

Labels: , , ,

Sunday, December 28, 2008

Server Side Scripting in Blogger (aka PHP, ASP etc in Blogger)

I wanted to try and add some php code to blogger, and when I added some php code to the template page, nothing seemed to happen....here is how you make it work:

It is actually very simple. It is a 2 step process.

Step 1: Set your blog file name in publishing option to index.php (the default is index.html). The fact that its a php file now allows you to integrate php code in the template that would be processed by the server. Here is an image of where you would do this:


Step 2: Add the php code to your template. Here is an image showing that.


The same steps will be followed for ASP pages or anyother server side scripting language - the difference being, the blog filename extension would have to correspond to the language (.asp for ASP).

The drawback is that this would only work on the index page, the rest of the pages (archives, post permanent link pages etc) are still generated as html pages.

Labels: , , ,

Tuesday, September 16, 2008

Presenting the YWeather API

I was designing a site this weekend when I needed some weather data. I started looking for solutions - I found phpweather and I found it to be an excellent tool. However, when I tried to query some "less" known cities, it returned nothing. One of the cities that I wanted the data for did not exist and I was disappointed.

Knowing that I can use sites like the weather network and get the weather data, I figured I might as well write my own class to fill this void. Thus was born the YWeather. YWeather is a php class that provides a class interface to access data from Yahoo Weather. It makes use of the Yahoo weather RSS feed.

The YWeather class uses MagpieRSS to parse through the RSS feed. When a location id is specified, the class parses the feed and gives a class interface to the weather data, making it easy to integrate to any web application.

Here is a test script I created to test the class, this list provides a list of the features of the class (I am too lazy to type this out :P)

$w = new YWeather("CAXX0504");

"URL: ".$w->getURL()
"Title: ".$w->getTitle()
"Skies: ".$w->getSkies()
"Skies Image: getImage($w->getSkies())."' />"
"Temperature: ".$w->getTemperature()
"Latitude: ".$w->getLat()
"Longitude: ".$w->getLong()
"isPM: ".$w->isPM()
"Published date: ".$w->getPublishDate()
"Description: ".$w->getDescription()
"Current Conditions: ".$w->getCurrentConditions()
"Forecasts: ".$w->getForecastsText()

The Yahoo feed provides 2 days forecast:

$forecasts = $w->getForecasts();
"Forecast 0 Day: ".$forecasts[0]['day']
"Forecast 0 Skies: ".$forecasts[0]['skies']
"Forecast 0 Skies Image: getImage($forecasts[0]['skies'])."' />"
"Forecast 0 High: ".$forecasts[0]['high']
"Forecast 0 Low: ".$forecasts[0]['low']
"Forecast 1 Day: ".$forecasts[1]['day']
"Forecast 1 Skies: ".$forecasts[1]['skies']
"Forecast 1 Skies Image: getImage($forecasts[1]['skies'])."' />"
"Forecast 1 High: ".$forecasts[1]['high']
"Forecast 1 Low: ".$forecasts[1]['low']


The class may be downloaded from here.
downloads/YWeather_w_magpie.zip

Labels: , ,