Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
PtPrashantTripathi committed Oct 4, 2024
1 parent 9e96267 commit b542e0e
Show file tree
Hide file tree
Showing 13 changed files with 746 additions and 502 deletions.
496 changes: 224 additions & 272 deletions DATA/API/current_holding_data.json

Large diffs are not rendered by default.

79 changes: 70 additions & 9 deletions FRONTEND/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Portfolio Tracker</title>

<!-- SEO Meta Tags -->
<meta
name="description"
content="Portfolio Tracker : A complete ETL for stock exchanges with PNL calculation and financial analysis tools."
/>
<meta name="keywords" content="ETL, finance, stock-market" />
<meta
name="author"
content="Pt. Prashant Tripathi - [email protected]"
/>
<meta name="robots" content="index, follow" />

<!-- Last Modified Meta Tag -->
<meta http-equiv="last-modified" content="2024-10-04T11:30:06Z" />

<!-- Open Graph Tags -->
<meta property="og:title" content="Portfolio Tracker" />
<meta
property="og:description"
content="Portfolio Tracker : A complete ETL for stock exchanges with PNL calculation and financial analysis tools."
/>
<meta
property="og:url"
content="https://ptprashanttripathi.github.io/PortfolioTracker/"
/>
<meta
property="og:image"
content="https://ptprashanttripathi.github.io/PortfolioTracker/asset/icon/favicon.ico"
/>
<meta property="og:updated_time" content="2024-10-04T11:30:06Z" />

<!-- Twitter Card Tags -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Portfolio Trackere" />
<meta
name="twitter:description"
content="Portfolio Tracker : A complete ETL for stock exchanges with PNL calculation and financial analysis tools."
/>
<meta
name="twitter:image"
content="https://ptprashanttripathi.github.io/PortfolioTracker/asset/icon/favicon.ico"
/>
<meta name="twitter:updated_time" content="2024-10-04T11:30:06Z" />

<!-- Dublin Core Metadata -->
<meta name="DC.date" content="2024-10-04T11:30:06Z" />

<!-- Structured Data (JSON-LD) -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebPage",
"url": "https://ptprashanttripathi.github.io/PortfolioTracker/",
"dateModified": "2024-10-04T11:30:06Z"
}
</script>

<link
rel="apple-touch-icon"
sizes="180x180"
Expand Down Expand Up @@ -229,15 +287,18 @@ <h3 class="card-title">Description</h3>
</div>
</div>
<footer class="main-footer">
<div>
Copyright © 2023-2024 -
<a
href="https://github.com/ptprashanttripathi/PortfolioTracker"
>@PtPrashantTripathi</a
>
<span class="float-right d-inline">
All rights reserved.
</span>
<div class="row">
<div class="col">
<b>Copyright</b> © 2023-2024
<a
href="https://github.com/ptprashanttripathi/PortfolioTracker"
>@PtPrashantTripathi</a
>
<br />All rights reserved.
</div>
<div class="col text-right">
<strong>Last updated</strong> 04 Oct 2024, 11:30 am IST
</div>
</div>
</footer>
</div>
Expand Down
File renamed without changes.
51 changes: 42 additions & 9 deletions FRONTEND/asset/js/current_holding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createCell,
calcDays,
loadDataTable,
updated_header_footer,
} from "./render.js";

// Load current holding table
Expand All @@ -22,7 +23,42 @@ function loadCurrentHoldingDataTable(data) {
"Holding Days",
];

const cellData = data.map((record) => {
const currentHoldingData = Object.entries(
Object.groupBy(
data,
(item) => `${item.segment}-${item.exchange}-${item.symbol}`
)
).map(([key, group]) => {
const total_quantity = group.reduce(
(sum, item) => sum + item.quantity,
0
);
const total_amount = group.reduce((sum, item) => sum + item.amount, 0);
const close_price = group[0].close_price;
const close_amount = close_price * total_quantity;

return {
key,
scrip_name: group[0].scrip_name,
symbol: group[0].symbol,
exchange: group[0].exchange,
segment: group[0].segment,
total_quantity,
total_amount, // Ensure total_amount is included
avg_price: total_quantity ? total_amount / total_quantity : 0, // Avoid division by zero
close_price,
close_amount,
pnl_amount: close_amount - total_amount,
min_datetime: new Date(
Math.min(...group.map((item) => new Date(item.datetime)))
),
history: group,
};
});

currentHoldingData.sort((a, b) => a.key.localeCompare(b.key));

const cellData = currentHoldingData.map((record) => {
const pnlClass = record.pnl_amount < 0 ? "text-danger" : "text-success";
return [
createCell(
Expand Down Expand Up @@ -51,10 +87,7 @@ function loadCurrentHoldingDataTable(data) {
// Update the financial summary section
function updateFinancialSummary(data) {
// Function to calculate profit/loss summary
const investedValue = data.reduce(
(sum, record) => sum + record.total_amount,
0
);
const investedValue = data.reduce((sum, record) => sum + record.amount, 0);
const currentValue = data.reduce(
(sum, record) => sum + record.close_amount,
0
Expand Down Expand Up @@ -97,11 +130,11 @@ function updateFinancialSummary(data) {
}

async function main() {
const { data: current_holding_data, load_timestamp } = await fetchApiData(
const { data, load_timestamp } = await fetchApiData(
"current_holding_data.json"
);
loadCurrentHoldingDataTable(current_holding_data);

updateFinancialSummary(current_holding_data);
loadCurrentHoldingDataTable(data);
updateFinancialSummary(data);
updated_header_footer(load_timestamp);
}
window.onload = main();
2 changes: 2 additions & 0 deletions FRONTEND/asset/js/dividend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
priceFormat,
loadDataTable,
createCell,
updated_header_footer,
} from "./render.js";

// Load ApexCharts chart
Expand Down Expand Up @@ -162,6 +163,7 @@ async function main() {
loadDividendDataTable(data);
loadDividendChart(data);
updateDividendSummary(data);
updated_header_footer(load_timestamp);
}

window.onload = main;
33 changes: 16 additions & 17 deletions FRONTEND/asset/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
priceFormat,
parseNum,
renderSummary,
updated_header_footer,
} from "./render.js";

// Load ApexCharts chart
Expand Down Expand Up @@ -95,29 +96,26 @@ function loadHoldingTrandsChart(data) {

// Update the financial summary section
function updateFinancialSummary(data) {
// Function to calculate profit/loss summary
const investedValue = data.reduce(
(sum, record) => sum + record.total_amount,
0
);
const currentValue = data.reduce(
(sum, record) => sum + record.close_amount,
0
);
const pnlValue = data.reduce((sum, record) => sum + record.pnl_amount, 0);
const latest_data = data.reduce((max, item) => {
return new Date(item.date) > new Date(max.date) ? item : max;
});

const pnlValue = latest_data.close - latest_data.holding;

const pnlClass = pnlValue > 0 ? "bg-success" : "bg-danger";
const pnlIcon = pnlValue > 0 ? "▲" : "▼";
const summaryItems = [
{
value: priceFormat(currentValue),
// currentValue
value: priceFormat(latest_data.close),
label: "Total Assets Worth",
colorClass: "bg-info",
iconClass: "fas fa-coins",
href: "current_holding.html#CurrentHoldingTable",
},
{
value: priceFormat(investedValue),
//investedValue
value: priceFormat(latest_data.holding),
label: "Total Investment",
colorClass: "bg-warning",
iconClass: "fas fa-cart-shopping",
Expand All @@ -131,7 +129,9 @@ function updateFinancialSummary(data) {
href: "current_holding.html#CurrentHoldingTable",
},
{
value: `${pnlIcon} ${parseNum((pnlValue * 100) / investedValue)}%`,
value: `${pnlIcon} ${parseNum(
(pnlValue * 100) / latest_data.holding
)}%`,
label: "Overall Return",
colorClass: pnlClass,
iconClass: "fas fa-chart-line",
Expand All @@ -142,12 +142,11 @@ function updateFinancialSummary(data) {
}

async function main() {
const { data: holding_trands_data, load_timestamp } = await fetchApiData(
const { data, load_timestamp } = await fetchApiData(
"holding_trands_data.json"
);
loadHoldingTrandsChart(holding_trands_data);

const { data } = await fetchApiData("current_holding_data.json");
loadHoldingTrandsChart(data);
updateFinancialSummary(data);
updated_header_footer(load_timestamp);
}
window.onload = main();
37 changes: 15 additions & 22 deletions FRONTEND/asset/js/profit_and_loss.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
renderSummary,
createCell,
loadDataTable,
calcDays,
updated_header_footer,
} from "./render.js";

// Update the P&L data summary section
Expand Down Expand Up @@ -73,7 +75,7 @@ function processProfitLossData(data) {
// Group the data by segment, exchange, and symbol
const groupedData = Object.groupBy(
data,
({ segment, exchange, symbol }) => `${segment}-${exchange}-${symbol}`
(item) => `${item.segment}-${item.exchange}-${item.symbol}`
);

// Transform the grouped data into the desired format
Expand All @@ -91,35 +93,25 @@ function processProfitLossData(data) {
(sum, item) => sum + item.close_amount,
0
);
const totalPnl = group.reduce((sum, item) => sum + item.pnl_amount, 0);

return {
segment: group[0].segment,
exchange: group[0].exchange,
symbol: group[0].symbol,
days: Math.floor(
(group[group.length - 1].close_datetime -
group[0].open_datetime) /
(1000 * 60 * 60 * 24)

min_datetime: new Date(
Math.min(...group.map((item) => new Date(item.open_datetime)))
),
max_datetime: new Date(
Math.max(...group.map((item) => new Date(item.close_datetime)))
),
quantity: totalQuantity,
open_amount: totalOpenAmount,
close_amount: totalCloseAmount,
avg_price: totalOpenAmount / totalQuantity,
sell_price: totalCloseAmount / totalQuantity,
pnl: totalPnl,
history: group.map((item) => ({
scrip_name: item.scrip_name,
position: item.position,
quantity: item.quantity,
days: item.days,
open_datetime: item.open_datetime,
open_price: item.open_price,
open_amount: item.open_amount,
close_datetime: item.close_datetime,
close_price: item.close_price,
close_amount: item.close_amount,
pnl_amount: item.pnl_amount,
pnl_percentage: item.pnl_percentage,
})),
pnl: group.reduce((sum, item) => sum + item.pnl_amount, 0),
history: group,
};
});

Expand Down Expand Up @@ -157,7 +149,7 @@ function loadProfitLossDataTable(data) {
)}%`,
pnlFlag ? ["text-danger"] : ["text-success"]
),
createCell(record.days),
createCell(calcDays(record.min_datetime, record.max_datetime)),
];
});
loadDataTable("ProfitLossTable", headers, cellData);
Expand All @@ -169,5 +161,6 @@ async function main() {
);
loadProfitLossDataTable(profit_loss_data);
updateProfitLossDataSummary(profit_loss_data);
updated_header_footer(load_timestamp);
}
window.onload = main();
Loading

0 comments on commit b542e0e

Please sign in to comment.