コード

HTML
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Investment and Interest Rate Simulation</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="container">
<h2>米国債券TLT・TMFシミュレーション</h2>

  <div class="form-group">
    <label for="current-stock-price-usd">現在のTLT株価 (USD):</label>
    <input
      type="number"
      id="current-stock-price-usd"
      placeholder="株価を入力してください"
    />
  </div>

  <div class="form-group">
    <label for="number-of-shares">購入株数:</label>
    <input
      type="number"
      id="number-of-shares"
      placeholder="購入株数を入力してください"
    />
  </div>

  <div class="form-group">
    <label for="current-exchange-rate">現在のドル円レート:</label>
    <input
      type="number"
      id="current-exchange-rate"
      placeholder="ドル円レートを入力してください"
    />
  </div>

  <div class="form-group">
    <label for="current-interest-rate">現在の金利 (%):</label>
    <input
      type="number"
      id="current-interest-rate"
      placeholder="金利を入力してください"
    />
  </div>

  <div class="form-group">
    <label for="duration">デュレーション:</label>
    <input type="number" id="duration" placeholder="17.70" />
  </div>

  <div class="form-group">
    <label for="simulated-exchange-rate">シミュレートドル円レート:</label>
    <input
      type="number"
      id="simulated-exchange-rate"
      placeholder="ドル円レートを入力してください"
    />
  </div>

  <div class="form-group">
    <label for="simulated-interest-rate">シミュレート金利 (%):</label>
    <input
      type="number"
      id="simulated-interest-rate"
      placeholder="金利を入力してください"
    />
  </div>

  <button onclick="calculateInvestmentDetails()">シミュレーション</button>

  <div id="results">
    <p>購入金額 (USD): <span id="investment-amount-usd"></span></p>
    <p>購入金額(円): <span id="investment-amount-jpy"></span></p>
    <p>予想リターン (円): <span id="expected-return-jpy"></span></p>
    <p>予想利益 (円): <span id="expected-profit-jpy"></span></p>
    <p>為替レートの差異: <span id="exchange-rate-difference"></span>%</p>
    <p>予想利益(%): <span id="expected-profit-percentage"></span>%</p>
    <p>
      予想利益(TMF):
      <span id="expected-profit-percentage-triple-duration"></span>%
    </p>
  </div>
</div>

<script src="simulate.js"></script>

</body>
</html>

CSS
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4 ;
margin: 0;
padding: 20px;
}

.container {
background-color: #fff ;
max-width: 800px;
margin: 20px auto;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h2 {
color: #333 ;
text-align: center;
margin-bottom: 30px;
}

.form-group {
margin-bottom: 15px;
}

.form-group label {
display: block;
margin-bottom: 5px;
}

.form-group input[type="number"] {
width: 100%;
padding: 8px;
border: 1px solid #ddd ;
border-radius: 4px;
margin-bottom: 10px;
box-sizing: border-box;
}

button {
width: 100%;
padding: 10px;
background-color: #4CAF50 ;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-top: 10px;
}

button:hover {
background-color: #45a049 ;
}

#results {
margin-top: 20px;
padding: 10px;
background-color: #e7f4e4 ;
border-radius: 4px;
box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}

#results p {
margin: 10px 0;
line-height: 1.6;
}

/* Add responsive design for smaller screens */
@media (max-width: 600px) {
.container {
width: 100%;
padding: 0;
box-shadow: none;
}

.form-group {
    margin-bottom: 10px;
}

.form-group input[type="number"] {
    width: calc(100% - 16px);
    margin-bottom: 10px;
}

button {
    width: calc(100% - 20px);
    margin-top: 10px;
}

}

JS
function calculateInvestmentDetails() {
// 入力値を取得
var stockPriceUSD = parseFloat(document.getElementById('current-stock-price-usd').value);
var shares = parseInt(document.getElementById('number-of-shares').value);
var exchangeRate = parseFloat(document.getElementById('current-exchange-rate').value);
var interestRate = parseFloat(document.getElementById('current-interest-rate').value);
var duration = parseFloat(document.getElementById('duration').value);
var simulatedExchangeRate = parseFloat(document.getElementById('simulated-exchange-rate').value);
var simulatedInterestRate = parseFloat(document.getElementById('simulated-interest-rate').value);

// 入力値の検証
if ([stockPriceUSD, shares, exchangeRate, interestRate, duration, simulatedExchangeRate, simulatedInterestRate].some(isNaN)) {
    alert("全てのフィールドに正しい数値を入力してください。");
    return;
}

// 投資額と予想リターンを計算
var investmentAmountUSD = stockPriceUSD
* shares;
var investmentAmountJPY = investmentAmountUSD * exchangeRate;
var priceChangePercent = (interestRate - simulatedInterestRate) * duration;
var expectedReturnUSD = investmentAmountUSD * (1 + priceChangePercent / 100);
var expectedReturnJPY = expectedReturnUSD * simulatedExchangeRate;
var expectedProfitJPY = expectedReturnJPY - investmentAmountJPY;
var expectedProfitPercentage = (expectedProfitJPY / investmentAmountJPY) * 100;

// 3倍のデュレーションでの予想される利益の割合を計算
var tripleDuration = duration * 3;
var priceChangePercentTriple = (interestRate - simulatedInterestRate) * tripleDuration;
var expectedReturnUSDTriple = investmentAmountUSD * (1 + priceChangePercentTriple / 100);
var expectedReturnJPYTriple = expectedReturnUSDTriple * simulatedExchangeRate;
var expectedProfitJPYTriple = expectedReturnJPYTriple - investmentAmountJPY;
var expectedProfitPercentageTriple = (expectedProfitJPYTriple / investmentAmountJPY) * 100;

// 為替レートの差異(パーセンテージ)を計算
var exchangeRateDifference = ((simulatedExchangeRate - exchangeRate) / exchangeRate) * 100;

// 結果の表示
document.getElementById('investment-amount-usd').textContent = `${investmentAmountUSD.toFixed(2)}`;
document.getElementById('investment-amount-jpy').textContent = ` ${investmentAmountJPY.toFixed(2)}`;
document.getElementById('expected-return-jpy').textContent = ` ${expectedReturnJPY.toFixed(2)}`;
document.getElementById('expected-profit-jpy').textContent = ` ${expectedProfitJPY.toFixed(2)}`;
document.getElementById('expected-profit-percentage').textContent = ` ${expectedProfitPercentage.toFixed(2)}`;
document.getElementById('exchange-rate-difference').textContent = ` ${exchangeRateDifference.toFixed(2)}`;
document.getElementById('expected-profit-percentage-triple-duration').textContent = ` ${expectedProfitPercentageTriple.toFixed(2)}`;

}

この記事が気に入ったらサポートをしてみませんか?