Friday, May 15, 2020

Code to download intra-day price quotes using Interactive Brokers API into csv files

Some time ago, I was searching the internet for data download of intra-day price quotes of futures contracts and forex.

The best I found was from Interactive Brokers(IBKR) which provided an API for programmers to download the quotes. This is applicable only for IBKR customers who need to write their own code to download the quotes. Not all data is free. Futures, stocks data require paid market data subscription. Forex and index CFDs are free.

I have written python code to download intra-day hourly price quotes of continuous futures contracts, CFDs and forex from Interactive Brokers API as csv files which are convenient for analytics purposes. The csv files can then be uploaded onto charting software like Amibroker which I use personally.

The code has been uploaded onto github.

It should be useful to Interactive Brokers customers who have a programming background. The code can serve as a base for further modifications. It will be difficult for those who have no programming experience.

If someone knows of better alternatives to this data source, please drop a comment on this blog post or drop a message to me at Telegram user hyom448. Thank you.

PS: Regarding leveraged financial instruments such as futures, CFDs, forex, please avoid if you are inexperienced and do have not much interest in financial markets. Better stick to plain vanilla stocks/bonds or better still, stock/bond index ETFs which are non-leveraged, diversified by nature. 

I personally will steer clear of leveraged instruments unless I am confident of having an edge protected by risk management rules.

Sunday, March 22, 2020

Covid-19 market selloff: It's ok to "panic". It's key to survival

Many retail investors have been caught up in the panic selling caused by the Covid-19 virus scare. REITs and local banks are popular among retirees and FF(financial freedom) seekers for their dividends. Several REITs fell 50% within the last 20 days. Naturally, many retail investors will panic sell at recent lows. Last Friday (20Mar2021), some REITs made monstrous gains as much as 20% intraday. Those who panic-sold at recent lows may be having a miserable weekend regretting their bad sell.

During panicky time like now, here are some standard investment advice you hear;
- Our worst enemies are ourselves because of our emotions
- Fear and greed drives humans to buy at the highs and and sell at the lows.
- Panic is bad.
- Be cool as a cucumber. Don't lose your head while others lose theirs.

I can't argue against these standard investment advice. They are standard because they are mostly right but in investment, there is no absolute right. It's not a STEM topic. Based on personal experience, it's ok to "panic". It's why I'm still surviving in the financial markets. The key is to panic early with a sense of proportion. Easy to say, not so easy to execute, though.

My personal favourite proprietary market timing indicator on when to get out as the market gets jittery is the lao-sai(diarrhea) indicator. When I start to shit too many times a day because of a bloody market, I sell and cut my risk exposure to the point when I can resume my normal shitting of once per day. George Soros has similar timing indicator. He gets backache while I shit more often. My shitting has served me well and is key to my survival in the financial markets. If your portfolio is affecting your body and mind, then sell to the point until the risk exposure no longer affects your body and mind.

Some people would say this is proprietary and cannot be copied. I would argue that fear is a basic instinct of human beings. Nature has blessed all of us with this basic fear instinct which is key to survival of the human race. You don't have to copy. It's in all of us. Don't try to suppress your fear by pretending to be a cool cucumber. Use the Force!

Having said that, do try to sell with a sense of proportion. Don't sell until the baby is thrown out with the bathwater. I can't go into specifics here. I don't like to write articles as if I sound like a guru. Frankly speaking, I don't know what the market is going to do tomorrow or which stocks are going to make money with a high level of certainty. When I get fearful, I don't read other people's articles/opinion pieces for assurance. Often, these financial articles are biased. If the writer has a huge position on, he will be bullish and talk up his stocks. If the writer just sold off his position, he will be bearish and talk down stocks. The bias can be subconscious with no ill intention if the writer is not paid. Now, if the writer is paid, I won't say he has ill intention but he has got to do whatever he is paid to do. The paid financial analyst/salesman can wax lyrical on whatever stance he is paid to promote.  In investment, you can always find data to support whatever stance you want to make. If you don't know about the topic, you are a sheep waiting to be fleeced.

So, don't rely on others, especially when it comes to money matters, because there's a lot of hidden agenda. Better rely on yourself. Nobody knows your own unique situation better than yourself.

If I were still an amateur with no systematic process to deal with an unprecedented market sell-off, then what I will do is to get in tune with my own body signals. For example, my lao-sai indicator. Be myself and listen to myself, not others. Use the Force, Luke. It's in all of us.

If you happen to be one of those who panic-sold and the stock you sold one day ago shockingly rise 20% the next day, don't feel bad. I think you did the right thing to survive. If you stay put or even double-down and the stock subsequently crashes another 50%, rest in peace. Nobody knows for sure how the stock will turn out but I would rather be the person who fights and runs away, so that he shall live to fight another day.

In financial markets as in everything else in life, you don't have to win all the time but you damn well have to survive all the time.

Saturday, November 9, 2019

Keeping the mind open. Seeing the good on some unpopular financial products

It is a good habit to keep an open mind and see things from the other side of the fence. When people disagree with you, the value of their information content is higher. It is uncomfortable emotionally, but essential to arrive at the right decisions.

I have been personally affected negatively by insurance agents selling high-commissioned insurance products, financial training courses and Multi-level Marketing (MLM). It is hard to keep an open mind on issues that impact a person negatively on a personal level. Nevertheless, I will try to see the other side of the coin. It is a good habit to cultivate.

Insurance products
I bought whole-life insurance plan before. It was an expensive plan for achieving my goal of protection. Since then, I have always advocated term insurance over savings-related, investment-linked plans that insurance agents love to sell because of the high commission. Insurance is for protection. Period. Don't mix them up with investment and savings products.

For people who have a past history of mis-managing cash on hand, financial products that force them to save can be a life-saver, even if substantial portion of the money goes to commission. Lottery winners are twice as likely to file for bankruptcy every year than the general population. So, if your spouse happen to strike Toto and you know him/her to be one of those who cannot manage money, it is better that he spends most of his winnings on financial products peddled by insurance agents than go on a spending spree, gamble it away in the financial markets, invest in speculative ventures by friends/relatives ...

EDIT: One more advantage of whole life and long-term endowment plans is to protect your savings  from creditors in the event of bankruptcy provided you put the plans under trust nomination. Credit for this insight goes to an Anonymous commenter (Saturday, November 9, 2019 at 12:07:00 PM GMT+8)

It is not without risk. You have to trust your family members. If a person is nominating his wife as beneficiary, please don't sabotage yourself by fooling around with mistresses. Keep your eyes open before marriage that she is not a gold-digger.

Financial training courses
I had family members who went for these financial training courses. One of them was a retiree. Outcome was bad (let's leave it at that). This is why I am angry and biased against expensive courses, particularly those that sell false hope.

This is a thread (Link) that warns about financial training courses. It provides good advice on what to watch out regarding the tricks used by the financial trainers and a list of the more controversial trainers in the industry. However, some of the language and labels (such as scammers) that were thrown on the financial trainers in the thread have gone overboard.

I had online correspondence with some financial bloggers in the past who later on became financial trainers. I'm pretty sure they are decent people. They are certainly not scammers. They are now running a business and face the normal pressures to feed the employees and their own family. If I were in their shoes, I will also try to maximize profits by charging as high as the customers can take. Which business-man will not do that?

I only hope these financial trainers will target the right customers, not the vulnerable victims. Definitely not retirees who can't afford to lose big in financial markets!! Don't touch my family.

There are many ways to make money from the financial market. For DIY investors, we need to go through a trial and error process to find the way that suits our unique strengths and personality. The DIY investor can learn by attending several courses to finally find what suits him. Even if your trainer is sincere and competent, what works for him may not work for you. Furthermore, if each course is going to cost thousands, then it makes the task of building the capital more challenging. This is why I've always recommended using cheap books and online resources to learn investing/trading because it keeps the cost of learning the investment craft low. The most important factor to success in investing/trading is size of capital. So, always try to keep your cost low to build up your capital.

I'm aware that not everyone learns well through books. There may be some people who learn better in a classroom, interactive environment compared to books. For young people (NOT retirees) who are hungry to learn but find books and websites/forums are not the channels for them, then perhaps paying up for these courses may be more effective. These are the right customers for the courses, not retirees!

When retirees' finances are badly injured, the financial contagion spreads to their children who are the sandwiched generation.

Multi-level marketing
A friend tried to recruit me into MLM. I was not interested. Perhaps I will talk about it in a later post.