Skip to content

Commit

Permalink
blog updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolai committed Jan 26, 2020
1 parent 5276d94 commit e90054c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions docs/blog/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
# 博客

## 2020.01.26 BOX 历史价格自动更新

我在 github 仓库里,添加了一个 ```data``` 目录,里面的 BOX 历史价格文件会每日 23:59 更新一次价格。

而后,可以使用这个文件去用 Python 制作价格变动图表,代码如下:



```python
import matplotlib.pyplot as plt
import pandas as pd
from re import sub

series = pd.read_csv(
"https://raw.githubusercontent.com/xiaolai/regular-investing-in-box/master/data/box_price_history.txt",
sep="\t"
)

number_of_rows = series.shape[0]

daily_invested = 1

# add column "Total Invested"
total_invested = []
for i in range(0, number_of_rows):
total_invested.append((i+1)*daily_invested)
series["Total Invested"] = total_invested

# add column "Daily Bought"
BOX_daily_bought = []
for i in range(0, number_of_rows):
BOX_daily_bought.append(daily_invested/float(sub(r"[^\d.]", "", series.at[i, "BOX Price"])))

series["BOX Bought"] = BOX_daily_bought

# add column "Value Accumulated"
value_accumulated = []
for i in range(0, number_of_rows):
holding = 0
for j in range(0, i+1):
holding += series.at[j, "BOX Bought"]
value_accumulated.append(holding * float(sub(r"[^\d.]", "", series.at[i, "BOX Price"])))
series["Value Accumulated"] = value_accumulated


# add BTC price change
btc_price_change = []
eos_price_change = []
xin_price_change = []
box_price_change = []
ri_box_change = []
for i in range(0, number_of_rows):
btc_price_change.append(float(sub(r"[^\d.]", "", series.at[i, "BTC Price"]))/float(sub(r"[^\d.]", "", series.at[0, "BTC Price"])) - 1)
eos_price_change.append(float(sub(r"[^\d.]", "", series.at[i, "EOS Price"]))/float(sub(r"[^\d.]", "", series.at[0, "EOS Price"])) - 1)
xin_price_change.append(float(sub(r"[^\d.]", "", series.at[i, "XIN Price"]))/float(sub(r"[^\d.]", "", series.at[0, "XIN Price"])) - 1)
box_price_change.append(float(sub(r"[^\d.]", "", series.at[i, "BOX Price"]))/float(sub(r"[^\d.]", "", series.at[0, "BOX Price"])) - 1)
ri_box_change.append(series.at[i, "Value Accumulated"]/series.at[i, "Total Invested"] - 1)
series["BTC"] = btc_price_change
series["EOS"] = eos_price_change
series["XIN"] = xin_price_change
series["BOX"] = box_price_change
series["RI-BOX"] = ri_box_change

# print(series)

ax = plt.gca()
series.plot(kind='line', x='Date', y='BTC', ax=ax)
series.plot(kind='line', x='Date', y='EOS', ax=ax)
series.plot(kind='line', x='Date', y='XIN', ax=ax)
series.plot(kind='line', x='Date', y='BOX', ax=ax)
series.plot(kind='line', x='Date', y='RI-BOX', ax=ax)
plt.show()
```

![png](images/output_0_0.png)

## 2020.01.24 多年前的一篇短文

我曾经用过 xiaolai.li 这个域名,后来不用了。现在,这篇文章只能在 [archive.org](https://web.archive.org/web/20140523062542/xiaolai.li/bitcoin-period) 上看到了。
Expand Down
Binary file added docs/blog/images/output_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e90054c

Please sign in to comment.