Posts
74
Comments
75
Trackbacks
0
January 2008 Entries
LINQ and Financial Simulation

improve my => 'code' Add to Google

I just started playing around with seriously, and I really love some of the features incorporated, like the Enumerable.Range() function and how it can be used for integer programming.

Here's a simple function for generating lognormal distributions (could be useful for financial engineering).

Hope you're enjoying the samples,

Jonathan Starr

 public List<double> GenerateLogNormalDistribution(int numberOfTimes, double mean, double standardDeviation)

{

    Random randomGenerator = new Random();

    var randomNumbers = from theNumbers in Enumerable.Range(1,

        numberOfTimes).Select(x => randomGenerator.Next(1,

  1000)/1000.0)

        select theNumbers;

 

    List<double> results = new List<double>();

    randomNumbers.ToList().ForEach

        (x => results.Add(mean + (standardDeviation * (Math.Sqrt(-2 * Math.Log(x)) * Math.Cos(6.28 * x)))));

 

    return results;

}

posted @ Friday, January 25, 2008 8:00 PM | Feedback (4)
Surprising CLR Behavior

improve my => 'code' Add to Google

The following code (surprise, surprise) compiles.  But it does not work as intended  (you won't be able to "doSomethingElse()!

Can any of you figure out why?  (I have my suspicions.)

Jonathan Starr

using System;

namespace test

{

    internal class BaseTest

    {

        private int _prop1;

        public virtual int prop1

        {

            get { return _prop1; }

            set { _prop1 = value; }

        }

    }

 

    internal class DerivedTest : BaseTest

    {

        public override int prop1

        {

            set { base.prop1 = value; doSomethingElse(); }

        }

    }

}

 

posted @ Friday, January 25, 2008 4:45 PM | Feedback (1)
Response to Brainteaser #11?

I have been pretty excited about LINQ, because it seems to do all of the optimization for me for free (kinda like T-SQL). 

Yow Han-Lee asks in his blog, Brainteaser #11, Given any two large List, what is the quickest way to find the mutual intersection of the two? Now take into consideration memory constraints?

 Well, the answer that only takes a minute or two for me is the following...

Comments welcome!

Jonathan Starr


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace orderlisttest
{

    internal class Number
    {
        private int _Num1;
        public int Num1
        {
            get { return _Num1; }
            set { _Num1 = value; }
        }

        public Number(int theNumber)
        {
            this._Num1 = theNumber;
        }

    }
    public class start
    {

        public static void Main(string[] args)
        {
            var bigList1 = new List<Number>();
            var bigList2 = new List<Number>();

            for (int counter = 0; counter < 100000; counter++)
            {
                Random randomGenerator = new Random();
                int number = randomGenerator.Next(10000000);
                bigList1.Add(new Number(number));

                int number2 = randomGenerator.Next(10000000);
                bigList2.Add(new Number(number2));
            }

            var Found = from o1 in bigList1
                        join o2 in bigList2 on o1.Num1 equals o2.Num1
                        select new { o1.Num1 };

            Console.WriteLine(Found.Count().ToString() + " items were found in common.");
        }

     }
   
}

posted @ Friday, January 25, 2008 3:23 PM | Feedback (0)
Beauty.Equals(Truth) ?

improve my => 'code' Add to Google

I noticed an entry on Wikipedia that made me smile.

SPL or the Shakespeare Programming Language is, in the words of Wikipedia, "designed to make programs appear to be something other than programs; in this case, Shakespearean plays. "

Variables in code are treated like characters in a Shakespearean play.  Variables must "enter" to be useable (allocated?) and "exit" to be declare out of scope...   And variables speak their mind to output to the console.  For instance,

[Enter Juliet]
[Enter Romeo and Juliet]

Hamlet:
Thou art as sweet as the sum of the sum of Romeo and his horse and his black cat! Speak thy mind!

[Exit Romeo]
[Exeunt Romeo and Juliet] [Exeunt]

My only point is - Do you write your code pleasing to the eye?  Or is it a jumble of symbols barely comprehensible? 

I am all for bringing a sense of beauty to our coding, and am open to suggestions.

Interested in your comments,

Jonathan Starr

posted @ Tuesday, January 22, 2008 1:58 PM | Feedback (0)
The Sesame Street Presentation Rule - Not #1

I just read through Jeff Atwood's recent post - The Sesame Street Presentation Rule - and it warrants a reaction.

The most important feature of a presentation is that it communicates how you can benefit your audience.  People are not actively trying to fund cartoons or quips as much as they are looking out for their own very personal needs (whatever that is).  So, it is vital that we analyze our audience for their needs - as needs differ.

Employees are generally interested in security, and possibilities for advancement.  Investors generally look for quick and sizable returns on investment. If you focus on the particular interests of your audience, there is very little need to be funny. 

Humor can help - I will concede.  But it is so difficult to be funny.

Hey, Jeff Atwoods' blog is a case in point.  Really not very funny, but he satisfies the needs of his readers to explore quirky topics.

Interested in your thoughts,

Jonathan

posted @ Monday, January 21, 2008 2:53 PM | Feedback (0)
Thought Experiment: Reforming Meetings

I just read an excellent article posted on XKCD on how to create a better IRC chat.

Basically, to keep chats interesting, the server boots out users who enter things already entered before.

Wouldn't that be good for corporate meetings? The rule could be amended: If someone says anything said before (even using different words), the person cannot speak again for the duration of the meeting. 

Imagine how much shorter meetings would be with this rule.  No more endless repetitions.  No more wasted time.

Another nice side effect is that meeting attendees might pay more attention to what is said - because they are enforcing the rule!

Interested in you thoughts,

Jonathan Starr

posted @ Wednesday, January 16, 2008 5:31 PM | Feedback (0)
Automatic Properties in C# - A Critique

improve my => 'code' Add to Google

In the latest release of Orcas, one of the new features provided is "Automatic Properties" which allows developers to use a shorthand like the following:

    public class Person {
    
        
public string FirstName {
            
get; set;
        
}

        
public string LastName {
            
get; set;
        
}        
        
        
public int Age {
            
get; set;
        
}
    }

and the compiler knows to interpret this as

    public class Person {

        
private string _firstName;
        private string 
_lastName;
        private int 
_age;
        
        public string 
FirstName {

            
get {
                
return _firstName;
            
}
            
set {
                _firstName 
= value;
            
}
        }

        
public string LastName {

            
get {
                
return _lastName;
            
}
            
set {
                _lastName 
= value;
            
}
        }        
        
        
public int Age {

            
get {
                
return _age;
            
}
            
set {
                _age 
= value;
            
}
        }
    }


Prima facie, this looks like a good thing.  The developer is typing less code, and still has hooks in property accessors to perform validation, or needed side effects from value changes.

But I have a few problems with this shorthand.

Criticism 1

Why is this shorthand needed when there is a snippet (prop) that provides full property accessors, with better hooks for inserting custom actions like validation?

Criticism 2

I think that the shorthand looks too much like the signature of a method normally found in an interface, not a class.  The only difference appears to be an access modifier. So I find the shorthand syntax is confusing...


What do you think?

Jonathan Starr
posted @ Tuesday, January 15, 2008 8:00 PM | Feedback (3)
Instructional Video #3 for Mobile Phone Project management

I did one more video with a friend today for 1CCN.COM - which is a mobile phone project management toolset custom designed for the construction industry.

The video below shows you how a user can add time entries via mobile phone to a project.

I am very interested in your comments!  Is the video easy to understand?

Jonathan

 

posted @ Sunday, January 13, 2008 8:17 PM | Feedback (3)
Reminder

improve my => 'code' Add to Google

Just a quick reminder to the Saint Louis developers out there.  There is another Saint Louis .NET User Group meeting on Monday, January 14th at 2 City Place.

Details are here in the updated Saint Louis Microsoft Technology calendar.

Hope to see you there!

Jonathan

posted @ Saturday, January 12, 2008 9:46 PM | Feedback (1)
1st Instructional Video
I have been helping a friend finish a mobile web application for his new business (www.1CCN.com), and posted below are my first attempts for making instructional videos.  Windows Movie Maker (which comes with Vista) was a blast - really easy to use.

Any comments are appreciated - btw, we will be adding Ajax to the budget entries tomorrow.

Thanks!

Jonathan



Adding a contact to the Contractors' Collaborative Network



Creating a Project in the Contractors' Collaborative Network
posted @ Saturday, January 12, 2008 8:55 PM | Feedback (0)
Critique of Richard Bookstaber's, “A Demon of Our Own Design”

I just finished Richard Bookstaber's new book, A Demon of Our Own Design: Markets, Hedge Funds, and the Perils of Financial Innovation, and he makes some fair points.

He asks a very important question in the book, in my opinion, “Why have economic cycles become less extreme while financial cycles have become more extreme?”. 

After all, our knowledge of financial instruments has increased over time, we use computer applications to help us hedge risk in better ways today, and we have better and more reliable streams of information for traders to navigate today's financial waters.

His answer, which I find intriguing, is that liquidity is the most important determinant of short term price swings (which is very different from the conventional answer - fear and greed).  He points out that financial instruments with different risk profiles quickly became correlated with each other because they were packaged together.  (Perhaps traders now have better means of smelling blood in the waters as well?)

I suppose this may be the reason we see Bank of America purchasing Countrywide today.  Bank of America had a lot of information about Countrywide because of their $2 Bn in the company over the summer, and they probably realized that providing liquidity to Countrywide's positions would not only enhance the value of today's $4Bn takeover, but also the existing $2 Bn investment made earlier.

Interested in your thoughts,

Jonathan

 

posted @ Friday, January 11, 2008 6:27 PM | Feedback (0)
Re-Adding Service References
improve my => 'code' Add to Google

While using Visual Studio 2008, I made the mistake today of dropping and re-adding a WCF service reference.  If you do this, not all of the service operations and exposed proxy types are recreated in the References.cs file.

If you made my mistake, cleaning the solution (right click on the solution and choose -> Clean Solution) will clear out the problem.

And in the future, I will be updating service references instead.

Hope this helps you out!

Jonathan

posted @ Friday, January 11, 2008 5:30 PM | Feedback (0)
Motivating Developers

I was just reading Jeff Atwood's post - The Magpie Developer - where he uses the metaphor of the magpie who collects shiny objects for his nest to explain why elite programmers go from one programming language to another.

Perhaps it would be more useful to think about what really motivates programmers generally.  After all, while the pay is okay in our profession, most of us  work in relative isolation on problems not generally of interest to the public.

Personally, I studied math as an undergrad - and the study of patterns interests me.  Creating systems to analyze and distribute changing informaiton intrigues me. 

Later on, I earned an MBA, where I learned a great deal about leverage - mostly using people or money as leverage.  But it occured to me that in the Information Age we live in the most efficient form of leverage may be using information technology.

So, for me, motivation comes from learning new patterns (I still get a kick out of learning new design patterns) and finding ways to use the web, or mobile devices, to create leverage.

I would guess that there are many other good motivations for becoming an excellent developer:

- The creative instinct to produce something new.

- The instinct to make something perfect (performant with accurate results).  (I think excellent developers are definitely prefectionists to some degree.)

- The instinct to solve an important problem - or just a puzzle...

- The instinct to show off to geek friends.

- The instinct to improve your skillsets to make your career more stable.

What motivates you as a developer?

Interested in your thoughts,

 

Jonathan Starr

 

posted @ Monday, January 07, 2008 5:26 PM | Feedback (2)
News
Jonathan Starr is a developer in Saint Louis, MO. He holds an MBA in Finance from Columbia Business School and earned his MCSD from Microsoft.


All statements in this blog are personal opinions and do not reflect the opinions of his employer.





Related Sites
Join My Community at MyBloglog!

Tag Cloud