Wednesday, December 31, 2014

Infix notation and Live templates



IntelliJ lets you complete code statements in several different ways.
  1. Infix notation.
  1. To create a loop that goes over each variable, try typing the variable name, a .fori. It should expand into a for loop that creates an index.
  2. To create a loop that creates a foreach, type the variable name and then a .for. It will expand into a foreach loop.
  1. Live templates. Look at Settings -> Live templates.
  1. With these, you can ifn or ifnn and a tab to get if null or if not null constructs.
  2. You can also construct your own.
  1. I added a logging category and set logdecl to private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());, as I had done before, in Eclipse.
  2. You can also add variables. I set logstart to be log.info("Entering $METHOD$.");. Then I pressed the Edit Variable button and told it that the expression to use was a predefined methodName().

Tuesday, December 30, 2014

The H2 database

I installed H2 on my work desktop. I tried to use Spring Data JPA, but ended up making a plain Maven project.

One of the problems that we have in software development is reading and writing information from a database. You don't want to use your regular database for reading, because you'll have to put test data into your regular database. You don't want to use it for writing, because you'll leave your test data on a database.

Enter H2.

The advertising says that I can set it up in memory, load it up with test data in Maven test phase, run my unit tests against it, and then have it all go away when I'm done. 

So far, I have set up a basic in which I start up the H2 database in one window and then run a Java test in my IntelliJ IDE. It's reading the single record from the single table like a champ.

Next step will be to have Maven start up H2, run the test data, and then politely go away. Should be fun.

Modern Portfolio Theory and a regular guy's portfolio

I took a course at UNCC called Statistical Techniques in Finance. There was enough math to make strong men weep, but there was a gem of a section about Modern Portfolio Theory (MPT). A quick search on MPT will tell you that Harry Markowitz got a Nobel Prize for the theory. 

Here's a quote from Wikipedia about MPT:
The fundamental concept behind MPT is that the assets in an investment portfolio should not be selected individually, each on its own merits. Rather, it is important to consider how each asset changes in price relative to how every other asset in the portfolio changes in price.
So I started from a list of assets from Agora Financial (their Focus stocks for 4Q14). I normally have a dilemma in trying to figure out how to buy these stocks: Fixed dollars of each? Fixed percentage of each? Look for the best story? The lowest risk? A high dividend? 

The list, usually about a dozen, is picked by all different money managers with quite different outlooks. By design, some are high-yield stocks, some are pharmaceuticals, some are military, some are undervalued. 

Instead of picking and choosing, I let the math do the work for me. I had Google Finance create a spreadsheet that retrieve the past 520 trading days, had the market return (SPX) as one of the stocks, and then had Excel line up the prices so that they were all the same date. 

Then I ran the correlation function in Excel, which returns a number between 1.0 (perfect correlation) and -1.0 (inversely correlated). In my Focus set, the maximum correlation was 0.27 and the minimum was -0.197.

MPT says that risky, uncorrelated stocks will give you a better return with a lower proportional risk than unrisky, correlated stocks. (By the way, when I say risk, I am referring to the square of the Standard Deviation of the return.)

Then I took the correlations and their log returns and tossed the numbers into Matlab. The program I ran did some optimization of risk to return, using linear programming (a branch of operations research). 

Anyway, here is what Matlab said the optimal weighting would be.

        Ticker      Original weight     name      
        SPX         13.66%              Standard & Poor   
        SE           8.62%              Spectra Energy    
        ICON         8.61%              Iconix    
        RYAM         8.33%              Rayonier      
        AKG         10.97%              Asanko Gold   
        SNMX        11.72%              Senomyx   
        EVER-A       7.99%              Everbank      
        INFI         5.18%              Infinity Pharma   
        NLNK         8.90%              NewLink Genetics      
        SRPT         3.86%              Serepta Therapeutics      
        CRY          7.52%              Cryolife      
        CMRX         4.64%              Chimerix       


The results were surprisingly good. 


Monday, December 29, 2014

UML Class Diagrams, IntelliJ, and automatic code generation

I built a small class diagram with a class and a subclass in IntelliJ. (This capability is found in the Ultimate Edition, but apparently not the (free) Community Edition.)

I added some class fields, constants, methods. Then I created a subclass. I also had the opportunity to refactor the code and pull up some things from the subclass to the parent class.

Then, without fanfare, I press F4 to jump from the diagram to the code. I expected that it would whirr and crank for a bit before it jumped to the code that was yet to be generated, but it generated the skeleton and displayed the code before you could say "Bob's your uncle."

I didn't save the UML diagram, but it was easy to regenerate it.

I also found that I could generate a JUnit or TestNG code by selecting the method and pressing Ctrl-Shift-T (or Navigate => Test).

If you're curious about the details, you may view details on my IntelliJ wiki on GitHub.

Very cool stuff.

Sunday, December 28, 2014

This day and that Day

“There are two days in my calendar: This day and that Day.”
― Martin Luther

Heard this in a sermon this morning. I can't find out where Martin Luther said it, so I will be a little suspect until I find the original. 
I think it means that "this day" is today. I'm not worried about yesterday or the future. 
I think "that Day" refers to the Judgement Day. 
Martin Luther was saying that I need to live today in light of how it will be viewed on Judgement Day.
 

Repurposing the Windy Poplars blog

Yes, that was one long pause between blogs. I talked to my friend, Todd S, about why he wanted to blog about theological issues. I decided that I might want to start blogging to remember things for myself and share things that may or may not be important to you, dear reader.

I realized that I often repeat stories to my friends about what 
  • I've read, 
  • I've learned, or 
  • I've experienced.
Also, sometimes I would draw conclusions from this list. You might (or perhaps might not) benefit from this wisdom (hah!).

Looking forward to 2015, I may end up talking about these topics.


  • What I'm reading
  • Software development
    • Architectural ideas
    • Agile / Extreme programming
    • Design patterns
    • Work at my place of employment
  • Grace abounding 
    • Relationships
    • Redemption Groups
    • Church
    • Theological issues
  • Music in the church
  • What I'm learning in grad school
  • Setting systems for myself
    • Spiritual life
    • Mental life
    • Physical life (esp. food and exercise)
  • Stock trading
    • Thinking of a portfolio return, rather than an individual stock
    • Rotating in and out of weightings
  • Futures trading
    • Working with CFRN
    • Trading Russell and soybeans
    • Gaining repeatability
    • Working towards increasing contracts traded