Easy Investment Portfolio Rebalancing Spreadsheet

This has nothing to do with development, but whatever.

 

I’ve been playing around with tools and methods for portfolio management.  I’m no investment whiz, and I don’t have the time to actively track individual company performance, so my portfolio contains only simple Schwab index ETFs with low expense ratios.  When portfolio rebalancing time comes around, though, I try to get the job done as quickly and efficiently as possible while staying on track.

 

One of the best tools I’ve found for portfolio rebalancing is the Optimal lazy portfolio rebalancing calculator, written by Albert Mao.  This calculator lets you figure out how much money to allocate to each stock in your portfolio given a target allocation percentage, without having to sell any over-weighted assets.

 

I have put together a template Google Spreadsheet that attempts to simplify this process as much as possible.  On the right side of the spreadsheet, you can see current ask and bid price, which are automagically pulled from Yahoo! Finance API and Google Finance Spreadsheet API, respectively.  These values are forwarded over to the columns on the left side of the spreadsheet.

To get your rebalancing calculation:

  1. Enter in your current porfolio values for each stock
  2. Adjust your asset allocation percentages if needed
  3. Copy the left 4 columns of the template into the textbox on the rebalancing calculator and hit Recalculate.

To track this information over time, I make side-by-side (before and after) charts on each rebalancing date using the left chart in the spreadsheet, with the Value column reflecting the before and after values for each transaction.

 

Links:

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Step-by-step quick installation of Redmine + SVN on Windows

Through trial and error, I have done a quick setup of Redmine + SVN on Windows.  This does not use Apache and WebDAV.  The Ruby on Rails webserver, Mongrel, is used, and SVN is accessed through svnserve (svn://).  If you need a full deployment of Redmine, with automatic generation of SVN repositories and SVN accounts, this can be a starting point (let me know how you got it to work!).  If you want a quick and dirty setup, this may be the only guide you need!

Here are the steps:

  1. Go to http://rubyonrails.org/download
  2. Install Ruby
  3. Install RubyGems
  4. Run [ gem install rails ]
  5. Run [ gem install mysql ]  (in case we want to use mysql as db, sqlite is fine though)
  6. Run [ gem install rake ]
  7. Run [ gem install sqlite3-ruby ]
  8. Extract redmine (I extracted to C:\Ruby\redmine-0.8.4)
  9. Browse to redmine folder/config
  10. Copy database.yml.example to database.yml
  11. Set database options for production:
    1. In production:
      1. adapter: sqlite3
      2. dbfile: db/prod.db
      3. host: localhost
  12. Get sqlite3.dll from sqlite 3 distribution (http://www.sqlite.org) and put in Ruby/bin directory
  13. Browse to Redmine directory in command prompt
  14. Run [ rake db:migrate RAILS_ENV=”production” ]
  15. Run [ rake redmine:load_default_data RAILS_ENV=”production” ]
  16. Run [ gem install mongrel ]
  17. Run [ gem install mongrel_service ]
  18. Run [ mongrel_rails service::install -N Redmine_Server -D “Redmine Server on Mongrel” -e “production” ]
  19. Start service and set to “Automatic”
  20. Username: admin Password: admin
  21. Refer to http://www.redmine.org/wiki/redmine/RedmineInstall for SMTP config (If you want emails generated for tickets, etc.)
  22. Install CollabNet SVN as svnservice (WebDAV not needed), svn root C:\svn_repository
  23. Start service “CollabNet Subversion svnserve”
  24. Run [ svnadmin create c:\svn_repository ]
  25. Uncomment anon-access = read, auth-access = write, password-db = passwd in svnserve.conf
  26. Add users to Redmine, have user change password to whatever they want it to
  27. Add users to passwd (same username), all plaintext, so create random passwords for each user and have them record it (cannot be changed unless requested by admin, and admin will know what pw is)
  28. Restart Redmine_Server service
  29. Create subfolders for projects, and trunk/tags/branches for each project
  30. Add svn://localhost/projectname as project root for each project in Redmine
VN:F [1.9.22_1171]
Rating: 4.8/5 (4 votes cast)
VN:F [1.9.22_1171]
Rating: +4 (from 4 votes)

Flex Builder and Eclipse 3.5

Here’s a blog post by a frustrated developer who seems to have found out how to set up the Flex Builder plugin with Eclipse 3.5 (I have tried it and it works!).  Thank you, frustrated developer!

http://worldwizards.blogspot.com/2009/08/eclipse-35-and-flex-builder.html

From the post:

(1) Download and install Eclipse 3.5. I used the J2EE install.
(2) Download and run the Flex Builder 3 installer.
(3) Ignore all the warnings that it only supports Eclipse 3.3 and 3.4. Just keep telling it that you know what you are doing and want to install it anyway. It will end with a scary message about failing and suggest you do a manual install from inside of eclipse. Don’t do that!
(4) Here is the magic, when it is done there will be a file in your eclipse/links directory called
com.adobe.flexbuilder.feature.core.link
Open that file in wordpad and you will see it contains one line:

C:/Program Files/Adobe/Flex Builder 3 Plug-in

Edit that line so it looks like this:

path=C:/Program Files/Adobe/Flex Builder 3 Plug-in

Save the file and start eclipse. Voilla!

VN:F [1.9.22_1171]
Rating: 5.0/5 (9 votes cast)
VN:F [1.9.22_1171]
Rating: +4 (from 4 votes)

Been a while…

I haven’t posted on this blog in a while since I haven’t been doing much development (just graduated from grad school, hadn’t found a job yet). Well, now that I do have a job, the development blog posts will continue as I find and solve particular developmental problems.

Work environment: C# (.NET/ASP), Adobe Flex, possible iPhone application along the way

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Google Maps Flex API: Refresh TileLayer without refreshing map

This submission is in response to this gmaps-api-flex feature request. This is a hack that provides functionality like what was requested here.

So you’ve added a custom tile layer to your Google Maps app in Flex, which lets you show all your pretty spatial features. Fantastic! If you want to make this tile layer dynamic, however, you run into a few problems. The Google Maps Flex API caches tiles that it has loaded from a specific Tile Overlay, so if your data changes, the changes won’t be reflected on your map immediately. There have been various hacks that force a refresh of the map, but they don’t completely meet the requirements set in this feature request. The attached code here is a hack that tries to mimic the requested functionality, without refreshing the entire map.

After exploring a little, I saw that one way the Flex API differentiates overlays is by the request URL. If you create an overlay, add it to the map, remove it, create a new overlay with the same URL, and add the new overlay, it will load the tiles from the internal cache. Now, this functionality can be nice if you’re switching between two different overlays, and there haven’t been any changes in the data. For instance, if an app requests tiles from the following URLs in order:

mapserver.php?X=0&Y=0&Z=0&LAYERS=calicounties

mapserver.php?X=0&Y=0&Z=0&LAYERS=oregcounties

it will load both of these layers properly, and cache them both. If you then load the calicounties layer, using the same URL string, it’ll give you back the cached version.

However, if the data has changed, you’d want to reload the entire layer. To do this, I have appended a garbage GET variable to the URL. The requests will now look like:

mapserver.php?X=0&Y=0&Z=0&LAYERS=calicounties&GARBAGE=SDK34K

mapserver.php?X=0&Y=0&Z=0&LAYERS=oregcounties&GARBAGE=SDK34K

Simply change the GARBAGE variable when loading calicounties again and it’ll load from the source.

The included code implements four events that are dispatched to/listened from the map object:

  • TileLayerRefresh
    • Tell the Tile Layer to refresh (do not change the GARBAGE variable)
  • TileLayerReload
    • Tell the Tile Layer to reload (change the GARBAGE variable)
  • TileLayerRefreshed
    • Refresh/Reload completed successfully (all tiles loaded)
    • Implemented by incrementing a counter whenever Loader instances are created, and decrementing the counter whenever they complete/fail.
  • TileLayerRefreshError
    • If any loading errors occurred.

Note: You need to pass the TileLayer both the TileOverlay that holds it and the Map object, so it can handle refreshing and event dispatch by itself.


var tileLayer:MapServerTileLayer = new MapServerTileLayer(map);
var tileLayerOverlay:TileLayerOverlay = new TileLayerOverlay(tileLayer);
tileLayer.setOverlay(tileLayerOverlay);
map.addOverlay(tileLayerOverlay);

For an example on using MapServer/PHP MapScript with Google Maps, go to this blog post.

Attached Files:

VN:F [1.9.22_1171]
Rating: 5.0/5 (3 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)

Get request headers sent by client in PHP

A nice little function I found posted by “lazynitwit” on BlueHost forums:

function getHeaders()
{
$headers = array();
foreach ($_SERVER as $k => $v)
{
if (substr($k, 0, 5) == "HTTP_")
{
$k = str_replace('_', ' ', substr($k, 5));
$k = str_replace(' ', '-', ucwords(strtolower($k)));
$headers[$k] = $v;
}
}
return $headers;
}

The PHP function getallheaders() only works on Apache, and only if Apache has been installed as a module.

It turns out that this information is within the $_SERVER global variable, and can be parsed out.

This code is useful if, for instance, you want to differentiate between user browser requests and requests made through AJAX. Some of the JavaScript frameworks (jQuery, Prototype, YUI, MooTools) send a special header,

X-Requested-With: XMLHttpRequest

whenever a request is made. I have put this to use in my phpFreeChat chat box to allow channels to be specified in the URL as GET parameters.

via request headers php – bluehostforum.com.

VN:F [1.9.22_1171]
Rating: 4.4/5 (12 votes cast)
VN:F [1.9.22_1171]
Rating: +5 (from 5 votes)

Wrapper classes for using SQLite on iPhone/Cocoa

Information on using SQLite for local storage on Cocoa isn’t all that easy to find. The best resource, as always, is Google, and you can find a few tutorials with step by step instructions and code samples on how to use it. Well, here’s another basic step by step set of instructions, but rather than including code samples, I have written a couple of wrapper classes for creating databases, making queries, and getting results.

Steps:

1: Include the SQLite framework in your project. It’s usually located somewhere like “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk/usr/lib/libsqlite3.0.dylib” (why is developer in there twice?)

2: Create a base sqlite database file, and modify SQLite.m so that the filename method refers to it. Place it in your main resource path. This will be copied out of your bundle into your application’s Documents directory. If you need help on creating one of these and managing it, there is a fantastic FireFox extension that does it for you!

3: Add the source files to your project.

Usage can be as simple as:


SQLiteResult *result = [SQLite query:@"SELECT * from test;"];
NSArray *row = [result.rows objectAtIndex:0];
NSString *firstValue = [row objectAtIndex:0];

NSArray columnNames contains NSStrings of all the names.
NSArray columnTypes contains NSStrings of all the types.
NSArray rows contains NSArrays, where each of these contains NSStrings of all the row values in that row.

Attached Files:

VN:F [1.9.22_1171]
Rating: 4.5/5 (11 votes cast)
VN:F [1.9.22_1171]
Rating: +5 (from 7 votes)

MapServer: Using Google Maps with PHP MapScript

Generating Google Maps tiles using MapServer is not completely intuitive. For static map applications, a new tile mode has recently been created for MapServer CGI mode ( http://mapserver.org/output/tile_mode.html ).

For more dynamic mapping applications, PHP MapScript is an ideal way execute this, as it only requires a very small static component (an initial map file, which won’t even be needed when MapServer 5.4 comes). Included is a short PHP example on how do go about doing this. The PROJ.4 projection parameters included are for the Google Maps mercator projection.

The sample code includes WGS84 to Google Maps mercator projection as well as the calculation of mercator extents from Google Maps tile indices.

This example has been extended from the previous iteration to include dynamic layer generation and POINT geometry feature symbols via image files. The $phplayers variable holds layer definitions that have been queried from a database table, obtained using the getLayersForSessionID($sessionID) function. The table includes layer table name, layer geometrytype layer geometry name, and a symbol definition for the layer. For point layers, this is an image file (ie. “image.gif”), and for polygon and line layers, this is a line color (255 0 0 for red).

Attached Files:

VN:F [1.9.22_1171]
Rating: 3.8/5 (4 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)
WordPress Loves AJAX