Monday, December 26, 2011

C++: "string" to C char*

Apparently there's a built in function for the c++ std::string type:
c_str()


Why does it come up? Things like ifstream are initialized with char* file names, not std::string.

Thursday, December 22, 2011

MS SQL and Python

Had trouble connecting Python to MS SQL Server. Here is the answer!

MS-SQL and Python

In short:
  • Set up your ODBC Data Source Administrator
  • Insert Python code using very built in imports (dbi, odbc)

    Python code:

    import dbi
    import odbc

    query = "SELECT * FROM default_table";
    conn=odbc.odbc("odbc_data_source_admin_name");
    cursor = conn.cursor();
    cursor.execute(query);
    print (cursor.fetchall());
  • Sunday, December 11, 2011

    Slavery and Freedom

    When people impose order on you, they enslave you.
    When you impose order on yourself, you liberate yourself.

    Saturday, November 26, 2011

    The Product

    Is this the answer? "Sculley believed in keeping people happy and worrying about relationships. Steve didn't give a shit about that. But he did care about the product in a way that Sculley never could, and he was able to avoid having too many bozos working at Apple by insulting anyone who wasn't an A player."

    Friday, November 25, 2011

    8353: Bugs today

    1) Was chasing around this bug for a few hours: for some reason my posts for my navigation bar wouldn't go to the right URL (select_auction.php), except when I was at the right URL (select_auction.php) to begin with. Turns out, I wrote
    action-"select_auction.php"
    What surprises me is the fact that this worked correctly for when I was at select_auction.php. I guess the default behavior for HTML is rather tolerant (redirect confused posts to self) which makes it hard to find bugs!

    Thursday, November 24, 2011

    8352: Bugs today

    1) For MySQL Queries, don't forget the "Quotations that surround text fields" when INSERTing new values
    2) Know when to tinker, and when to use the manual

    Thursday, November 10, 2011

    Quickie on Make Files

    Found it at this quick Makefile Tutorial

    CC=g++
    CFLAGS=-c -Wall
    LDFLAGS=
    SOURCES=main.cpp hello.cpp factorial.cpp
    OBJECTS=$(SOURCES:.cpp=.o)
    EXECUTABLE=hello

    all: $(SOURCES) $(EXECUTABLE)

    $(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

    .cpp.o:
    $(CC) $(CFLAGS) $< -o $@

    Wednesday, November 9, 2011

    Bugs I was caught up on today

    161 Program:
    (+) Using a bit counter, identifying the right bit in a bunch of buckets.
    (+) Dereferencing and incrementing properly in the same line

    Wednesday, November 2, 2011

    Meeting with Travis - On beginning

    Travis, founder of 27bards.com gave me some advice on starting out. Key takeaways?

    First, be solution-focused. Think about the problem you want to solve. Money is just a metric for the value of your answers.

    Next, work effectively. Your breaks should be commensurate with your work. Not getting enough sleep or space to think bogs down your mind, keeps you from holding complex code in your head. On the other hand, checking news every couple of minutes sucks.

    Third, learn early and often. Do lots of side-projects. Learn LAMP. Just do it. And don't forget 1.

    Schedule a meeting with him in another couple of weeks to check your progress.

    Tuesday, October 25, 2011

    Day 1

    Of the first day of my life.

    I am starting anew, in a sense. Everyone wants their chance. This is my chance.

    The first step is to follow the ways of Bruce Lee. Read his story, copy his steps, perfect everything.

    Wednesday, October 19, 2011

    A person can do anything.

    And you can do anything a person can.
    Ergo: You can do anything.

    6-Pack abs

    One man's routine:For six-pack, on YouTube
    Some Takeaways:
    • Decline-bench situps
    • Leg lifts
    • Overhead cable crunch
    • 7-7-7s
    • Medicine Crunches
    • Plank, to finish it off
    Keep it at around 15 reps generally. The biggest factor though is a good diet, which will help you burn off fats.

    Tuesday, October 18, 2011

    Don't forget in silicon valley...

    Fate changes rapidly (your company's profits, for example) but people change organically (you, for example).

    Converse, Inverse, Contrapositive

    Okay, I'm going to need a mnemonic because I always mix these up.
    • statement: if p then q

    • converse: if q then p

    • inverse: if not p then not q

    • contrapositive: if not q then not p


    Check the source out for more information.

    Sunday, October 16, 2011

    Python with SQL

    To be used at PPC when I get the chance. I want to make my current reporting system more robust.

    http://www.python.org/dev/peps/pep-0249/

    Value Systems

    "The first thing to realize is that it’s easy to swear by a value system, and a different thing to follow it. To see someone’s true colors, you have to observe them when they are forced to compromise. Even the most morally bankrupt individual will adhere to “you shall not steal” if he’s alone on an island. Without a forbidden fruit there will never be a test of will, and you will never know what the person’s made of."
    ...

    "On the inverse, companies that lack or have inconsistent value systems often have an incredibly difficult time executing well, no matter what engineering, sales or marketing skills they have. Because they disagree on what is good and bad, and right and wrong."

    Source


    Towards Good Programming Style in C
    Major takeaways on variable:


    • Use good variable names, with camelCasing or under_scores

    • Describe variables at declaration


    Major takeaways on documentation:

    • Document every subroutine with a block comment

    • For longer programs describe the entire program, including purpose, requirements, missing (required) features, known bugs, etc.


    Lastly, the golden rule of style:


    Style Principle
    Structure and document your program the way you wish other programmers would.


    Saturday, October 8, 2011

    Be true to yourself

    Truth -> Independent thinking -> Conflict -> Innovation.

    First and foremost, you have to be true to yourself, and be confident in your reasoning.

    Second, because what is true to you is not always transparent, you must focus on communicating this truth.

    Independence

    “Don’t be trapped by dogma—which is living with the results of other people’s thinking.”

    -Steve Jobs, Stanford Commencement 2005

    Do the right thing

    “When you want to do pension reform for the prison guards,” he says, “and all of a sudden the Republicans are all lined up against you. It was really incredible, and it happened over and over: people would say to me, ‘Yes, this is the best idea! I would love to vote for it! But if I vote for it some interest group is going to be angry with me, so I won’t do it.’ I couldn’t believe people could actually say that. You have soldiers dying in Iraq and Afghanistan, and they didn’t want to risk their political lives by doing the right thing.”

    -Arnold Schwarzenegger, interview by Michael Lewis

    Source: Vanity Fair

    Friday, October 7, 2011

    Article source Reproduced below.

    tl;dr

    Find a mentor and track metrics
    Don't over fundraise
    Find a partner to complement you (techie or non-techie)
    Care about your impact
    Everyone overestimates their market



    The start up genome Report -interesting findings
    After interviewing 650 early Internet startups a group of incredibly smart people based on empirical information summarize what makes a successful internet startup

    1.Founders that learn are more successful-Startups that have helpful mentors, track metrics effectively, and learn from startup thought leaders raise7x more money and have 3.5x better user growth.

    2. Startups that pivot once or twice times raise 2.5x more money have 3.6xbetter user growth, and are 52% less likely to scale prematurely than startups that pivot more than 2 times or not at all.

    3. Many investors invest 2-3x more capital than necessary in startups that haven’t reached problem solution fit yet. They also over-invest in solo founder sand founding teams without technical cofounders despite indicators that show that these teams have a much lower probability of success.

    4. Investors who provide hands-on help have little or no effect on the company's operational performance.But the right mentors significantly influence a company’s performance and ability to raise money. (However, this does not mean that investors don’t have a significant effect on valuations and M&A)

    5. Solo founders take 3.6x longer to reach scale stage compared to a founding team of 2 and they are 2.3x less likely to pivot.

    6. Business-heavy founding teams are 6.2x more likely to successfully scale with sales driven startups than with product centric startups.

    7. Technical-heavy founding teams are 3.3x more likely to successfully scale with product-centric startups with no network effects than with product-centric startups that have network effects.

    8. Balanced teams with one technical founder and one business founder raise 30% more money , have 2.9x more user growth and are 19% less likely to scale prematurely than technical or business-heavy founding teams.

    9. Most successful founders are driven by impact rather than experience or money.

    10. Founders overestimate the value of IP before product market fit by 255%.

    11. Startups need 2-3 times longer to validate their market than most founders expect. This underestimation creates the pressure to scale prematurely
    .
    12. Startups that haven’t raised money over-estimate their market size by 100x and often misinterpret their market as new.

    13. Premature scaling is the most common reason for startups to perform worse. They tend to lose the battle early on by getting ahead of themselves.

    14.B2C vs. B2B is not a meaningful segmentation of Internet startups anymore because the Internet has changed the rules of business


    Noam Zur

    Sales Mentor - Customer development for startups
    4 months ago

    Thursday, October 6, 2011

    Truth

    Steve Jobs passed away today. It's funny how one person can impact so many lives.

    Today is 8302 of my life, I believe. Soon, I will be a 10,000 day old person.

    For most of life you need partnerships. But to find your own truth and following your heart, as Steve Jobs put it, you must look within. He was a hustler. He made things the way they are. Because he believed enough in his heart.

    Wednesday, October 5, 2011

    Racial humor

    Telling racial jokes is kind of like drinking for the first time.

    It's hard to know when to stop.

    Monday, October 3, 2011

    Day 8299

    Enjoying my time with David. Stayed up the last 36 hours, most of which was spent on a Lab for my networking class. I liked it, although I'll crash soon..

    Going to do Algo Homework and sleep. Today I hung out with Jim for a bit, then Simon for dinner, and David for post dinner beer and chill. Listening to Starry Starry Night by Don McLean...

    Want to put down this link so I don't forget it, just some intermediate python work.

    http://www.rexx.com/~dkuhlman/python_201/python_201.html

    David's wisdom to me yesterday... "The red herring is purpose"

    It's catching...

    Sunday, October 2, 2011

    Algorithms + Data Structures = Programs

    On my to read list.

    Yeah but...

    I've noticed that I need a second opinion to make a lot of decisions lately. So, that really puts me at the whims of whatever suggestion floats by. Always, when someone offers a suggestion, you have to do your own optimization. Tell yourself "That's interesting, but..." And try to think of things objectively.

    Happy planning =D

    Thursday, September 29, 2011

    Day 8295

    Making Better Decisions


    I can trace all my problems back to a decision I made while tired and unfocused. This is exactly what former-President Clinton talked about before.

    “In my long political career, most of the mistakes I made, I made when I was too tired, because I tried too hard and worked too hard,” he told Rao. “You make better decisions when you're not too tired. So that would be my only advice.”[1]

    That isn't a call not too forgo sleep once in a while to work hard. It means you should be rested when making important decisions. Unfortunately, you make important decisions in your life every day. I have no solution to that. I will say, though, that this applies all the way, to my relationships when I've going through rough times, to the ebay seller I said I would buy from. Before you pull a trigger, catch some shut-eye.

    At the very least, it'll save you a bullet.

    [1] Source: Sleep Eduction Blog

    Tuesday, September 27, 2011

    Day: 8293

    Negotiation: Because you're worth it


    Before signing my contract for some part-time work while I do my M.S., I called for a wage increase. Comparable TA and RA positions pay tuition plus a stipend that comes out to $40 per hour, presumably non-taxed. Since I was getting slightly under that before taxes, I tried to make things work.
    The person on the other end asked for a number. I recalculated to be 40 after tax, but it came out to be 50. Which was a bit of a jump for her. In retrospect, I should have gotten her "number". However, I let her get back to me. A few tactics would be better:
    • Presenting your BATNA in clear comparable terms. Here it was $80/hour, but I presented it as "XX wage, plus a stipend"
    • Getting information in return for information. Don't walk away without some idea what they want.
    • Clarity. Work together, without timidness, but directness. Everyone will benefit as a result

    Anyway, ended up with a pinch of an increase. I'm glad I asked, for the practice.

    Simplicity


    Too many things in our lives. Too meta. Look at the path, and look for the shortest path. Then the clearest path. So that soon you see nothing but your goal. My goal: To solve social problems with technology, and technical problems with society, and then receive recognition for it.

    First day as a Grad Student

    How do you feel about this?

    In my last few years, it's hard to tell what I've learned. Just a bunch of facts, but nothing amazing conceptually. From now on, I plan on reflecting upon/ remembering what I learn each day; what I learn each week; each quarter; each year. The key lies with actually learning something, conceptually speaking -- not just facts, although those are good too.

    Today I learned a bit about machine learning:

    • Supervised Learning -- train an algorithm with data, which consists of "inputs" and "outputs"

      • Regression analysis used with continuous variables

      • Classification used with discrete variables

    • Learning Theory -- the theory of machine learning

    • Unsupervised learning -- using an algorithm to identify "groups" of variables, without prior training or criteria

    • Reinforcement learning -- identifying "good" and "bad" behavior, allowing the machine to adapt

    Thursday, September 22, 2011

    MSCS Orientation

    There's Stanford. Then there's the computer science at Stanford. Then there's the graduate computer science programme at Stanford.

    See, what you have now is the Nerdiness3. And then there's orientation, where these fine souls come together. At our luncheon table, we had a nail-biting, hard-glaring, strongly-opinionated Jewish nerd on my right; on my left, there was my roommate, the friendly, well-spoken, positive, humorous American fellow; and on his left, quiet, subdued, Indian from Dehli.

    I can only imagine how everyone would classify me. But there you have it. Some of the finest computer scientists in the world (minus myself).

    Tomorrow, we get to meet Google nerds...

    Wednesday, September 14, 2011

    How I handle VBA

    How to handle any task in VBA:

    1. Open up 30 google search tabs like: "how to " + QUERY + " VBA?"

    2. Profit.

    Monday, September 12, 2011

    Change the date on your computer

    Some dangerous lack of soft modularity in VBA.

    Forgetting that Date was a datatype, I went ahead and used this little code in VBA for an excel app.


    Date = Now()
    countdown = Date - 20
    ...
    Date = Date - 20


    I started getting inconsistent values for Date every time I ran the program, and realized Date was actually decreasing over time. I checked my system clock and was fooled at first since the system date (on the Windows toolbar) matched the same date as Date.

    Didn't take a while to realize that the system clock was wrong too!

    So I suppose I was changing the value of Now(), Date, and the system date itself by modifying it! ridiculous!

    To fix this, I just added back the missing days to the Date variable.

    Bloomberg calls

    How do you handle Bloomberg XLS values that aren't complete?


    Sub Something()

    If Application.WorksheetFunction.CountIf(Range(Cells(5, 5), Cells(lastRow, 8)), "#N/A Requesting Data...") > 0 Then
    Application.OnTime Now + TimeValue("00:00:30"), "Something"
    Exit Sub
    End If

    End Sub



    The code as is keeps delaying until all values specified are done loading from Bloomberg.

    Source: Bloomberg API best practices

    Sunday, September 11, 2011

    How bad do you want it?

    Sitting outside with HC. It was his last day in SF. We decided to go on a fast food binge -- one his favorite things to do. With an hour left to kill before had to head out on the bart to SFO back to Chicago, we decided to drink some brews on market. Finding a 6-pack of.. (what, exactly?) for 3 bucks, we drained the first while waxing philosophical.

    Our thoughts kept returning to -- How Bad Do You Want It?.

    How bad do you want it?

    How bad do these coders on cocaine want it? How bad do these super ambitious bankers want it?

    Am I lucky enough? Am I good enough?

    Only one way to find out.

    Saturday, September 10, 2011

    JW's advice

    JW told me to write this down (as accurate as I can be):

    You're 22 right now. You don't want to be married for another 10 years at least. Marrying early is right for some people. But remember, I told you, don't marry early. And I know in ten years you will not have listened and I will punch you in the face for not doing so. But also, never do something you'll regret. If she's the right one, well then...

    Thursday, September 8, 2011

    One year challenge

    JC said:

    "It's like something clicked
    one year to excise the bulls***tery from my life
    i challenge you to the same"

    Thursday, September 1, 2011

    Copy and paste from remote desktop

    This trick is for windows, mind you.

    Since I was remoting into a Windows 7 machine from an XP, I had to do this trick on my older XP and then disconnect. When I reconnected (make sure you have the "Clipboard" option selected) everything worked fine.


    Follow the following instruction in both local and remote computers.

    Go to Start->Control Panel->Administrative Tools->Services. Enable and start the following services in the order shown below:

    1. Network DDE DSDM 2. Network DDE 3. ClipBook

    If you want to see the clipboard action in live:

    You can go to Start->Run and type clipbrd and click OK to run clip board viewer. You will be shown current clipboard objects in this viewer.

    Now you can use standard copy/paste menu options of the applications in both the computers to exchange the data.


    Wednesday, August 31, 2011

    What I've learned...

    Any fool can make a task harder.

    Prayer to action

    Based off the triplet found in Reinhold Neibuhr's Serenity Prayer:

    Prayer to action

    God, grant me the clarity to see,
    the boldness to walk,
    and the discipline to stay the right path.

    Tuesday, August 30, 2011

    4 stages of competence

    Condensed, from Wikipedia here:

    The Four Stages

    Unconscious Incompetence
    You don't know you suck.

    Conscious Incompetence
    You know you suck, but also where you suck. (I.e., where to improve).

    Conscious Competence
    You've got something going, but it takes an aneurism and a half to get things done right.

    Unconscious Competence
    You're awesomeness is practically in autodrive.

    Monday, August 29, 2011

    Ggplot2 Panels

    I've been trying to use R to print out columns of data each in their own panel form for some time now. They all use the same time frame, of course, so I wanted to arrange by X-axis.

    ggplot2 has a "facet" grammar you can use to plot different aspects of your data in a meaningful way -- i.e., different parts of an observation. The trick is to contort your data with the "melt" function, which will create two new variables per observation.

    The first variable is the name of one of the columns.
    The second variable is the value that corresponds to said variable.

    I tried taking a peek at the data length -- observations should increase by a factor equal to the number of columns you are melting, i.e. if I'm melting by 3 variables


    >>> data = melt(factor.data, measure.vars=c("variable_one", "variable_two", "variable_three"))
    >>> length(factor.data$val)
    85
    >>> length(melted.data$val)
    340


    The data length increases by 3. But of course.

    Here's the code I'm using to format, melt, plot, and save the data to pdf:


    process.open <- function(filename) {
    return(read.csv(file=filename, head=TRUE, sep=",", dec="."))
    }

    filename <- "z1_output_quint.csv"
    output <- "z1_output_quint_panel.pdf"

    factor.data <- process.open(filename)
    factor.data$date <- as.Date(as.character(factor.data$date), format="%Y%m%d")
    factor.data$val <- factor.data$value
    factor.data$value <- NULL

    vars = c("val", "momentum", "size")
    vars_2 = c("dividend_yield", "profitability", "growth")
    vars_3 = c("earnings_variability", "trading_activity", "volatility", "leverage")

    pdf(output)
    data = melt(factor.data, measure.vars=vars)
    ggplot(data, aes(date)) + geom_hline(yintercept=0)+
    geom_line(aes(y=value))+
    facet_grid(variable ~ .)

    data = melt(factor.data, measure.vars=vars_2)
    ggplot(data, aes(date)) + geom_hline(yintercept=0)+
    geom_line(aes(y=value))+
    facet_grid(variable ~ .)

    data = melt(factor.data, measure.vars=vars_3)
    ggplot(data, aes(date)) + geom_hline(yintercept=0)+
    geom_line(aes(y=value))+
    facet_grid(variable ~ .)

    dev.off()

    Sunday, August 28, 2011

    Extend vs Append

    Could be useful.


    >>> x = [1,2,3]
    >>> y = [4,5,6]
    >>> x.append(y)
    >>> x
    [1, 2, 3, [4, 5, 6]]
    >>> x.remove(y)
    >>> x
    [1, 2, 3]
    >>> x.extend(y)
    >>> x
    [1, 2, 3, 4, 5, 6]
    >>>

    Friday, August 26, 2011

    Words from a Quant

    The head of Director of Quantitative Research at my firm offered wonderful advice on understanding macro trends in finance:

    1) A strong (formal) economic background
    2) Great market experience
    3) Patience and intelligence

    One thing I asked him about was physical fitness and rest. He said because of the high level of concentrated study, adequate sleep and physical training (he did weightlifting) was necessary. I will take these words to heart when I go to study for my MSCS next year.

    As an added bonus, he said that being the opposite of "scatter-brained" was one of the important qualities of a Ph.D. candidate. I think it is definitely something for a short-attention-span person like me to think about.

    Thursday, August 25, 2011

    A stitch in time

    Saves nine.

    Was chasing down a bug in my factor model for a week. Went through a lot of stuff.

    I decided to look at one day that seemed out of wack. Surely, if this simple calculation was wrong, it must be the data. Otherwise, I would have to keep looking in my own code.

    Surprise surprise, the period i was looking at did not match up with my expectations. When I inspected the FactSet code with the resident quant, I instantly saw the problem...

    Was using P_TOTAL_RETURNC(0/0/-2,0/0/-1) rather than P_TOTAL_RETURNC(0/-2/0,0/-1/0)

    I was grabbing yearly returns, instead of monthly!!!

    Lesson: Be more thorough, use methods to narrow in on the problem.

    Wednesday, August 24, 2011

    Unit Tests and Python floats

    I realized my downfall with using Python's easy dynamic typing: unit tests.

    Since I use ints to simplify things, I forget that special "." that makes 1./3 different from 1/3 (hint: the difference is a third)

    Which really means, remember to use . anytime you don't specifically mean an integer!


    class TestNormalizeFunction(unittest.TestCase):
    def setUp(self):
    ## Setup for weight test
    self.dateList2 = [1,1,1,2,2,2]
    self.countryList2 = ["us","us","mx","us","us","mx"]
    self.list2 = [1.,3.,3.,1.,3.,3.] ## <--- NOT THE SAME AS [1,3,3,1,3,3]!

    def test_weights (self):
    self.assertEqual(process.calculateWeights(
    self.dateList2, self.countryList2, self.list2),
    [self.list2[0] / sum(self.list2[:2]),
    self.list2[1] / sum(self.list2[:2]),
    1.,
    self.list2[3] / sum(self.list2[3:5]),
    self.list2[4] / sum(self.list2[3:5]),
    1.])

    if __name__ == "__main__":
    unittest.main()

    Monday, August 22, 2011

    The Basel Multiplier

    Chebyshev's Inequality says:
    Chebyshev's inequality

    Suppose we wanted the highest VaR at the 99 percent confidence level.

    That means, only 1 percent of samples taken should have VaR that exceed this level. Without making any assumptions about the distribution, Chebyshev's inequality says that we can expect K = 10 at the 1% tail end.

    Granted, that's pretty big, but if we assume the distribution is symmetric then we can divide the righthand of the equation by half and the new k becomes about 7.

    So if a financial institution had assumed a normal distribution, the k value for which VaR is not exceeded with 99% confidence is closer to 2.36. Dividing our earlier k (=7) by this k value, we get ~3. Thus the correction multiplier is about 3.


    Example taken from Jorion

    Tail events

    There are two ways to measure VaR (Value at Risk):
    • Finding quantiles using empirical data
    • Matching a parametric distribution to data
    ETL (Expected Tail Loss) takes averages of the tail value at risk to provide better perspective for tail risk outcomes.

    There are still drawbacks to using empirical data.
    "The most powerful statistical techniques cannot make short histories reveal once-in-a-lifetime events." (Jorion, Chapter 5)
    For this, we move on to Stress Testing.