Skip to content

Commit

Permalink
adjusted the call sell return values
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Sep 18, 2024
1 parent e69c54c commit 6da8278
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/app/screener/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function Page() {
return <div>
Screener
</div>
}
15 changes: 10 additions & 5 deletions src/components/StockOptionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum PutCallType {
const numberFormatter = (v: string) => v && Number(v);
const todaysDate = dayjs().format('YYYY-MM-DD');
export const StockOptionsView = (props: ITickerProps) => {
const { data, isLoading, strikePriceRange, setStrikePriceRange, targetPrice, setTargetPrice } = useOptionTracker(props.symbol);
const { data, isLoading, strikePriceRange, setStrikePriceRange, targetPrice, setTargetPrice, costBasis, setCostBasis } = useOptionTracker(props.symbol);
const [openSearchTickerDialog, setOpenSearchTickerDialog] = useState(false);
const router = useRouter();

Expand Down Expand Up @@ -104,16 +104,18 @@ export const StockOptionsView = (props: ITickerProps) => {
if (putCallTabValue == PutCallType.PUT) {
return (targetPrice > s.value ? price : (price - (s.value - targetPrice))) / (s.value);
} else {
return (price / targetPrice);
const sellCost = targetPrice >= s.value ? (price + s.value) : (targetPrice + price);
return (sellCost - costBasis) / costBasis;
}
case 'ANNUAL_RETURN':
if (putCallTabValue == PutCallType.PUT) {
const sellCost = (targetPrice > s.value ? price : (price - (s.value - targetPrice)));
const risk = s.value;
return (sellCost / risk) * (365 / numberofdays);
} else {
const sellCost = (targetPrice < s.value ? price : (price - (targetPrice - s.value)));
return (sellCost / targetPrice) * (365 / numberofdays);
// const sellCost = (targetPrice < s.value ? price : (price - (targetPrice - s.value)));
const sellCost = targetPrice >= s.value ? (price + s.value) : (targetPrice + price);
return ((sellCost -costBasis) / costBasis) * (365 / numberofdays);
}
case 'PCR':
return po.oi;
Expand Down Expand Up @@ -161,6 +163,9 @@ export const StockOptionsView = (props: ITickerProps) => {
<FormControl sx={{ m: 1 }} variant="standard">
<TextField label="Target price" variant="standard" value={targetPrice} onChange={v => setTargetPrice(Number(v.target.value))} type='number' />
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<TextField label="Cost basis" variant="standard" value={costBasis} onChange={v => setCostBasis(Number(v.target.value))} type='number' />
</FormControl>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={putCallTabValue} onChange={(e, v) => handleCallTabValue(v)} variant="fullWidth" indicatorColor="secondary"
textColor="secondary">
Expand Down Expand Up @@ -231,7 +236,7 @@ export const StockOptionsView = (props: ITickerProps) => {
>
<DialogTitle id="search-ticker-dialog-title">Search</DialogTitle>
<DialogContent dividers={true}>
<TickerSearch onChange={(v) => router.push(`/options/analyze/${v.symbol}`)} />
<TickerSearch onChange={(v) => router.push(`/options/analyze/${v.symbol}`)} />
</DialogContent>
</Dialog>

Expand Down
4 changes: 3 additions & 1 deletion src/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const useOptionTracker = (symbol: string) => {
const [data, setOd] = useState<OptionsData>();
const [isLoading, setIsLoading] = useState(true);
const [targetPrice, setTargetPrice] = useState(0);
const [costBasis, setCostBasis] = useState(0);
const [strikePriceRange, setStrikePriceRange] = useState<NumberRange>({ start: 0, end: Number.MAX_VALUE });

useEffect(() => {
Expand All @@ -159,6 +160,7 @@ export const useOptionTracker = (symbol: string) => {
end: Math.round(currentPrice + thresholdValue)
});
setTargetPrice(r.currentPrice);
setCostBasis(r.currentPrice);
}).finally(() => setIsLoading(false));
// socket.emit('options-subscribe-request', item);
// socket.on(`options-subscribe-response`, setOd);
Expand All @@ -167,7 +169,7 @@ export const useOptionTracker = (symbol: string) => {
// socket.off('options-subscribe-response', setOd);
// }
}, [symbol]);
return { data, isLoading, strikePriceRange, setStrikePriceRange, targetPrice, setTargetPrice };
return { data, isLoading, strikePriceRange, setStrikePriceRange, targetPrice, setTargetPrice, costBasis, setCostBasis };
}

export const useCachedDatesData = (symbol: string, dt: string) => {
Expand Down

0 comments on commit 6da8278

Please sign in to comment.