Skip to content

Commit 74d6626

Browse files
authored
Implement daily P&L Ratio (#5)
* Implement daily P&L Ratio * always build and publish dockerfile * use workflow for pushing tag test image * update view * choice for dropdown * typo misspeeling * dev * remove currency * bug * remove P&L dup data in daily
1 parent 0570cde commit 74d6626

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

.github/workflows/docker-publish.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
description: 'Set to "yes" to push tag :test image to GHCR for testing before merging to main'
1414
required: false
1515
default: 'no'
16+
type: choice
17+
options:
18+
- 'no'
19+
- 'yes'
1620

1721
jobs:
1822

@@ -40,7 +44,10 @@ jobs:
4044
4145
push-to-ghcr:
4246
runs-on: ubuntu-latest
43-
if: github.ref == 'refs/heads/main'
47+
# Run if on main branch, or if manual_push is yes from workflow_dispatch
48+
if: >-
49+
(github.ref == 'refs/heads/main') ||
50+
(github.event_name == 'workflow_dispatch' && github.event.inputs.manual_push == 'yes')
4451
needs: build-test
4552
permissions:
4653
contents: read
@@ -69,6 +76,14 @@ jobs:
6976
run: |
7077
echo "LOWERCASE_REPO=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
7178
79+
- name: Set IMAGE_TAG for build-test
80+
run: |
81+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.manual_push }}" = "yes" ]; then
82+
echo "IMAGE_TAG=test" >> $GITHUB_ENV
83+
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
84+
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
85+
fi
86+
7287
- name: Extract metadata for Docker
7388
id: meta
7489
uses: docker/metadata-action@v5
@@ -83,6 +98,6 @@ jobs:
8398
file: ./docker/Dockerfile
8499
push: true
85100
tags: |
86-
ghcr.io/${{ env.LOWERCASE_REPO }}:latest
101+
ghcr.io/${{ env.LOWERCASE_REPO }}:${{ env.IMAGE_TAG }}
87102
ghcr.io/${{ env.LOWERCASE_REPO }}:${{ github.sha }}
88103
labels: ${{ steps.meta.outputs.labels }}

src/views/Daily.vue

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,36 @@ const checkDate = ((param1, param2) => {
393393
return check
394394
})
395395
396+
// Compute P/L Ratio for a daily itemTrade (avg win per share / avg loss per share)
397+
const getPLRatio = (itemTrade) => {
398+
try {
399+
if (!itemTrade || !itemTrade.pAndL) return '-'
400+
const p = itemTrade.pAndL
401+
const pref = amountCase && amountCase.value ? amountCase.value : amountCase
402+
403+
const winSum = p[pref + 'SharePLWins'] || p[pref + 'SharePLWins'] === 0 ? p[pref + 'SharePLWins'] : null
404+
const winCount = p[pref + 'WinsCount'] || p[pref + 'WinsCount'] === 0 ? p[pref + 'WinsCount'] : null
405+
const lossSum = p[pref + 'SharePLLoss'] || p[pref + 'SharePLLoss'] === 0 ? p[pref + 'SharePLLoss'] : null
406+
const lossCount = p[pref + 'LossCount'] || p[pref + 'LossCount'] === 0 ? p[pref + 'LossCount'] : null
407+
408+
if (!winSum || !winCount || !lossSum || !lossCount) {
409+
// Fallback: try keys without 'SharePL' prefix (older structures)
410+
const altWinSum = p[pref + 'Wins'] || p[pref + 'Wins'] === 0 ? p[pref + 'Wins'] : null
411+
const altLossSum = p[pref + 'Loss'] || p[pref + 'Loss'] === 0 ? p[pref + 'Loss'] : null
412+
if (altWinSum == null || altLossSum == null || winCount == 0 || lossCount == 0) return '-'
413+
}
414+
415+
const avgWinPerShare = (winSum / winCount)
416+
const avgLossPerShare = (-(lossSum) / lossCount)
417+
418+
if (!isFinite(avgWinPerShare) || !isFinite(avgLossPerShare) || avgLossPerShare === 0) return '-'
419+
420+
return (avgWinPerShare / avgLossPerShare).toFixed(2)
421+
} catch (e) {
422+
return '-'
423+
}
424+
}
425+
396426
/**************
397427
* SATISFACTION
398428
***************/
@@ -801,11 +831,10 @@ function getOHLC(date, symbol, type) {
801831
:data-index="index" class="ms-2 uil uil-tag-alt pointerClass"></i>
802832

803833
</div>
804-
<div class="col-12 col-lg-auto ms-auto">P&L({{ selectedGrossNet.charAt(0)
805-
}}):
834+
<div class="col-12 col-lg-auto ms-auto">P/L Ratio:
806835
<span
807-
v-bind:class="[itemTrade.pAndL[amountCase + 'Proceeds'] > 0 ? 'greenTrade' : 'redTrade']">{{
808-
useTwoDecCurrencyFormat(itemTrade.pAndL[amountCase + 'Proceeds'])
836+
v-bind:class="[itemTrade.pAndL.grossWinsCount/(itemTrade.pAndL.grossWinsCount+itemTrade.pAndL.grossLossCount) < 0.5 && getPLRatio(itemTrade) < 1.0 ? 'redTrade' : 'greenTrade']">{{
837+
getPLRatio(itemTrade)
809838
}}</span>
810839
</div>
811840

@@ -882,8 +911,8 @@ function getOHLC(date, symbol, type) {
882911
</div>
883912
<div>
884913
<label>P&L(g)</label>
885-
<p>{{ useTwoDecCurrencyFormat(itemTrade.pAndL.grossProceeds)
886-
}}
914+
<p v-bind:class="[itemTrade.pAndL[amountCase + 'Proceeds'] > 0 ? 'greenTrade' : 'redTrade']">
915+
{{ useTwoDecCurrencyFormat(itemTrade.pAndL.grossProceeds) }}
887916
</p>
888917
</div>
889918
</div>

0 commit comments

Comments
 (0)