編程計算定投黃金的收益率
首先用Bing搜gold price,得到下圖:

然后用Gwenview, IrfanView等裁剪圖片,得到下圖:

裁多了。應正好裁外框——可用opencv的演示程序squares.py :-)
然后用程序找出紅線上各點坐標。如果提取紅色通道,由于白是(255,255,255),紅是(255,0,0),就分不清了。所以我們提取綠色通道。綠色代表下跌,一般沒人用。提取后再畫出來,如下圖:

差不多與原圖一致。注意y要從[0,height)縮放為原圖的,比如[0,4500)。然后假設每期投1000元,計算結果是:
總投入:705000
總份額:4314.979
收益率:24.9倍 2492.82%
1995年,北京外銷商品房均價2~3萬元/㎡(按當時匯率1:8折算),普通住宅因福利分房制度主導,市場交易極少。向個人出售的商品住宅的平均價格為2427元/㎡,但實際可購渠道受限,單位團購仍是主流?。區域差異明顯,二環內商品房售價6500-8000元/㎡,四環外近郊區約2500-4500元/㎡。同期煎餅果子價格約1.5元/套(基礎款)?。
可完美處理天天基金網的多種顏色線。
程序(寫完才知道有Image.histogram; ImageDraw.floodfill, Image.getbbox):
import sys import numpy as np from PIL import Image img = Image.open(sys.argv[1]) # If用紅色通道,紅和白都是白,所以用綠 ary = np.array(img.split()[1]) >> 4 ''' ue, counts = np.unique(ary, return_counts=True) sorted_indices = np.argsort(-counts) r = ue[sorted_indices], counts[sorted_indices] [15, 12, 0, 14...] [179351, 9084, 1715, 411...] So 0 the color is. ''' data = []; height,width = ary.shape for x in range(width): points = np.where(ary[:, x][:] <= 5)[0] n = len(points) if n == 0: print('Point missing') if len(data): data.append(data[-1]) else: data.append(height - points[n // 2]) # 圖不一樣時要換4500這個高度 data = np.array(data) / height * 4500 import matplotlib.pyplot as plt plt.plot(data, color='green') plt.show() # 705 705,最好相等 n = len(data); print(n, width) z = data # 凈值(zhi) c = n * [1000] # capital sum_c = sum(c) print(f'總投入:{sum_c}') sum_s = 0 # sum_share for i in range(n): sum_s += c[i] / z[i] print(f'總份額:{sum_s:.3f}') # 份額×末期凈值 - 投入 ret = sum_s * z[-1] - sum_c print(f'收益率:{ret/sum_c:0.1f}倍 {100*ret/sum_c:.2f}%')

浙公網安備 33010602011771號