Skip to content

Instantly share code, notes, and snippets.

@igrep
Last active February 7, 2018 05:56
Show Gist options
  • Select an option

  • Save igrep/9b8281116a4b24fd6cb8f004692c56a7 to your computer and use it in GitHub Desktop.

Select an option

Save igrep/9b8281116a4b24fd6cb8f004692c56a7 to your computer and use it in GitHub Desktop.
GMOクリック証券「保有投信一覧」で、ジャンル毎の評価額の割合を計算(私の保有している銘柄がばれてしまうので、一部修正しています)
(() => {
const countFunds = parseInt(document.querySelector('#dataCount>span').innerHTML, 10);
const a = [];
for(let i = 1 ; i <= countFunds ; ++i){ a.push(i); } ;
const funds = a.map((i) => {
return {
name: $(`#positionFundName${i} a`).text(),
price: parseInt($(`#positionAppraisedAmount${i}`).text().replace(/,/g, ''), 10)
};
});
const sum = funds.map((f) => f.price).reduce((x, y) => x + y);
funds.forEach((f) => { f.rate = f.price / sum });
const classify = (name) => {
const m = name.match(/日本|日系|国内|新興国|世界|先進国|外国/);
const region =
m ?
(
m[0].includes("日")?
"国内"
: (
m[0].includes("外国") ? "先進国" : m[0]
)
)
: "その他";
const n = name.match(/債券|株/);
const product =
(n && n[0]) || (/STOCK/.test(name) ? "株" : "その他");
return `${region}・${product}`;
};
funds.forEach((f) => { f.group = classify(f.name) });
const groupSums = new Map();
funds.forEach((f) => {
groupSums.set(f.group, (groupSums.get(f.group) || 0) + f.price);
});
groupSums.forEach((groupSum, group) => { console.log(`${group}\t${groupSum}\t${(groupSum / sum).toFixed(2)}`); });
})();
@igrep
Copy link
Copy Markdown
Author

igrep commented Feb 7, 2018

ChromeのDevToolsのConsoleに貼り付けることで、ジャンル毎の評価額の合計と割合を見ることができます。
もちろん非公式なものなので動かなくても問い合わせなんてしないでくださいね!

@igrep
Copy link
Copy Markdown
Author

igrep commented Feb 7, 2018

⚠️ 注意: 現状、保有投信一覧が1ページに収まらなくなった場合は恐らく正しく計算できなくなります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment