07/18/2016 – Sentiments!

For someone like me who’s always been interested in practical machine learning, it was wonderfully delightful to have found Word2vec, a neural network that intakes text and outputs numerical vectors. It transforms each word in a sentence into a series of numbers that could be used to predict the probabilities of related items, on top of mathematical interpretations of similar words. This means that this method doesn’t need to know the exact definition of the words, and with enough data could better interpret relationships between words than the average human being.

Of course, that’s not all Word2vec could do. It seems that the applicability of the Word2vec (there are 2 distinct models) goes beyond predictive syntax interpretations.

If you’re interested in learning more about the Word2vec and its intricacies, check out:

  1. This document published by an Israelian computer science PhD (with a link to the PDF).
  2. A publication by the guys at GOOG on sentence and phrase compositions.
Advertisements

07/07/2016 – Basics

When one reaches an advanced stage of professional practice it’s easy to forget the basics because they are no longer needed or have already been done by entry analysts for you. Although it’s not crucial that one should retain everything, it’s quite useful to reacquaint oneself with the fundamentals from time to time.

Here are some of the finance books I’ve been flipping through recently:

  1. Finance, by David Whitehurst – this textbook contains decent summary of capital risk, structure, financing methodologies, and some derivatives. It also includes some elementary financial planning and mergers&acquisitions which doesn’t have much substance but good as a light read on industry expectations.
  2. Introduction to the Economics and Mathematics of Financial Markets, by Jaksa Cvitanic and Fernando Zapatero – you have to expect some hardcore materials when one of the authors’ last name sounds Eastern European, and I’m expectantly trudging through it at a slower pace than the other books. Luckily I’ve encountered a lot of its notations when I was studying for actuarial exams so it’s been making it a bit easier to read. It touches on mainly portfolio modeling techniques, asset pricing, risk mitigation, and a bit on probability theory. The book dedicates two chapters exclusively for fixed income hedging and option pricing, signifying the amount of past research done for these two fields.
  3. Finance, by Zvi Bodie and Robert C. Merton – aha! Written by one of the Nobel Laureates who revolutionized the options pricing world and also crashed the world markets with the same idea, this book is surprisingly light in terms of difficulty…if it were in English. I’m reading this in Chinese (yes!) to A) get a deeper understanding on modern finance theory, and B) improve my Chinese. So far I’m checking google translate every 2 to 3 pages which is not too bad considering I haven’t yet used it in any professional capacity. The book actually doesn’t go too much into theories but looks at the markets as a whole from both a quantitative and qualitative perspective. The book looks at the evolution of financial markets, then delves deeper into its various components such as accounting, investing time frames, and valuation models. It’s one of the classic reads so I’d recommend it if you are interested in the topic (and perhaps read it in a language you are more adept in).

My GRE is coming up soon and I’m debating whether I should write the GMAT instead, dilemmas!

06/05/2016 – Path to CFA: Level 1, Part 3

Life definitely passes in a blink of an eye when you’re busy. Like 1000s of others, I’ve written one of the world-acclaimed CFA exams yesterday, finally done (so far)! I’ll first give a quick summary of my thoughts on the exam in general and the exam taking experience, then I’ll give some general tips for studying for the L1 exam if I (god forbid) have to take it again, I’ll finish off with some curious thoughts about the CFA in general because I’m still tired 🙂

The CFA L1 Exam in General

The entire CFA L1 curriculum, if I have to put it on a difficulty scale between 1 to 10, would rate as a 5. Don’t get me wrong, the exam wasn’t easy, but what the materials lack in difficulty, they make up for in the volume of information. I started studying in mid-January thinking I could finish all the materials by mid-April, but due to work and other commitments I didn’t finish all the materials until the beginning of May, which gave me about 3 weeks to do practice exams.

Now this sounds like it’s plenty of time, but due to the length of study time, I’ve forgotten most of what I’ve studied in the beginning, and it was a nightmare because I chose to study Accounting and Financial Statements first to get the difficult stuff out of the way. So I ended up using about a week to re-learn the material, then spent one week doing practice exams before bleeding out 1 practice exam in the final week due to work commitments.

Exam Taking Experience

I picked up my friend who was also writing the exam and headed off to the Toronto Congress Center, I thought I was early at 7:10am but hell no, plenty of people have already set up their stuff and looking dead serious. We relaxed by waiting in a giant line at Tim Hortons… wait you don’t care about that? Suck it up and pretend you’re interested, please. Just kidding, here goes the actual account.

I generally cruised through both morning and afternoon session, not because it was easy, but because they are generally straightforward and you simply know the material or you don’t. If I had to pick one the afternoon session would be the harder of the two, or maybe I felt that way due to sleeping only 6 hours the night before. The accounting portion was muddy to go through as usual, and the other portions giving me trouble was fixed income and economics.

I almost passed out in the second hour of the afternoon session, and pretty much slept for about 10-15 minutes before continuing the exam. It’s known that you shouldn’t eat too much at lunch, but apparently too little is bad for you too, who knew eh?

One thing I would note is the seriousness of the person reading the instructions for the exam, including the mandatory ethical behavioral pledge we all had to sign. From her tone it sounded like offenders will be stabbed by pitchforks in a reddish and hot environment. Ok, she did wish us good luck on our exams so it’s not too bad.

General Tips

Overall, the exam material was quite straightforward, the exam committee however, is quite devious as they enjoy creating questions that are tricky mostly in the way they’re asked. This is especially prevalent in Ethics, where you are required to get an excellent score else face failure (even if you scored perfect in all other sections). General tips for studying the L1 is:

  1. Start early – material isn’t sky high difficult, but it’ll bury you in information overload if you don’t already know most of the material
  2. Study Accounting before Ethics, and study Ethics last – these two sections are important and weigh a ton on the exam, studying those last allows the materials to remain fresh in your mind and would require less ‘re-studying’ when you’re trying to memorize the rules (learning it is counter-intuitive as real life work experience will instantly crush ‘what you learned’)
  3. Actually stick to the study schedule – this might be a no-brainer, it’s easy to get lazy because you’re tired or unmotivated, but studying anything – even a small portion of a chapter – would help as it’ll keep the materials fresh in your mind
  4. Physical exercise – you need those endorphins to keep you going (also for giving you something else to depend on other than your DHV stories when wooing the ladies)
  5. Relax the day before your exam – you’ve studied hard, last minute studying will scramble your entire thought pattern and impression of the exam testing experience, do anything except study, but reading Ethics in general is fine
  6. Get a personal driver, or a friend/family drive you to/from the exam venue – this is optional. I tested in Toronto so this might not apply to you. In general you need it when you’re getting out the zombie horde of a parking lot, plenty of horrible drivers so keep yourself sane and cool by having another person driving you home (or a lobster eating party) after your exam

 

Random Thoughts

It’d be interesting to find out if the exam content is the same from country to country (theoretically it should be), because some really smart Asian kid who just took it 12 hours earlier could memorize most if not all of the exam answers and sell them to the highest bidders in North America. I tried to find the dates of which the CFA Institute held the exams in Asia but couldn’t find any. Of course, the smart CFA charter-holders may have already thought about this and created contingencies for it, why else would we sign a candidate pledge at the beginning of each of the exam sessions?

 

 

Congratulations to all those who’s been studying all these months for the CFA exams, you survived and deserve a break! Time to make up to your friends and family whom you’ve neglected.

03/09/2016 – Efficient SQL

What is efficiency?

That’s the question that plagued me when I stared blankly into a log telling me it spent an abysmal amount of time running a few simple queries.

Usually, I run a few SAS queries before I leave work so that I can look at results as soon I arrive in the morning. I was running a total of 5 months worth of financial product performance information, split into 5 different tables. There wasn’t a lot of information so the expected run time was about 10 minutes per table. Hence I was flabbergasted when the log told me it took 1 hour 28 minutes to run each month of data.

Long story short, after playing it around with it some more I decided to condense 5 queries into a single SQL query and ran it again. Guess how long it took this time?

5 minutes 28 seconds.

1236% increase in efficiency.

SQL_runtime

I think I’ll be able to go home early today.

02/29/2015 – Path to CFA: Level 1, PART 2

One might guess by the lack of posts that I’ve been hard at work studying for my CFA, for the most part, that is true. Being bogged down in administrative responsibilities isn’t fun, but definitely part of an adulthood that I’m becoming more comfortable with everyday (for example, cleaning up after the cat).

So far I’m a little behind schedule, I’m supposed to have finished Accounting, Economics, and Equity sections, with Corporate Finance/Portfolio Management deadline coming up soon. The accounting section took longer than expected due to extra time spent on understanding taxes and its many connections to other financial statements. I can see why people don’t like studying taxes, but it’s a necessary component of our financial system that keeps it alive; they just need to make learning it a bit more sexy.

I’m almost done with Economics, and luckily most of the materials are quite intuitive and relatively easy to understand. Its “hardcore” mathematics section is relatively straightforward, the difficult part is sifting out the irrelevant portions of economic mathematics (which there is a lot of).

One thing that struck me as a CFA characteristic is its sheer volume of information. The material isn’t difficult, but takes great discipline to go through this much material within a short time frame. This is more of a test of personality than intellect (at least, for Level 1). It reminds me of the premise for the movie Limitless (2011) featuring Bradley Cooper, where the main character (Cooper) became a genius through the use of drugs but underwent a painful recovery after forgoing sleep and food regularly (side effect of the drug). Now if I could only get my hands on some of that stuff 😉

I intend to complete the Economics module by the end of this week. Then move on to the rest of the course, where it would be covered in a faster pace since the bulwark of the course material would be behind me.

Currently experiencing on and off recovery from a minor cold, but expecting some alleviations from the warm Canadian weather this week.

 

01/10/2016 – Overtime

When I was working at an actuarial consulting firm, there is no real concept of working ‘overtime’ since everyone is more or less working the same hours (translation: work on it until it is completed). This instilled a culture of intense focus and tendency to stay at the office until you’ve done enough to satisfy yourself or the client/boss. One of my wiser colleagues told me that “there is always a tomorrow”, which is a philosophy I begun to adopt towards long term projects and goals.

Naturally, the next question to ask is, what if there is no tomorrow (Rocky III!)? What if today is the day before that project (that you’ve been working on for so long) gets axed, being fired from that job (you enjoy), or separating with a loved one? Sometimes it’s a force of will to move on and return to the fray.

Perhaps instead of being rushed for the future, cherish the current moment, because you never know when there might not be a tomorrow.

Including that overtime you might be doing right now.

01/06/2015 – Path to CFA: Level 1, Part 1

Late last year I decided to study for the Chartered Financial Analyst (CFA) designation, so despite the unfavorable CDN/USD exchange rate I signed up for the early bird June 2016 sitting of the CFA Level 1 examination. It still cost me almost 40% higher in exchange rates.

My study plan is roughly as follows:

  1. 01/09/2016 – 01/23/2016: Financial Reporting & Analysis
  2. 01/23/2016 – 02/13/2016: Economics
  3. 02/13/2016 – 02/20/2016: Equity
  4. 02/20/2016 – 03/05/2016: Corporate Finance & Portfolio Management
  5. 03/05/2016 – 03/12/2016: Derivatives
  6. 03/12/2016 – 03/19/2016: Practice Questions
  7. 03/19/2016 – 04/02/2016: Fixed Income and Derivatives
  8. 04/02/2016 – 04/16/2016: Alternative Investments and Ethics
  9. 04/16/2016 – 05/30/2016: Practice questions (includes reviewing more important topics)
  10. 05/30/2016 – Test Date: Review and rest

The schedule looks extremely packed, but having studied roughly 30% of the exam material already in my previous studies it shouldn’t be too difficult to follow. I’ll spend roughly 6 days a week studying the material, and the final day as a day for review and rest. The strategy is to go through the majority of the materials, taking notes on material relevant to the Learning Outcomes Statements (LOS) of each chapter. Then work on a large number of practice questions and reviewing the material. Someone suggested studying for Ethics last because it’s the seal that puts together all the other topics together, hence I put it after Alternative Investments. I should have roughly 1.5 months of practice time before my test date, which should be more than enough based on what I’ve seen.

To deal with the boredom of long term studying I’ll be regularly summarizing here the basics of what I’ve learned and my personal experiences in dealing with the more difficult topics, although from what I’ve researched none of the material would be too difficult until CFA Level 2. It’ll be a nice way to review the study material as well as checking how well I’m following my own study schedule.

12/30/2015 – Schopenhauer

These days my cooking music has turned from rap/classical to YouTube audio stories, I find it to be an excellent way to keep my mind stimulated while mindlessly cutting vegetables or making mashed potatoes.

One of the more interesting figures that I’ve learned about recently is the ideas of the 19th century German philosopher Arthur Schopenhauer, who suggested that the way to approach to life should be similar to Buddhist monks (known for his famous work The World as Will and Representation). Born in Germany in 1788 to wealthy parents, Schopenhauer studied the work of many prominent philosophers and began his famous work at the age of 26 (and finished it at age 31). I will (try to) summarize his ideas below in less than 250 words.

Schopenhauer believes there is a primal force called “will-to-life” within us (wile zum leben in German) that overcomes our logic reasoning and causes us to think, amongst other wasteful things, sex and love. Schopenhauer is more forgiving of the latter since he believes that love offers a logical goal, which is to conceive children. He argues that although people who opposite traits tend to fall in love with one another, they would actually make terrible friends and, apart from sex, would hate each others’ guts. Schopenhauer makes a comparison of humans to moles, which does its best to survive despite dismal living conditions (note that Schopenhauer considers living underground from a human’s perspective, and not the moles. Moles might love it there.).

In general, the “will-to-life” drives humans away from our “higher” logical self by wasting it on carnal pleasures and instincts, often reflecting regrettably over its aftermath. Schopenhauer believes that elder individuals’ faces are full of wrinkles because they are vastly disappointed that they have failed at the pursuit of happiness (on a side note, check out this old classic if you are interested in the stock market). Schopenhauer proposes two solutions:

  1. Emulate the actions of Eastern Buddhist monks – living in isolation, overcome one’s instincts, and never marry. Schopenhauer recognizes the difficulty of the average person overcoming such a thing and thus recommends highly the next solution,
  2. Immerse oneself in Arts and Philosophy – the objective is for it to act as a guide of continuous self-awareness to one’s actions, thus being able to look at oneself from an objective perspective and avoid the pitfall of being driven by the “will-to-life”.

Schopenhauer is an interesting character and it’s one of the philosophers that were eclipsed by the other ones I’ve studied in university. I admire him for recognizing the serene practicalities within the mysterious Eastern philosophy and being able to adapt it for the much more practical Western civilization. His comments on the misery of human life were sobering yet comical and witty, and although he didn’t end up being rich or famous, he found an audience for his work and died peacefully in 1860.

In my opinion, Schopenhauer’s approach to life is very conservative, his disdain for “will-to-life” may have held him back from doing certain things which would have made him more financially successful (but who knows what his definition of success was) or more popular (maybe fame isn’t the name of his game). However, his ideas are excellent in today’s hectic world and there is no doubt that a healthy dose of Schopenhaurism would bring a much needed break from our modern, fast-paced lifestyles.

It’s the last day of 2015 tomorrow, I’m expecting a fairly empty office and a shorter day tomorrow.

12/29/2015 – Investing

I’ve always read multiple books at the same time to prevent mental stagnation. Recently I have been reading two market related ones, The Intelligent Investor by Benjamin Graham and The New Market Wizards by Jack D. Schwagner. Both are great books and sheds light on different aspects of the market, the former is about how to intelligent allocate your capital for long term investing, and the latter is a summary of interviews with some of the top performing traders at the time of publishing (1992).

The biggest thing that both books agree on (with regards to how much I’ve read so far) seem to be that:
1) No one can consistently predict the stock market, and
2) Humans are ill-suited to handle themselves in the stock market

It’s important to note that The Intelligent Investor is a book that could benefit both investors/traders, and appeals to a large range of market participants. The Market Wizards series is great but it feels like Schwagner picked a biased subset of the trading world, or according to Nassim Taleb (author of the popular book The Black Swan), they were lucky. Alternatively, it could just mean that most people are too emotional to trade. This is an interesting phenomenon that has spawned countless behavioural finance courses and psychology studies.

I’ve been trading the stock market for fun since early 2013 with a small amount of capital (for me at that time), and during my short stint with the stock market I’ve always questioned whether it is better to invest for the long run or rack up a series of winning trades using leverage and options over a much shorter period of time. As a consequence my strategies were inconsistent and I wasn’t able to produce consistent wins. Due to the recent oil crisis my commodity related options were crushed and brought me to a point where I need to re-evaluate my goals or face eventual annihilation of my trading net worth. Luckily these options only consist of 20% of my high risk capital so much of my trading portfolio is still intact.

I’m currently educating myself on trading indicators so I could make more accurate directional assessments, with the eventual goal of building a probability based trading system with buy/sell signals. This process has been an interesting one, as much of the indicators use a combination of mathematics that feels quite artificial and closer to a computer programming experience than statistics or abstract mathematics. I will update any research efforts as they become available.

12/29/2015 – Wait Time

Running an advanced algorithm in SAS takes a long time, just came back from lunch and the query is still running. Life is a game of patience and frankly by the time it finishes running I’d be fossilized. To be fair, my lunch lasted less than half an hour so it probably isn’t a giant query like the one I wrote a few months a go (which took 50min).

Most of the issues with time comes from joining giant tables, I tried adjusting the algorithms to make it more efficient like reducing the joining data set, adding as much action into each query as I could so there’d be less computation in the next one, and writing macros so that there’d be less . However it seems that code efficiency does not mean computation efficiency.

There may be a few things causing this problem:

  1. Macros are actually slowing things down: since I’m joining huge datasets they are running through them again and again, there is no way to avoid this issue since I need to obtain the same information for different risk levels from the same tables. A possible cure is run the programs through a subset of the original database.
  2. Too many actions in one query: after a bit of Googling I found that this isn’t a problem, it’s actually beneficial to combine different actions into one query. That is one myth busted.
  3. Crummy coding: this is a little unlikely since I’m writing SQL code and they’re quite similar across the board as I’m merely extracting data at this point for exploratory analyses, perhaps I could throw them into separate queries and see how long they take individually.
  4. Conflicting computation requirements: it seems that I’m not the only one not taking vacations a few days after Christmas and before New Years. Plus there’s a minor issue that is currently on the hot seat with another team so they’re requesting a lot of support from the data analysts who operate within and out of the SAS systems. Again, no way out of this one but patience.

I could only potentially improve on 1/4 of the issues described above (#3), so it wouldn’t produce much improvement in processing speed at all. I might spend some time reviewing the loess method I implemented last week, this interesting regression method has yielded some interesting insights regarding some of our products. So far I’ve only been interpreting them visually, so there could be additional information that I could uncover once I (re)learn how to interpret the coefficients.

 

Update: I was able to get the run time to decrease by almost half after using the function <compress=yes> and joining tables using unique accounts to reduce the size of every table created. It turns out that one of the tables had 251 million rows of data, when I tried to join it with another table the information multiplied and thus overwhelmed the system. The new program took about 50 minutes in total for all the risk levels I tested, which is a drastic improvement.