I use code to analyze a money-making technique for you

Introductory tutorials, case source code, learning materials, readership

Please visit:  python666.cn

Hello everyone, welcome to Crossin's programming classroom!

Making money is a cheesy topic, but it is something that no one can avoid. Let's discuss this topic "scientifically" today.

When talking about making money, you will talk about financial management, investment, and stock trading. There is such a joke:

Q: How to become a millionaire?

Answer: Bring 10 million into the stock market.

Although the stock market is a place full of myths about creating wealth, for most participants, the risk is extremely high, the so-called seven losses, two equals and one gain . However, general bank wealth management and monetary funds have relatively stable low-yield rates. What I want to talk about today is an investment strategy between the two, which can not only increase your rate of return, but also maintain a relatively controllable risk . (Is there really such a good thing?)

The strategy is simple and consists of two steps:

  1. Invest 50% of the spare money you have on hand for investment (note that it is spare money) in stock index funds , such as index fund 300ETF, and 50% in low-risk fixed-income products , such as the well-known Yu’e Bao, other currency funds, Bank fixed income wealth management, etc.

  2. Asset rebalancing is carried out every fixed period of time (assuming one year), so that the ratio of stock assets and fixed income assets will return to 50% to 50% , for example, on December 31 every year, if the stock price rises sharply this year, then It is necessary to sell stocks and buy monetary funds to restore the market value of the two assets after adjustment by 50% to 50%.

Then, there's no more...it's as simple as that.

I didn't come up with this strategy by scratching my head. Its official name is dynamic rebalancing strategy . It was first proposed by the "Godfather of Wall Street" Graham , and was later quoted by many securities analysts. The above is a minimalist version.

Many people have discussed in books or articles about the actual effect of the strategy. But I think you are still cautiously skeptical about it. Then, next, I will use the code to do some simulated statistical experiments on historical data to see how the effect is.

The data source of this simulation code is a Python library called  akshare  , which is an open source financial data interface package.

Data processing uses numpy and plotting uses matplotlib .

See the end of the article for detailed code acquisition.

Our simulation scenario is set as:

  1. The initial capital is 10,000 yuan

  2. Index funds traded with CSI 300ETF [510300]

  3. In order to simplify the model, we do not consider rest days, assuming that the fixed income of each trading day is 1/10,000 (annualized about 3%).

  4. At regular intervals, a "rebalance" operation is performed to restore the ratio of index funds to fixed income to 50:50.

  5. Compare the results to the effect of buying all index funds and buying all fixed income .

According to the previous strategies and settings, different cycles and time periods were selected for several experiments, and the results are as follows:

699eefa4508bd173115a06d70f0aa7fa.jpeg

In several experiments, the return of the rebalancing strategy is in the middle of the other two strategies: when the stock market is good, you can obtain returns far exceeding fixed income; You won't lose too much. Especially like the last group, buying from around 3000 points in 2007, after 10 years of two big bull markets, after the stock returns to the original point, the rebalancing strategy still has the effect equivalent to fixed income.

Visual display:

968c2c82281383fde7db599fcc01a03b.jpeg

The blue line is the index, the red line is the full index fund strategy (the curves of the two are the same, but the coordinate axes are different), the green line is the curve of fixed income , and the stacked line chart is the curve of rebalancing strategy (the lower half is fixed income, the upper half is index funds). The rebalancing strategy basically uses fixed income as the standard and makes fluctuations around it, and the impact of fluctuations is the rise and fall of the stock market . Therefore, it not only ensures the stability of income, but also increases the chance of excess income.

On the basis of the simplest version, there can also be a change: instead of rebalancing according to a fixed period, it is proportional, for example, when one part exceeds the other by 20%, rebalancing is triggered .

In the above experimental data, the overall rate of return has improved:

a98be2b1b8cba5588fb126e4c74af187.jpeg

You can also combine the rebalancing strategy with the regular investment strategy. For example, start with 10,000 yuan, and then invest 1,000 yuan every month (simplified by 30 trading days). According to our second rebalancing strategy, from May 2007 to Now, the result is:

A total investment of 101,000 yuan

The final capital of the rebalancing strategy is 131010 yuan

Compared with only buying fixed income, it is 118317 yuan

Only buying index funds is 108857 yuan

ab2ed6769b5da100bca0cc2f93867405.jpeg

Of course, it is still not very convincing to draw conclusions from these few selections, so I let the program randomly select the start and end time points (at least 1000 trading days), and conducted 1000 experiments , and the final yield statistics As shown below:

dcbb18f673f1c8571c659791efeccfaf.jpeg

Red dots are rebalanced strategy yields, yellow dots are fixed yields, and green dots are index fund yields .

Most of our strategy returns remain between 0 and 7 , with a standard deviation of 5.88, which is relatively stable. This rate of return also depends on the underlying rate of return of fixed income. If fixed income can be increased to more than 5%, the rate of return of this strategy will be close to 10% on average.

Although the rate of return of pure stocks may reach an astonishing value (such as 150+% at the top point), the standard deviation is 14.1, and there is a high probability of loss.

Therefore, this strategy is not likely to make you rich, but it is a very worthwhile asset allocation strategy for those who are looking for stable asset appreciation.

Someone muttered, it’s so amazing, did you buy it yourself?

emmmmm... Let's stop here for today's topic!

To obtain relevant codes in this article, please reply to the keyword strategy in the official account (Crossin's programming classroom)


Crossin's second book " Operation on Code: Using Python and ChatGPT to Efficiently Get Excel Data Analysis " is now on the market.

da1f63905a4247a7eea81f92d77fa254.jpeg

This book explains the ideas, methods and practical applications of processing and analyzing data from the perspective of the combined use of Python and Excel. Whether you are a learner who wants to engage in data analysis or an office worker in other occupations, you can master the skills of Python to analyze data through the study of this book. The book innovatively introduces ChatGPT into teaching, uses ChatGPT to answer questions and provides practical training codes, and introduces some practical skills of using ChatGPT to assist learning, bringing a new way of learning to learners.

Readers and friends of the official account can contact me in the background after purchase and join the reader exchange group. Crossin will open the accompanying reading mode for you and answer all your questions when reading this book.

Thank you for retweeting and liking ~


_Previous article recommendation_

N implementations of Python singleton mode (Singleton)


If you want to learn about paid quality courses and teaching Q&A services

Please reply in Crossin's programming classroom : 666

feed745438678cdb5ca18da58327c74c.jpeg

Guess you like

Origin blog.csdn.net/qq_40523737/article/details/132033593