Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Get-SharesInAmount {
[CmdletBinding()]
param (
$stock,
$amount,
$transactionCost = 5,
$maxCostRatio = 0.02
)
begin {
}
process {
$sharesToConsider = [Math]::floor(($amount * ($stock.Weight)/100) / ($stock.Price) )
$purchasePrice = ($sharesToConsider * $stock.Price) + $transactionCost
if ($transactionCost/$purchasePrice -gt $maxCostRatio) {
$sharesToConsider = 0
$purchasePrice = 0
}
[PSCustomObject]@{
Symbol = $stock.Symbol
Company = $stock.Company
Shares = $sharesToConsider
Cost = $purchasePrice
}
}
end {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment