Skip to content

Instantly share code, notes, and snippets.

@amandadebler
Created August 26, 2019 15:02
Show Gist options
  • Save amandadebler/90ebb12db5b40bbc88de0482d006e4bf to your computer and use it in GitHub Desktop.
Save amandadebler/90ebb12db5b40bbc88de0482d006e4bf to your computer and use it in GitHub Desktop.
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